[antlr-interest] Re: Local lookahead depth

Oliver Zeigermann oliver at zeigermann.de
Sat Nov 8 13:35:49 PST 2003


Hi Loring!

lgcraymer wrote:
> ANTLR is actually quite a bit smarter about lookahead--k is maximum lookahead, and ANTLR generates minimum lookahead.  If you 
> set k=20 but don't need more than k=2, then 2 is the maximum lookahead in the generated code.  I think that Sriram put local 
> lookahead into JavaCC as a workaround--it does add a step to grammar debugging that is not necessary for ANTLR.

Hmmm. Is this true? Definitly not when using greedy blocks... Have a 
look at this simple grammar

top : TOKEN0 (sub | top )* TOKEN3 ;

sub : TOKEN1
         ( options {greedy=false;} : . )*
         TOKEN2
     ;

k=1 is needed and works ok. Try using k=10 and: Ooops!

> Also, as to actions in lookahead code:  this is something that Ter supported in PCCTS under the name "guarded predicates" or some 
> such.  I don't know that it saw much use, and I suspect that usage indicates a too early incorporation of semantic information into the 
> translator--tree transformation helps avoid that.

1.) You might really increase the set of parseable languages using this 
technique
2.) Sometimes using tree transformation is too expensive

> LLK is interesting, but it is a synthesis of implementation approaches from a number of sources (ANTLR, JavaCC, flex) and not an 
> extension to the state of the art.  I think that's why Leung describes it as an ANTLR 2.7.2 derivative despite what seems to be the 
> complete absence of any ANTLR 2.7.2 source code in the distribution.  It is also a work in progress.

Who knows ;) In any case it brings a bit life into discussion :)

Oliver



 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list