[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 03:42:27 PDT 2008


Doucette, Charles schrieb:
> Many of my grammar rules have arguments.
> 
> Very few of my productions use explicit syntactic predicates or semantic
> predicates.
> 
> Almost all of them seem to generate implicit syntactic/semantic
> predicates (except the last production of each rule).

That seems suspicious. Are you sure that no alternative is disabled? Do
you use backtracking for convenience? There is a tutorial which
describes the removal of global backtracking on the wiki.
> 
> Here’s the one that is giving me trouble:
...
> When I look at this rule in ANTLRworks, it says that the production for
> commonObjectBodyElement corresponds to the semantic predicate
> {synpred20_vscript}?.
> 
> That generated code looks like this:
...
> This obviously doesn’t compile since it refers to an argument of a
> parent rule (which is not part of the current context).
> 
> Is this an ANTLR bug or a user bug?
> 
> In any case, how can I refactor my grammar to avoid this situation (and
> generate a parser which will compile)?
> 
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;}
   ;

Johannes


More information about the antlr-interest mailing list