27 March 2000 Release 2.22 Notes for New Users of PCCTS Version 1.33MR22
30
The extra code checks that the predicate pb is evaluated only when the lookahead is ID. Since we always expect the
predicate to be ID this provides no extra power.
With option -mrhoist on the code generated for rule "a" resembles:
if (LA(1)==ID) {
bc();
} else if (LA(1)==ID && ((! LA(1)==ID) || pd)) {
d();
} ...
This is the correct code sequence. However, we have a warning:
c.g(2) : warning: alt 1 line 2 and alt 2 line 3 of of the rule itself
These alts have ambig lookahead sequences resolved by a predicate for
the second choice. The second choice may not be reachable.
You may want to use a complementary predicate or rearrange the alts
The problem is that the prediction expression for bc in rule a will always match an ID. This is the correct prediction
expression because rule c is always viable when the lookahead is ID, but the alternative for rule d in rule a is no
longer reachable when the lookahead is ID. Hence the warning.
We now return to the topic of predicate hoisting. Using the
ANTLR
-info p option we would find the following note
in the generated code: