Public Member Functions | |
void | addChild (AST node) |
int | getNumberOfChildren () |
boolean | equals (AST t) |
boolean | equalsList (AST t) |
boolean | equalsListPartial (AST sub) |
boolean | equalsTree (AST t) |
boolean | equalsTreePartial (AST sub) |
ASTEnumeration | findAll (AST target) |
ASTEnumeration | findAllPartial (AST sub) |
AST | getFirstChild () |
AST | getNextSibling () |
String | getText () |
int | getType () |
int | getLine () |
int | getColumn () |
abstract void | initialize (int t, String txt) |
abstract void | initialize (AST t) |
abstract void | initialize (Token t) |
void | removeChildren () |
void | setFirstChild (AST c) |
void | setNextSibling (AST n) |
void | setText (String text) |
void | setType (int ttype) |
String | toString () |
String | toStringList () |
String | toStringTree () |
void | xmlSerializeNode (Writer out) throws IOException |
void | xmlSerializeRootOpen (Writer out) throws IOException |
void | xmlSerializeRootClose (Writer out) throws IOException |
void | xmlSerialize (Writer out) throws IOException |
Static Public Member Functions | |
static void | setVerboseStringConversion (boolean verbose, String[] names) |
static String[] | getTokenNames () |
static String | decode (String text) |
static String | encode (String text) |
Protected Attributes | |
BaseAST | down |
BaseAST | right |
A Child-Sibling Tree.
A tree with PLUS at the root and with two children 3 and 4 is structured as:
PLUS | 3 -- 4
and can be specified easily in LISP notation as
(PLUS 3 4)
where every '(' starts a new subtree.
These trees are particular useful for translators because of the flexibility of the children lists. They are also very easy to walk automatically, whereas trees with specific children reference fields can't easily be walked automatically.
This class contains the basic support for an AST. Most people will create ASTs that are subclasses of BaseAST or of CommonAST.
void antlr.BaseAST.addChild | ( | AST | node | ) |
Add a node to the end of the child list for this node
References antlr.BaseAST.down, and antlr.BaseAST.right.
Referenced by antlr.debug.ParseTreeDebugParser.addCurrentTokenToParseTree(), antlr.debug.misc.ASTFrame.main(), and antlr.debug.ParseTreeDebugParser.traceIn().
static String antlr.BaseAST.decode | ( | String | text | ) | [static] |
static String antlr.BaseAST.encode | ( | String | text | ) | [static] |
Referenced by antlr.BaseAST.xmlSerializeNode(), and antlr.BaseAST.xmlSerializeRootOpen().
boolean antlr.BaseAST.equals | ( | AST | t | ) |
Is node t equal to this in terms of token type and text?
References antlr.collections.AST.getText(), antlr.BaseAST.getText(), antlr.collections.AST.getType(), and antlr.BaseAST.getType().
Referenced by antlr.BaseAST.equalsTree(), and antlr.BaseAST.equalsTreePartial().
boolean antlr.BaseAST.equalsList | ( | AST | t | ) |
Is t an exact structural and equals() match of this tree. The 'this' reference is considered the start of a sibling list.
References antlr.collections.AST.equals(), antlr.collections.AST.equalsList(), antlr.collections.AST.getFirstChild(), and antlr.collections.AST.getNextSibling().
Referenced by antlr.BaseAST.equalsTree().
boolean antlr.BaseAST.equalsListPartial | ( | AST | sub | ) |
Is 'sub' a subtree of this list? The siblings of the root are NOT ignored.
References antlr.collections.AST.equals(), antlr.collections.AST.equalsListPartial(), antlr.collections.AST.getFirstChild(), and antlr.collections.AST.getNextSibling().
Referenced by antlr.BaseAST.equalsTreePartial().
boolean antlr.BaseAST.equalsTree | ( | AST | t | ) |
Is tree rooted at 'this' equal to 't'? The siblings of 'this' are ignored.
References antlr.BaseAST.equals(), antlr.BaseAST.equalsList(), antlr.collections.AST.getFirstChild(), and antlr.BaseAST.getFirstChild().
boolean antlr.BaseAST.equalsTreePartial | ( | AST | sub | ) |
Is 't' a subtree of the tree rooted at 'this'? The siblings of 'this' are ignored.
References antlr.BaseAST.equals(), antlr.BaseAST.equalsListPartial(), antlr.collections.AST.getFirstChild(), and antlr.BaseAST.getFirstChild().
ASTEnumeration antlr.BaseAST.findAll | ( | AST | target | ) |
Walk the tree looking for all exact subtree matches. Return an ASTEnumerator that lets the caller walk the list of subtree roots found herein.
ASTEnumeration antlr.BaseAST.findAllPartial | ( | AST | sub | ) |
Walk the tree looking for all subtrees. Return an ASTEnumerator that lets the caller walk the list of subtree roots found herein.
int antlr.BaseAST.getColumn | ( | ) |
AST antlr.BaseAST.getFirstChild | ( | ) |
Get the first child of this node; null if not children
References antlr.BaseAST.down.
Referenced by PascalParser.constant(), PascalParser.constList(), antlr.BaseAST.equalsTree(), antlr.BaseAST.equalsTreePartial(), PascalParser.fieldList(), PascalParser.functionDesignator(), antlr.ParseTreeRule.getLeftmostDerivation(), PascalParser.identifierList(), BinaryOperatorAST.left(), PascalParser.parameterGroup(), PascalParser.parameterList(), PascalParser.procedureStatement(), PascalParser.recordSection(), PascalParser.statements(), PascalParser.tag(), PascalParser.typeList(), and SymtabPhase.usesUnitsPart().
int antlr.BaseAST.getLine | ( | ) |
AST antlr.BaseAST.getNextSibling | ( | ) |
Get the next sibling in line after this one
References antlr.BaseAST.right.
Referenced by BinaryOperatorAST.right(), and SymtabPhase.usesUnitsPart().
int antlr.BaseAST.getNumberOfChildren | ( | ) |
How many children does this node have?
References antlr.BaseAST.down, and antlr.BaseAST.right.
String antlr.BaseAST.getText | ( | ) |
Get the token text for this node
Reimplemented in antlr.CommonAST.
Referenced by antlr.BaseAST.equals(), antlr.BaseAST.toString(), antlr.BaseAST.xmlSerializeNode(), and antlr.BaseAST.xmlSerializeRootOpen().
static String [] antlr.BaseAST.getTokenNames | ( | ) | [static] |
Return an array of strings that maps token ID to it's text.
int antlr.BaseAST.getType | ( | ) |
Get the token type for this node
Reimplemented in antlr.CommonAST.
Referenced by antlr.BaseAST.equals(), antlr.BaseAST.toString(), antlr.BaseAST.xmlSerializeNode(), and antlr.BaseAST.xmlSerializeRootOpen().
abstract void antlr.BaseAST.initialize | ( | int | t, | |
String | txt | |||
) | [pure virtual] |
Implemented in antlr.CommonAST, antlr.ParseTree, and CalcAST.
abstract void antlr.BaseAST.initialize | ( | AST | t | ) | [pure virtual] |
Implemented in antlr.CommonAST, antlr.CommonASTWithHiddenTokens, antlr.ParseTree, and CalcAST.
abstract void antlr.BaseAST.initialize | ( | Token | t | ) | [pure virtual] |
Implemented in antlr.CommonAST, antlr.CommonASTWithHiddenTokens, antlr.ParseTree, and CalcAST.
void antlr.BaseAST.removeChildren | ( | ) |
Remove all children
References antlr.BaseAST.down.
void antlr.BaseAST.setFirstChild | ( | AST | c | ) |
References antlr.BaseAST.down.
void antlr.BaseAST.setNextSibling | ( | AST | n | ) |
References antlr.BaseAST.right.
void antlr.BaseAST.setText | ( | String | text | ) |
Set the token text for this node
Reimplemented in antlr.CommonAST.
void antlr.BaseAST.setType | ( | int | ttype | ) |
Set the token type for this node
Reimplemented in antlr.CommonAST.
static void antlr.BaseAST.setVerboseStringConversion | ( | boolean | verbose, | |
String[] | names | |||
) | [static] |
String antlr.BaseAST.toString | ( | ) |
Reimplemented in antlr.ParseTreeRule, antlr.ParseTreeToken, INTNode, MULTNode, and PLUSNode.
References antlr.BaseAST.getText(), and antlr.BaseAST.getType().
Referenced by antlr.ParseTree.getLeftmostDerivation(), antlr.ParseTree.getLeftmostDerivationStep(), antlr.BaseAST.toStringList(), and antlr.BaseAST.toStringTree().
String antlr.BaseAST.toStringList | ( | ) |
Print out a child-sibling tree in LISP notation
References antlr.collections.AST.getFirstChild(), antlr.collections.AST.getNextSibling(), and antlr.BaseAST.toString().
Referenced by Calc.main(), and antlr.BaseAST.toStringTree().
String antlr.BaseAST.toStringTree | ( | ) |
References antlr.collections.AST.getFirstChild(), antlr.BaseAST.toString(), and antlr.BaseAST.toStringList().
Referenced by Main.main(), and Calc.main().
void antlr.BaseAST.xmlSerialize | ( | Writer | out | ) | throws IOException |
Referenced by Main.main().
void antlr.BaseAST.xmlSerializeNode | ( | Writer | out | ) | throws IOException |
Reimplemented in INTNode.
References antlr.BaseAST.encode(), antlr.BaseAST.getText(), and antlr.BaseAST.getType().
void antlr.BaseAST.xmlSerializeRootClose | ( | Writer | out | ) | throws IOException |
void antlr.BaseAST.xmlSerializeRootOpen | ( | Writer | out | ) | throws IOException |
Reimplemented in MULTNode, and PLUSNode.
References antlr.BaseAST.encode(), antlr.BaseAST.getText(), and antlr.BaseAST.getType().
BaseAST antlr.BaseAST.down [protected] |
BaseAST antlr.BaseAST.right [protected] |