Package antlr
Class BaseAST
java.lang.Object
antlr.BaseAST
- All Implemented Interfaces:
AST,Serializable
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.
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a node to the end of the child list for this nodestatic Stringstatic StringbooleanIs node t equal to this in terms of token type and text?booleanequalsList(AST t) Is t an exact structural and equals() match of this tree.booleanequalsListPartial(AST sub) Is 'sub' a subtree of this list? The siblings of the root are NOT ignored.booleanequalsTree(AST t) Is tree rooted at 'this' equal to 't'? The siblings of 'this' are ignored.booleanequalsTreePartial(AST sub) Is 't' a subtree of the tree rooted at 'this'? The siblings of 'this' are ignored.Walk the tree looking for all exact subtree matches.findAllPartial(AST sub) Walk the tree looking for all subtrees.intGet the first child of this node; null if not childrenintgetLine()Get the next sibling in line after this oneintHow many children does this node have?getText()Get the token text for this nodestatic String[]Return an array of strings that maps token ID to it's text.intgetType()Get the token type for this nodeabstract voidinitialize(int t, String txt) abstract voidinitialize(AST t) abstract voidinitialize(Token t) voidRemove all childrenvoidsetFirstChild(AST c) Set the first child of a node.voidSet the next sibling after this one.voidSet the token text for this nodevoidsetType(int ttype) Set the token type for this nodestatic voidsetVerboseStringConversion(boolean verbose, String[] names) toString()Print out a child-sibling tree in LISP notationvoidxmlSerialize(Writer out) voidxmlSerializeNode(Writer out) voidvoid
-
Field Details
-
down
-
right
-
-
Constructor Details
-
BaseAST
public BaseAST()
-
-
Method Details
-
addChild
Add a node to the end of the child list for this node -
getNumberOfChildren
public int getNumberOfChildren()How many children does this node have?- Specified by:
getNumberOfChildrenin interfaceAST
-
equals
Is node t equal to this in terms of token type and text? -
equalsList
Is t an exact structural and equals() match of this tree. The 'this' reference is considered the start of a sibling list.- Specified by:
equalsListin interfaceAST
-
equalsListPartial
Is 'sub' a subtree of this list? The siblings of the root are NOT ignored.- Specified by:
equalsListPartialin interfaceAST
-
equalsTree
Is tree rooted at 'this' equal to 't'? The siblings of 'this' are ignored.- Specified by:
equalsTreein interfaceAST
-
equalsTreePartial
Is 't' a subtree of the tree rooted at 'this'? The siblings of 'this' are ignored.- Specified by:
equalsTreePartialin interfaceAST
-
findAll
Walk the tree looking for all exact subtree matches. Return an ASTEnumerator that lets the caller walk the list of subtree roots found herein. -
findAllPartial
Walk the tree looking for all subtrees. Return an ASTEnumerator that lets the caller walk the list of subtree roots found herein.- Specified by:
findAllPartialin interfaceAST
-
getFirstChild
Get the first child of this node; null if not children- Specified by:
getFirstChildin interfaceAST
-
getNextSibling
Get the next sibling in line after this one- Specified by:
getNextSiblingin interfaceAST
-
getText
Get the token text for this node -
getType
public int getType()Get the token type for this node -
getLine
public int getLine() -
getColumn
public int getColumn() -
initialize
- Specified by:
initializein interfaceAST
-
initialize
- Specified by:
initializein interfaceAST
-
initialize
- Specified by:
initializein interfaceAST
-
removeChildren
public void removeChildren()Remove all children -
setFirstChild
Description copied from interface:ASTSet the first child of a node.- Specified by:
setFirstChildin interfaceAST
-
setNextSibling
Description copied from interface:ASTSet the next sibling after this one.- Specified by:
setNextSiblingin interfaceAST
-
setText
Set the token text for this node -
setType
public void setType(int ttype) Set the token type for this node -
setVerboseStringConversion
-
getTokenNames
Return an array of strings that maps token ID to it's text. @since 2.7.3 -
toString
-
toStringList
Print out a child-sibling tree in LISP notation- Specified by:
toStringListin interfaceAST
-
toStringTree
- Specified by:
toStringTreein interfaceAST
-
decode
-
encode
-
xmlSerializeNode
- Throws:
IOException
-
xmlSerializeRootOpen
- Throws:
IOException
-
xmlSerializeRootClose
- Throws:
IOException
-
xmlSerialize
- Throws:
IOException
-