[antlr-interest] Actions and non-LL(*) rules ??

Terence Parr parrt at cs.usfca.edu
Mon May 3 15:47:37 PDT 2010


Marcin, ANTLR should let backtracking predicates work even with actions.
Ter
On May 3, 2010, at 3:36 PM, Marcin Rzeźnicki wrote:

> 2010/5/3 Marcin Rzeźnicki <marcin.rzeznicki at gmail.com>:
>> 2010/5/3 Terence Parr <parrt at cs.usfca.edu>:
>>> it still won't execute the {{...}}} before the pred is evaluated during
>>> prediction. it must not eval disambiguating preds after actions in any
>>> circumstance.
>>> Ter
>> 
>> I see. So that poses yet another problem with recursive tree-like
>> definitions. If I got production like
>> 
>> s returns[Tree tree]
>> :
>> a1=a {$tree = $a1.tree; }  (DELIMITER a2=a {$tree = new Tree($tree,$a2.tree);})*
>> 
>> AND there is an ambiguity in whether to enter the loop or leave it (it
>> creates predicate under the hood) then the first action hides that
>> predicate. Then the solution is to explicitly check in the second
>> action whether current iteration is the first one, which is pretty
>> ugly and imposes performance hit as this means that this test is
>> repeated on every loop roll, or unroll the loop manually one time
>> which is ugly too :-/ I suppose there is no syntax which marks an
>> action as predicate-safe? :-)
>> 
> All this is harder than it sounds, I see - as lot of problems emerge
> from automatically generated ANTLR predicates. In presence of this
> discovery my question is: how can you deal with actions and implicit
> predicates? I cannot "move" the predicate to the left obviously, and
> this "hiding" rule seems to be really constraining in this case.
> 
> -- 
> Greetings
> Marcin Rzeźnicki



More information about the antlr-interest mailing list