[antlr-interest] help understanding the parsing error
John B. Brodie
jbb at acm.org
Fri May 11 15:42:38 PDT 2012
On 05/11/2012 11:29 AM, Mikhail Kruk wrote:
> I have a very simple grammar (attached, but here's the relevant part):
> : (simple_expression | dotted_identifier)*
> : 'XYZ' 'HAHA'
> : ID
> : identifier ( DOT identifier )*
> It pretty much works as expected, accepting "XYZ HAHA", "BLAH.TEST"
> and "ABC". But when I try to parse "XYZ.A" or "A.XYZ" it gets
> confused trying to apply simple_expression to 'XYZ'. I don't
> understand why this is happening. Shouldn't backtracking tear right
> through this?
ANTLR does not backtrack across the Parser-Lexer interface.
So as soon as the Lexer recognizes string "XYZ" as the keyword in your
grammar 'XYZ' it can never be (re-)considered to be an ID token.
Please search the mailing list archives for "keywords as identifiers" or
other similar searches for the ways around this issue.
Hope this helps...
More information about the antlr-interest