[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:16:15 PDT 2008


Doucette, Charles schrieb:
>> 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.
> 
> I don't know what it means for "no alternative to be disabled."

When ANTLR discovers ambiguities it shows warnings that it doesn't know
which path it should prefer and that it disables all paths but the first
one. You have to tell ANTLR manually which path you want by the means
described in the "Global backtracking removal" tutorial.
> 
> Here are my grammar options:

You didn't included them.

Johannes
> 
> 
>>> 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