27 March 2000 Release 2.22 Notes for New Users of PCCTS Version 1.33MR22
27
#if 0
Hoisting of predicate suppressed by alternative without predicate.
The alt without the predicate includes all cases where the predicate is
false.
WITH predicate: line 8 infop.g
WITHOUT predicate: line 9 infop.g
The context set for the predicate:
B
The lookahead set for the alt WITHOUT the semantic predicate:
B
The predicate:
pred << pc(LT(1))>>?
depth=k=1 rule c line 8 infop.g
set context:
B
Chain of referenced rules:
#0 in rule start (line 3 infop.g) to rule all
#1 in rule all (line 4 infop.g) to rule a
#2 in rule a (line 7 infop.g) to rule c
#3 in rule c (line 8 infop.g)
#endif
&&
#if 0
pred << pb(LT(1))>>?
depth=k=1 rule b line 11 infop.g
set context:
X
#endif
#138. Semantic predicates, predicate context, and hoisting
The interaction of semantic predicates with hoisting is sometimes subtle. Hoisting involves the evaluation of
semantic predicates in a rule's parent in order to determine whether the rule associated with the semantic predicate
is "viable". There are two ways to generate code for semantic predicates which are "hoisted" into a parent rule.
With "­prc off", the default, the behavior of semantic predicates resembles gates which enable or disable various
productions. With "­prc on" the behavior of semantic predicates resemble a token for which its token type is
determined by run-tine information rather than by purely lexical information. It is important to understand what
"-prc on" does, when to use semantic predicates, and when to choose an alternative method of using semantic
information to guide the parse. We start with a grammar excerpt which does not require hoisting, then add a rule
which requires hoisting and show the difference in code with predicate context computation off (the default) and on.
Consider:
statement
: upper
| lower
| number
;
upper : <<isU(LT(1)->getText())>>? ID ;
lower : <<isL(LT(1)->getText())>>? ID ;
number : Number ;