[antlr-interest] Ambiguous lexer rules
Fs Cc
reginfo_ar at ymail.com
Fri Jul 1 02:18:16 PDT 2011
Hi,
How can I resolve the ambiguous antlr3 lexer rules in following case:
xstr [aaa ----> A xstr whose value is '[aaa'
[aaa bbb ccc] ----> An array with 3 strings: 'aaa' 'bbb' 'ccc'
So I write following rules:
STRING : ('a'..'z' | 'A'..'Z' | '0'..'9')+; # only contains digits and letters
XSTRING : '\u0021'..'\u007e'+; # 0x21-0x7e are the readable ascii chars.
xstr : 'xstr' (XSTRING | STRING);
array : '[' STRING+ ']';
But the array rule doesn't work, because '[aaa' is treated as a XSTRING
rather than '[' and 'aaa'.
How can I fix it?
Thanks,
Fussi
More information about the antlr-interest
mailing list