[antlr-interest] Trouble with lexer ambiguity
Michael Stover
michael.r.stover at gmail.com
Sun May 30 15:37:44 PDT 2010
I'm making a grammar that knows how to parse coordinates, such as:
4,5
It knows about offsets, like:
+2,-8
It should parse adding coordinates together:
4,5+5,9
However, it seems to see the '+' and from there predict the next token to be
an offset, despite the fact there is not '+'|'-' before the '9'.
Here's the grammar I think should work (I made k large enough to show it's
not helping, no matter how large):
grammar Test;
main : COORD '+' COORD
| OFFSET
;
COORD options{k=7;} : '0'..'9'+ ',' '0'..'9'+
;
OFFSET options{k=7;} : ('+'|'-') '0'..'9'+ ',' ('-'|'+') '0'..'9'+
;
WS : ( ' '
| '\t'
| '\r'
| '\n'
) {$channel=HIDDEN;}
;
What am I missing?
More information about the antlr-interest
mailing list