[antlr-interest] the nihilistic circle hoist

Ron Burk ronburk at gmail.com
Mon Jan 3 11:15:59 PST 2011


After more tinkering, it appears there are two
separate bugs. First, the code generated for
predicate hoisting may simply be wrong when
the "+" EBNF operator is used. The second
is the more systemic problem that hoisted
predicates can be executed in the wrong syntactic
context.

The first bug can be seen in Wincent's original
report:

grammar Simple;

FOO : 'foo' ;

section : element* EOF ;
element : {P1}?=> pre ;
pre : FOO+ ;

The code generated for the previous grammar can
consume no FOOs. But after changing FOO+ to FOO FOO*:

grammar hoist1;

FOO : 'foo' ;

section : element* EOF ;
element : {P1}?=> pre ;
pre : FOO FOO* ;

This grammar, though it should produce identical
behavior to the previous one, does not. It correctly
consumes one FOO for every 'pre'. It does, however,
still suffer from the second bug, since 'pre' contains
a predicate that will "taint" any unrelated nonterminal
that uses it. E.g.:

...
unrelated : '(' pre ')' ;

This latter rule cannot match ( FOO FOO ) because
'pre' is executing predicate P1 in a completely unrelated
syntactic context. (assume P1 = true).


More information about the antlr-interest mailing list