27 March 2000 Release 2.22 Notes for New Users of PCCTS Version 1.33MR22
31
#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 5 c.g
WITHOUT predicate: line 6 c.g
The context set for the predicate:
ID
The lookahead set for the alt WITHOUT the semantic predicate:
ID
The predicate:
pred << pb(LT(1))>>?
depth=k=1 rule b line 8 c.g
set context:
ID
Chain of referenced rules:
#0 in rule a (line 2 c.g) to rule bc
#1 in rule bc (line 5 c.g)
#endif
if ( (LA(1)==ID) ) {
bc();
}
else {
if ( (LA(1)==ID)&&
#if 0
pred << pd(LT(1))>>?
depth=k=1 rule d line 10 c.g
set context:
ID
#endif
(!(((LA(1)==ID)))||(pd(LT(1)))) ) {
d();
...
There are additional examples in the
CHANGES_FROM_133*.TXT
files.
#141.
The context guard
(...)? && <<predicate>>?
vs.
(...) => <<predicate>>?
The idea for the new (...)? && <<predicate>>? is due to Reinier van der Born (reinier@vnet.ibm.com)
The
(...)? =>
predicate guard does not apply the predicate if the context guard doesn't match, whereas the
(...)? &&
form requires both the predicate guard and the predicate to be true to make the alternative viable.
What is the significance ?
If you have a predicate which is
not
on the "leading edge" it cannot be hoisted. Suppose you need a predicate that
looks at LA(2). You must introduce it manually. The classic example is:
castExpr : LP typeName RP
| ....
;
typeName : <<isTypeName(LT(1))>>? ID
| STRUCT ID