[antlr-interest] identifier vs keyword issue
Joep Suijs
jsuijs at gmail.com
Thu Apr 15 13:02:27 PDT 2010
Hi guys,
I am working on parser for JAL, 'Just Another Language' for Microchips
PIC microcontrollers.
Within JAL you can define a variable like:
var byte data
where 'data' is a valid identifier, matched by
IDENTIFIER : LETTER (LETTER|'0'..'9')* ;
fragment LETTER : 'A'..'Z' | 'a'..'z' | '_' ;
Now I want to add support for pragma statement, used for the setup of
the microcontroller. An example (one of quite a few) of this is:
pragma data 0x20-0x6F,0xA0-0xEF
With:
pragma
: 'pragma'^ (
( 'target' pragma_target )
| ( 'data' constant '-' constant (',' constant '-' constant)* )
)
;
This works okay, but does break the parsing of identifiers like 'data'.
How can antlr (in general) handle keywords within a specific context,
while retaining the possibility to use these keywords as identifiers
in the general context?
Any advice is appreciated!
Joep
PS Amongst others, the full grammar (current state, not completed) is
at http://code.google.com/p/jallib/source/browse/#svn/trunk/grammar
More information about the antlr-interest
mailing list