[antlr-interest] lexical nondeterminism
None None
new_open_close at yahoo.com
Thu Sep 15 06:51:54 PDT 2005
This might be in the FAQ, but I haven't seen it. A
few months ago I started to look at antlr and had a
lexical problem. I haven't had a chance to look at
again until today, but when I tried some of the
suggestions they didn't work. If anyone could point
me in the correct direction it would be much
appreciated.
I have a file called dms.g that contains the
following:
class TestLexer extends Lexer;
options {
k=10;
}
protected LATLON : DMS "," DMS | FLOAT "," FLOAT;
protected DMS : DIGIT DIGIT (DIGIT)? ":" DIGIT
DIGIT ":" DIGIT DIGIT "." DIGIT;
protected FLOAT : (SIGN)? (DIGIT)+ ( "." (DIGIT)* )?;
protected SIGN : "+" | "-";
protected DIGIT : '0'..'9';
When I run "antlr dms.g" I get the following output
ANTLR Parser Generator Version 2.7.5 (20050615)
1989-2005 jGuru.com
dms.g:7: warning:lexical nondeterminism between alts 1
and 2 of block upon
dms.g:7: k==1:'0'..'9'
dms.g:7: k==2:'0'..'9'
dms.g:7: k==3:'0'..'9'
dms.g:7: k==4:'0'..'9'
dms.g:7: k==5:'0'..'9'
dms.g:7: k==6:'0'..'9'
dms.g:7: k==7:'0'..'9'
dms.g:7: k==8:'0'..'9'
dms.g:7: k==9:'.','0'..'9'
dms.g:7: k==10:'.','0'..'9'
It seems to me that by the 3rd or 4th token the ":"
the lexer should be able to tell which production (DMS
or FLOAT) was being constructed. The thing puzzles me
is that if the DMS rule is changed to:
protected DMS : DIGIT DIGIT DIGIT ":" DIGIT DIGIT
":" DIGIT DIGIT "." DIGIT;
antlr is happy and doesn't issue any errors!
Thanks in advance.
______________________________________________________
Yahoo! for Good
Donate to the Hurricane Katrina relief effort.
http://store.yahoo.com/redcross-donate3/
More information about the antlr-interest
mailing list