It looks like all of the statements satisfy the first requirement (starts
with a non-C token), since #rom is not a normal C identifier.
All but the last satisfy the second requirement (can recognize the end of
the statement without looking ahead). As an example for the last
statement, after the parser sees:
#rom locateLo@A + B
it would need to peek at the next token to see if it is one that would
continue the expression (such as +, -, *, etc), or something else such as
the 'void' token for a following function definition:
#rom locateLo@A + B + C
vs.
#rom locateLo@A + B
void foo(int x) {
...
}
In the second case, the 'void' token would be scanned in the "full scan"
state, so would not be copied to the output. Having seen 'void', the
parser would return the scanner to the "copy" state, where it would pick up
with "foo"... and start copying from there, missing 'void'.
If it is possible to change the syntax, something like:
#rom locateLo(addr)
or
#rom locateLo@addr;
would correct this. Then the ) or ; would signal the end of the statement
with no need to look any further.
As to generalizing this, I would think that most of the scanner tokens
would be the same for most languages (various literals, identifiers, return
any single special character as a token, though comments are a bit
different). Thus from the scanner perspective it should be relatively easy
to use this as a preprocessor for python, or ruby, or C, or fortran, or
many other languages.
You want C expressions in your preprocessor statements. Full C expressions
include multi-special-character tokens such as ++ or +=. I don't know what
these would mean in your context, and whether you would want to include
them since they have side effects; but if so, you'd need special scanner
rules for them; with a single rule to return any single special character
as a token.
Then the parser rules would be specific to your preprocessing directives.
If somebody wants to use this for another purpose, they would need to
define their own preprocessor statement syntax.
If you are familiar with a source code control system, such as
mercurial<http://mercurial.selenic.com/>,
you can put your code on code.google.com for free. There are several other
free open source code hosting sites if you don't like google. No rush on
any of this, if you just want to play with the idea for a bit to see if you
can get it working.
If you aren't familiar with a common source code control system, and don't
mind sending a copy to me, and don't mind if I put it up on google code, I
would appreciate it! Again, no rush...
Thanks!
-Bruce
On Sun, Jun 16, 2013 at 3:25 PM, [email protected] <
[email protected]> wrote:
> Thanks for ideas so far. The grammer I've defined to date is
>
> *#rom* *ID*, *int8* { *int8*, *int8* … }
>
> *#rom* *ID*, *int16* { *int16*, *int16* … }
>
> *#rom* *ID*, "*Quoted text string*"
>
> *#rom* *ID*, """
>
> *Block text a*
>
> *la Python*
>
> """
>
> *#rom* (*locateLo*|*locateHi*)@*addr*
>
> IDs are general identifers so each rom block can be referred to by the
> rest of the 'C' code. *int8*, *int16,* *locateLo *and *locateHi* are
> reserved words. *int8*, *int16* and *addr *are general 'C' expressions.
>
> I'll certainly make the source available but it's rather specific compared
> to something like M4. What's the best way to do that? it's ~640 lines at
> the moment.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "ply-hack" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ply-hack/790ee177-3522-48ac-867d-d31faf4f5662%40googlegroups.com
> .
>
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
--
You received this message because you are subscribed to the Google Groups
"ply-hack" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ply-hack/CAEs%3D1RiVMzTpoMo%2BD1GPcG0svpyy%3DyfxrgfbPB%2BQnvsLQa4Mzw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.