[antlr-interest] non-determinism warning
Monty Zukowski
monty at codetransform.com
Tue Jul 5 12:01:47 PDT 2005
Tarun Khanna wrote:
> Hi All,
>
> I stumbled across this problem once more, so here I am looking for some
> standard solution to such a problem.
>
> Consider the following production ->
>
> F: LP exp RP | (DOT IDENT)* (DOT TAB)?
>
> There is non-determinism because the parser doesn't know, when to stop
> matching the first DOT and start looking for the second DOT.
>
> Syntactic or semantic predicates can not be used as, there are no
> alternates. I don't want to use a look ahead of more than 1.
>
Why not? ANTLR only uses the extra lookahead when it is necessary. k=2
is the perfect solution for this.
Otherwise you could keep your own state and do something like
(DOT
{!tabMatched}?(IDENT|TAB{tabMatched=true;})
| (SOME_IMAGINARY_TOKEN_THAT_YOUR_LEXER_NEVER_PRODUCES)
)*
Monty
More information about the antlr-interest
mailing list