[antlr-interest] automatically generated syntatic predicates become semantic predicates (fragments) plus arguments generate parser which doesn't compile

Johannes Luber jaluber at gmx.de
Tue Sep 16 07:41:34 PDT 2008


Doucette, Charles schrieb:
> Sorry - that was sent prematurely:
> 
> Here are my grammar options.
> I don't completely understand what they mean.
> I inherited them when I started with a Java grammar.
> 
> options {
>         k=2;

k=2; sets the lookahead to a maxmimum of two tokens.
>         backtrack=true;

backtrack=true; activates backtracking. If you don't know what
backtracking does, Wikipedia has an article about it.

>         memoize=true;

With this option you store temporary results created by backtracking.
Increased memory usage for speeding up the analysis.

> //      output=AST;

With no output-option function don't return only void, unless specified
otherwise via the return keyword.
> }
> 
> When I tried to remove them and use the default options - I did get many errors and warnings.
> I guess I have to follow your suggested tutorial to remove backtracking?

Right. Be aware that it is time consuming to do it right and to get
really rid of all instances. Depending on the source of the Java grammar
you may want to postpone this until you are more familiar with ANTLR.
> 
> I didn't explicitly use arguments and predicates. ANTLR automatically generated the predicates for me;
> probably based on my grammar options above.

Correct.

Johannes
> 
>>> It's a user bug. Arguments and predicates don't mix. Use scopes
>>> instead like this.
>>>
>>> rule a
>>> scope {
>>> int i;
>>> }
>>>    : (pred)=> y {$a::i = 3;}
>>>    ;
> 
> Thanks,
> Chuck
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
> 



More information about the antlr-interest mailing list