27 March 2000 Release 2.22 Notes for New Users of PCCTS Version 1.33MR22
13
#57.
Summary of command line switches related to ambiguity aid
The ambiguity aid is controlled by the following command line options:
-aa
ruleName
Selects reporting by name of rule
-aa
lineNumber
Selects reporting by line number (the file name is not used).
-aad
depth
Selects the depth of the search. The default value is 1.
The number of paths to be searched, and the size of the report can grow geometrically with the -ck value
if a full search for all contributions to the source of the ambiguity is explored. The depth represents the
number of tokens of lookahead which are matched against the sets of ambiguous tokens. A depth of 1
means that the search stops when a lookahead sequence of just one token is matched.
A k=1 ck=6 grammar might generate 5,000 items in a report if a full depth 6 search is made with the
ambiguity aid. The source of the problem may be in the first token and obscured by the volume of data -
I hesitate to call it information.
When the user selects a depth > 1, the search is first performed at depth=1 for both alternatives, then
depth=2 for both alternatives, etc.
-aam
Enables "multiple" reporting for a token in the intersection set of the alternatives. The default is "off".
A given token may appear dozens of times in various paths as the program explores the rules which are
reachable from the point of an ambiguity. With option -aam every possible path the search program
encounters is reported.
Without -aam only the first encounter is reported. This may result in incomplete information, but the
information may be sufficient and much shorter.
C++ Mode
#58.
The destructors of base classes should be virtual in almost all cases
If you don't know why you should read Scott Meyers' excellent book, "Effective C++, Fifty Specific Ways ...".
#59.
Why must the AST root be declared as ASTBase rather than AST ?
The functions which implement the rules of the grammar are declared with the prototype:
void aRule(ASTBase ** _root) {...};
The underlying support code of
ANTLR
depends only on the behaviors of ASTBase. There are two virtues to this
design:
No recompilation of the underlying routines is necessary when the definition of AST changes
The same object code can be used with multiple parsers in the same program each with its own kind of AST
This is in contrast to C++ templates which are designed to provide source code reuse, not object code reuse.
An "AST *" can be passed to an "ASTBase *" why not an "AST **" for an "ASTBase **" ?
This is a C++
FAQ
. Consider the following (invalid) code fragment:
struct B {}; /* a1 */
struct D1 : B {int i;}; /* a2 */
struct D2 : B {double d;}; /* a3 */
void func(B ** ppB) {*ppB=new D2;}; /* WRONG */ /* a4 */
D1 * pD1=new D1; /* a5 */
func(&pD1); /* a6 */
At line a5, pD1 is declared to be a pointer to a D1. This pointer is passed to "func" at line a6. The function body at
line a4 replaces a pointer to a D1 with a pointer to a D2, which violates the declaration at line a5.
The following
is
legal, although it may not do what is expected:
void func2(B * pB) {D1 d1; *pB=d1;}; /* b1 */
func2(pD1); /* b2 */
The assignment at line b1
slices
d1 and assigns only the B part of d1 to the object pointed to by pB because the
assignment operator chosen is that of class B, not class D1.