27 March 2000 Release 2.22 Notes for New Users of PCCTS Version 1.33MR22
33
If it is an ID and:
a. it is an external command name => command
b. it is followed by a paren => fun_call
c. otherwise => command
If it is an @ and:
a. the ID is a var name => fun_call
b. otherwise => command
One can implement these rules quite neatly using && predicates:
call : ("@" ID)? && <<isVarName(LT(2))>>? fun_call
| (ID)? && <<isExtCmdName>>? command
| (ID "(")? fun_call
| command
;
#142. Experimental
ANTLR
option -mrhoistk on for suppression of predicates with lookahead depth
k
> 1
The
ANTLR
option -mrhoist provides fairly complete handling of predicates with lookahead depth of 1. The
handling of predicates with lookahead depth greater than one is more complicated and the solution provided by
PCCTS
is good, but not complete.
Consider the following grammar with -ck 2 and the predicate in rule "a" with depth 2:
r1 : (ab)* "@" ; /* 2 */
ab : a /* 3 */
| b /* 4 */
; /* 5 */
a : (A B)? => <<p(LT(2)>>? A B C ; /* 6 */
b : A B C ; /* 7 */
Without "-mrhoistk on" the predicate would be hoisted into rule r1 in order to determine whether to call rule "ab".
However it should
not
be hoisted because, even if p is false, there is a valid alternative in rule b. With "-mrhoistk
on" the predicate will be suppressed.
With the "-mrhoistk on" and "-info p" the following information will appear in the generated code:
while ( (LA(1)==A)
#if 0
Part (or all) of predicate with depth > 1 suppressed by alternative without
predicate
pred << p(LT(2)>>?
depth=k=2 ("=>" guard) rule a line 6 t1.g
tree context:
(root = A
B
)
The token sequence which is suppressed: ( A B )
The sequence of references which generate that sequence of tokens:
1 to ab r1/1 line 2 t1.g
2 ab ab/1 line 3 t1.g
3 to b ab/2 line 4 t1.g
4 b b/1 line 7 t1.g
5 #token A b/1 line 7 t1.g
6 #token B b/1 line 7 t1.g
#endif
) {
ab();
}
}