[antlr-interest] Can't figure out the ambiguity leading to this unreachable token def
Kamil Burzynski
nopik at data.pl
Sun Apr 6 01:33:44 PDT 2008
Hello Dan,
Dan wrote:
> Thanks Kamil.
> But when you look at my grammar, doesn't the "expr" rule make it clear
> that only the "VALUE" rule can match what's inside the single quotes?
Lexer do not look at expr rule. expr is parser rule. In general it works
like this:
- in case of parser/lexer combined grammar (like your) rule with name
beginning with small letter is parser rule, while capital letter at
beginning of rule name indicates lexer rule.
- so, you have expr parser rule and NAME/VALUE lexer rules
- the first thing your generated code does is just to split input
characters into tokens, using lexer rules. Parser rules will be later
used to process resulting token stream.
- lexer therefore is not aware of context - it just matches characters,
so such definition of NAME and VALUE is ambiguous for it.
I suggest rewriting VALUE to :
VALUE = '\'' ('a'..'z' | 'A'..'Z')+ '\''
and remove ' from expr.
--
Best regards from
Kamil Burzynski
More information about the antlr-interest
mailing list