[antlr-interest] Question on the protected keyword in lexer
Subhobroto Sinha
subhobrotosinha at rediffmail.com
Mon Jul 4 11:02:22 PDT 2005
When I hit a block in parsing ints and floats, a little bit of Googling turned out that I was not the first one ;)
As I have found the ANTLR docs to be lacking for beginners, I have (unofficially) set myself to document the way I am working with ANTLR - perhaps it can help a newbie or two after me.
Currently, I am very interested in gathering as much as possible re/ parsing floats and ints.
Here's my first question :
Consider the grammar :
FLOAT_OR_INT : ( INT '.' ) => FLOAT { $setType(FLOAT); }
| INT { $setType(INT); } ;
protected INT
options {
testLiterals = true;
paraphrase = "a constant integer";
}
: ('0' .. '9')+;
protected FLOAT
options {
testLiterals = true;
paraphrase = "a floating point value";
}
: INT '.' INT;
If I remove 'protected' from the tokens, ANTLR hits me with :
ANTLR Parser Generator Version 2.7.5 (20050201) 1989-2005 jGuru.com
DSD.g: warning:lexical nondeterminism between rules FLOAT_OR_INT and INT upon
DSD.g: k==1:'0'..'9'
DSD.g: warning:lexical nondeterminism between rules FLOAT_OR_INT and FLOAT upon
DSD.g: k==1:'0'..'9'
DSD.g: warning:lexical nondeterminism between rules INT and FLOAT upon
DSD.g: k==1:'0'..'9'
but it issues no warning if INT and FLOAT are made protected.
Can you explain the reasons for the warnings (verbosely if possible) ?
If the responses are assuring, I intend to follow up with more technical questions which are already running wild in me.
Finally, I hope to consolidate all the answers into a verbose FAQ entry.
Regards
Subhobroto Sinha
http://www.geocities.com/subhobrotosinha
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20050704/73dacc70/attachment.html
More information about the antlr-interest
mailing list