27 March 2000 Release 2.22 Notes for New Users of PCCTS Version 1.33MR22
23
#113. Upward inheritance returns arguments by passing back values
If the rule has more than one item passed via upward inheritance then
ANTLR
creates a
struct
to hold the result
and then copies each component of the structure to the upward inheritance variables.
#token T_int
#token T_real
#token T_complex
class P {
...
number : <<int useRadix=10;int iValue;double rValue;double rPart,iPart;>>
{ radix > [useRadix] }
intNumber [useRadix] > [iValue]
| realNumber > [rValue]
| complexNumber > [rPart,iPart]
;complexNumber > [double rPart,double iPart] :
"\[" realNumber > [$rPart] "," realNumber > [$iPart] "\]"
;realNumber > [double result] :
v:"[0-9]+.[0-9]*" <<$result=toDouble($v);>>
;radix > [int i] : v:"%[0-9]+" <<$i=toInt($v);>>
;intNumber [int radix] > [int result] :
v:"[0-9]+" <<$result=toInt($v);>>
;}
This example depends on the use of several constructors for ASTs and user defined routines toInt() and toDouble().
#114. Be careful about passing via upward inheritance LT(i)->getText() if using
ANTLR
CommonToken
If the token is destroyed due to the reference count going to 0 will the text still be valid ?
#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
The default PURIFY macro zeroes the memory occupied by objects passed via upward inheritance. If your object
has a non-trivial default constructor this could cause problems.
Syntactic Predicates
The terms "infinite lookahead", "guess mode", and "syntactic predicate" all imply use of the same facility in
PCCTS
to
provide a limited amount of backtracking by the parser. In this case we are
not
referring to backtracking in
DLG
or other
lexers. The term "syntactic predicate" emphasizes that it is handled by the parser. The term "guess mode" emphasizes that
the parser may have to backtrack. The term "guess mode" may also be used to distinguish two mutually exclusive modes
of operation in the
ANTLR
parser:
- Normal mode: A failure of the input to match the rules is a syntax error. The parser executes actions,
constructs ASTs, reports syntax errors it finds (or invokes parser exception handling) and attempts automatic
recovery from the syntax errors. There is no provision for backtracking in this mode.
- Guess mode: The parser attempts to match a "
(...)?
" block and knows that it must be able to backtrack if
the match fails. In this case the parser does
not
execute user-actions (except init-actions), nor does it construct
ASTs. Failed semantic predicates cause backtracking, except when they are validation predicates.
In C++ mode, lookahead uses a sliding window of tokens whose initial size is specified when the
ANTLR
TokenBuffer is
constructed. In C mode the entire input is read, processed, and tokenized by
DLG
before
ANTLR
begins parsing. The term
"infinite lookahead" derives from the initial implementation in
ANTLR
C mode.
#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