27 March 2000 Release 2.22 Notes for New Users of PCCTS Version 1.33MR22
3
#94. For doubly linked ASTs derive from class ASTDoublyLinkedBase and call tree­>double_link(0,0)
18
#95. When ASTs are constructed manually the programmer is responsible for deleting them on rule failure
18
Rules
#96. To refer to a field of an
ANTLR
Token within a rule's action use
<<... mytoken($x)->field...>>
19
#97. Rules don't return tokens values, thus this won't work:
rule: r1:rule1 <<...$r1...>>
19
#98. A simple example of rewriting a grammar to remove left recursion
19
#99. A simple example of left-factoring to reduce the amount of
ANTLR
lookahead
19
#100.
ANTLR
will guess where to match "
@
" if the user omits it from the start rule
20
#101. To match any token use the token wild-card expression "." (dot)
20
#102. The "~" (tilde) operator applied to a #token or #tokclass is satisfied when the input token does
not
match
20
#103. To list the rules of the grammar grep
parserClassName.
h for "_root" or edit the output from
ANTLR
­cr
­
#104. The
ANTLR
­gd trace option can be useful in sometimes unexpected ways
20
#105. Associativity and precedence of operations is determined by nesting of rules
20
#106. #tokclass can replace a rule consisting only of alternatives with terminals (no actions)
21
#107. Rather than comment out a rule during testing, add a nonsense token which never matches - See Item #110. ­
Init-Actions
#108. Don't confuse init-actions with leading-actions (actions which precede a rule)
21
#109. An empty sub-rule can change a regular action into an init-action
22
#110. Commenting out a sub-rule can change a leading-action into an init-action
22
#111. Init-actions are executed just once for sub-rules:
(...)+
,
(...)*
, and
{...}
22
Inheritance
#112. Downward inherited variables are just normal C arguments to the function which recognizes the rule
22
#113. Upward inheritance returns arguments by passing back values
23
#114. Be careful about passing via upward inheritance LT(i)->getText() if using
ANTLR
CommonToken
23
#115.
ANTLR
­gt code will include the AST with downward inheritance values in the rule's argument list
­
#116. Predefine the
PURIFY
macro if you are passing objects using upward inheritance
23
Syntactic Predicates
#117. Normal actions are suppressed while in guess mode because they have side effects
­
#118. Automatic construction of ASTs is suppressed during guess mode because it is a side effect
­
#119. Syntactic predicates should not have side-effects
24
#120. How to use init-actions to create side-effects in guess mode (despite Item #119)
24
#121. With values of
k
>1 or infinite lookahead mode one cannot use feedback from parser to lexer
24
#122. Can't use interactive scanner (
ANTLR
­gk option) with
ANTLR
infinite lookahead
­
#123. Syntactic predicates are implemented using setjmp/longjmp - beware C++ objects requiring destructors
­
Semantic Predicates
#124. Semantic predicates have higher precedence than alternation:
<<>>? A|B
means
(<<>>? A)|B
­
#125. Get rid of warnings about missing LT(i) by using a comment:
/* LT(i) */
­
#126. It is sometime desirable to use leading actions to inhibit hoisting of semantic predicates
­
#127. Any actions (except init-actions) inhibit the hoisting of semantic predicates
24
#128. Semantic predicates that use local variables or require init-actions must inhibit hoisting
­
#129. Semantic predicates that use inheritance variables must not be hoisted
24
#130. A semantic predicate which is not at the left edge of a rule becomes a validation predicate
24
#131. Semantic predicates are not always hoisted into the prediction expression
25
#132. Semantic predicates can't be hoisted into a sub-rule: "
{x} y
" is not exactly equivalent to "
x y | y
"
25
#133. How to change the reporting of failed semantic predicates
25
#134. A semantic predicate should be free of side-effects because it may be evaluated multiple times
25
#135. There's no simple way to avoid evaluation of a semantic predicate for validation after use in prediction
­
#136. What is the "context" of a semantic predicate ?
26
#137. Use
ANTLR
option "-info p" for information on how semantic predicates are being handled and hoisted
26
#138. Semantic predicates, predicate context, and hoisting
27
#139. Another example of predicate hoisting
28
#140. Example of predicate hoisting and suppression with the
ANTLR
option -mrhoist on
29
#141. The context guard
(...)? && <<predicate>>?
vs.
(...) => <<predicate>>?
31