[antlr-interest] Non-LL(*) Constructs

Joseph Klumpp jklumpp0 at gmail.com
Fri Mar 27 07:46:45 PDT 2009


The definitive ANTLR reference uses the following grammar as an
example of resolving Non-LL(*) Constructs with Syntactic Predicates:

grammar x;
s : e '%'
  | e '!'
  ;
e : '(' e ')'
  | INT
  ;
INT : '0'..'9' + ;

and notes that this grammar can handle (3)! but cannot handle ((3))!,
because the DFA cannot figure out what to do when e invokes itself.
But, e does invoke itself: s=>e! => '(' e ')'! => '('INT')'! =>
'('3')'!.

My question is:
Why does this work with one recursive invocation, but not two or more?

Thanks in advance,
JK


More information about the antlr-interest mailing list