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).

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to