[antlr-interest] How to get the last token type just recognized in the lexer?
chain one
chainone at gmail.com
Fri Nov 21 05:30:57 PST 2008
I am right now using antlr V2 to write a parser.And I meet this
problem,don't know how to fix it.
The problem is:
Lexer rule:
INT
: (DIGIT)+
;
FLOAT
: '.' (DIGIT)+ (('e' | 'E') ('+' | '-')? (DIGIT)+)?
| '.' ('e' | 'E') ('+' | '-')? (DIGIT)+
;
DIGIT
: '0'..'9'
;
I want to match the strings like:
0.1E-10
0.1e+1
0.0
0.E14
To deal with the case like:"class.e9", ".e9" here could be accepted by FLOAT
rule and ID rule
So it seems that the only solution is to predict the last token just
recognized, if the last token is a INT, then FLOAT rule should be followed.
so I need to know what the last token is.
calling function LA(-1) could do this, however LA(-1) is only available in
parser not in lexer
So...Is there anyone could tell me how to get the last token type
just recognized in the lexer?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20081121/0ce5b75c/attachment.html
More information about the antlr-interest
mailing list