Package antlr
Class BaseAST
- java.lang.Object
-
- antlr.BaseAST
-
- All Implemented Interfaces:
AST
,java.io.Serializable
public abstract class BaseAST extends java.lang.Object implements AST, java.io.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:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description BaseAST()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addChild(AST node)
Add a node to the end of the child list for this nodestatic java.lang.String
decode(java.lang.String text)
static java.lang.String
encode(java.lang.String text)
boolean
equals(AST t)
Is node t equal to this in terms of token type and text?boolean
equalsList(AST t)
Is t an exact structural and equals() match of this tree.boolean
equalsListPartial(AST sub)
Is 'sub' a subtree of this list? The siblings of the root are NOT ignored.boolean
equalsTree(AST t)
Is tree rooted at 'this' equal to 't'? The siblings of 'this' are ignored.boolean
equalsTreePartial(AST sub)
Is 't' a subtree of the tree rooted at 'this'? The siblings of 'this' are ignored.ASTEnumeration
findAll(AST target)
Walk the tree looking for all exact subtree matches.ASTEnumeration
findAllPartial(AST sub)
Walk the tree looking for all subtrees.int
getColumn()
AST
getFirstChild()
Get the first child of this node; null if not childrenint
getLine()
AST
getNextSibling()
Get the next sibling in line after this oneint
getNumberOfChildren()
How many children does this node have?java.lang.String
getText()
Get the token text for this nodestatic java.lang.String[]
getTokenNames()
Return an array of strings that maps token ID to it's text.int
getType()
Get the token type for this nodeabstract void
initialize(int t, java.lang.String txt)
abstract void
initialize(AST t)
abstract void
initialize(Token t)
void
removeChildren()
Remove all childrenvoid
setFirstChild(AST c)
Set the first child of a node.void
setNextSibling(AST n)
Set the next sibling after this one.void
setText(java.lang.String text)
Set the token text for this nodevoid
setType(int ttype)
Set the token type for this nodestatic void
setVerboseStringConversion(boolean verbose, java.lang.String[] names)
java.lang.String
toString()
java.lang.String
toStringList()
Print out a child-sibling tree in LISP notationjava.lang.String
toStringTree()
void
xmlSerialize(java.io.Writer out)
void
xmlSerializeNode(java.io.Writer out)
void
xmlSerializeRootClose(java.io.Writer out)
void
xmlSerializeRootOpen(java.io.Writer out)
-
-
-
Method Detail
-
addChild
public void addChild(AST node)
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:
getNumberOfChildren
in interfaceAST
-
equals
public boolean equals(AST t)
Is node t equal to this in terms of token type and text?
-
equalsList
public boolean 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.- Specified by:
equalsList
in interfaceAST
-
equalsListPartial
public boolean equalsListPartial(AST sub)
Is 'sub' a subtree of this list? The siblings of the root are NOT ignored.- Specified by:
equalsListPartial
in interfaceAST
-
equalsTree
public boolean equalsTree(AST t)
Is tree rooted at 'this' equal to 't'? The siblings of 'this' are ignored.- Specified by:
equalsTree
in interfaceAST
-
equalsTreePartial
public boolean equalsTreePartial(AST sub)
Is 't' a subtree of the tree rooted at 'this'? The siblings of 'this' are ignored.- Specified by:
equalsTreePartial
in interfaceAST
-
findAll
public ASTEnumeration 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.
-
findAllPartial
public ASTEnumeration 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.- Specified by:
findAllPartial
in interfaceAST
-
getFirstChild
public AST getFirstChild()
Get the first child of this node; null if not children- Specified by:
getFirstChild
in interfaceAST
-
getNextSibling
public AST getNextSibling()
Get the next sibling in line after this one- Specified by:
getNextSibling
in interfaceAST
-
getText
public java.lang.String getText()
Get the token text for this node
-
getType
public int getType()
Get the token type for this node
-
initialize
public abstract void initialize(int t, java.lang.String txt)
- Specified by:
initialize
in interfaceAST
-
initialize
public abstract void initialize(AST t)
- Specified by:
initialize
in interfaceAST
-
initialize
public abstract void initialize(Token t)
- Specified by:
initialize
in interfaceAST
-
removeChildren
public void removeChildren()
Remove all children
-
setFirstChild
public void setFirstChild(AST c)
Description copied from interface:AST
Set the first child of a node.- Specified by:
setFirstChild
in interfaceAST
-
setNextSibling
public void setNextSibling(AST n)
Description copied from interface:AST
Set the next sibling after this one.- Specified by:
setNextSibling
in interfaceAST
-
setText
public void setText(java.lang.String text)
Set the token text for this node
-
setType
public void setType(int ttype)
Set the token type for this node
-
setVerboseStringConversion
public static void setVerboseStringConversion(boolean verbose, java.lang.String[] names)
-
getTokenNames
public static java.lang.String[] getTokenNames()
Return an array of strings that maps token ID to it's text. @since 2.7.3
-
toString
public java.lang.String toString()
-
toStringList
public java.lang.String toStringList()
Print out a child-sibling tree in LISP notation- Specified by:
toStringList
in interfaceAST
-
toStringTree
public java.lang.String toStringTree()
- Specified by:
toStringTree
in interfaceAST
-
decode
public static java.lang.String decode(java.lang.String text)
-
encode
public static java.lang.String encode(java.lang.String text)
-
xmlSerializeNode
public void xmlSerializeNode(java.io.Writer out) throws java.io.IOException
- Throws:
java.io.IOException
-
xmlSerializeRootOpen
public void xmlSerializeRootOpen(java.io.Writer out) throws java.io.IOException
- Throws:
java.io.IOException
-
xmlSerializeRootClose
public void xmlSerializeRootClose(java.io.Writer out) throws java.io.IOException
- Throws:
java.io.IOException
-
xmlSerialize
public void xmlSerialize(java.io.Writer out) throws java.io.IOException
- Throws:
java.io.IOException
-
-