[antlr-interest] Lexer rule match keyword or identifier depending on the previous token
Edwards, Waverly
Waverly.Edwards at genesys.com
Mon Aug 20 06:21:30 PDT 2007
Is this different that looking ahead? If you are at token B and token A
determines
how your respond to token B then wouldn't this be the same as being at
token A, looking
ahead and seeing token B then responding the same way? I don't know the
circumstance
so I don't really know. I haven't figured out how the lookahead in
ANTLR works just yet
but I know it exists.
W.
-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Guillaume
Chavanon
Sent: Monday, August 20, 2007 5:45 AM
To: antlr-interest at antlr.org
Subject: [antlr-interest] Lexer rule match keyword or identifier
depending on the previous token
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