[antlr-interest] Lexer rule match keyword or identifier depending on the previous token
Guillaume Chavanon
guillaume.chavanon at systemsvip.com
Mon Aug 20 02:44:39 PDT 2007
Hi all,
I am writing a grammar for a language that allow some keywords to be
identifiers if they are preceded by a special character.
Is it possible to add gated semantic predicate in a lexer rule that will
test the previous token ?
I would like to do something like this :
IDENTIFIER
: { previousToken != ... }?=> 'KEYWORD1' {$type=KEYWORD1;}
| { previousToken != ... }?=> 'KEYWORD2' {$type=KEYWORD2;}
| 'A'..'Z' ( '_'? ( 'A'..'Z' | '0'..'9' ) )*
;
Thanks in advance,
Guillaume Chavanon
More information about the antlr-interest
mailing list