antlr

Class BaseAST

public abstract class BaseAST extends Object implements 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.
Field Summary
protected BaseASTdown
protected BaseASTright
Method Summary
voidaddChild(AST node)
Add a node to the end of the child list for this node
static Stringdecode(String text)
static Stringencode(String text)
booleanequals(AST t)
Is 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?
booleanequalsTree(AST t)
Is tree rooted at 'this' equal to 't'?
booleanequalsTreePartial(AST sub)
Is 't' a subtree of the tree rooted at 'this'?
ASTEnumerationfindAll(AST target)
Walk the tree looking for all exact subtree matches.
ASTEnumerationfindAllPartial(AST sub)
Walk the tree looking for all subtrees.
intgetColumn()
ASTgetFirstChild()
Get the first child of this node; null if not children
intgetLine()
ASTgetNextSibling()
Get the next sibling in line after this one
intgetNumberOfChildren()
How many children does this node have?
StringgetText()
Get the token text for this node
static String[]getTokenNames()
Return an array of strings that maps token ID to it's text.
intgetType()
Get the token type for this node
abstract voidinitialize(int t, String txt)
abstract voidinitialize(AST t)
abstract voidinitialize(Token t)
voidremoveChildren()
Remove all children
voidsetFirstChild(AST c)
voidsetNextSibling(AST n)
voidsetText(String text)
Set the token text for this node
voidsetType(int ttype)
Set the token type for this node
static voidsetVerboseStringConversion(boolean verbose, String[] names)
StringtoString()
StringtoStringList()
Print out a child-sibling tree in LISP notation
StringtoStringTree()
voidxmlSerialize(Writer out)
voidxmlSerializeNode(Writer out)
voidxmlSerializeRootClose(Writer out)
voidxmlSerializeRootOpen(Writer out)

Field Detail

down

protected BaseAST down

right

protected BaseAST right

Method Detail

addChild

public void addChild(AST node)
Add a node to the end of the child list for this node

decode

public static String decode(String text)

encode

public static String encode(String text)

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.

equalsListPartial

public boolean equalsListPartial(AST sub)
Is 'sub' a subtree of this list? The siblings of the root are NOT ignored.

equalsTree

public boolean equalsTree(AST t)
Is tree rooted at 'this' equal to 't'? The siblings of 'this' are ignored.

equalsTreePartial

public boolean equalsTreePartial(AST sub)
Is 't' a subtree of the tree rooted at 'this'? The siblings of 'this' are ignored.

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.

getColumn

public int getColumn()

getFirstChild

public AST getFirstChild()
Get the first child of this node; null if not children

getLine

public int getLine()

getNextSibling

public AST getNextSibling()
Get the next sibling in line after this one

getNumberOfChildren

public int getNumberOfChildren()
How many children does this node have?

getText

public String getText()
Get the token text for this node

getTokenNames

public static String[] getTokenNames()
Return an array of strings that maps token ID to it's text. @since 2.7.3

getType

public int getType()
Get the token type for this node

initialize

public abstract void initialize(int t, String txt)

initialize

public abstract void initialize(AST t)

initialize

public abstract void initialize(Token t)

removeChildren

public void removeChildren()
Remove all children

setFirstChild

public void setFirstChild(AST c)

setNextSibling

public void setNextSibling(AST n)

setText

public void setText(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, String[] names)

toString

public String toString()

toStringList

public String toStringList()
Print out a child-sibling tree in LISP notation

toStringTree

public String toStringTree()

xmlSerialize

public void xmlSerialize(Writer out)

xmlSerializeNode

public void xmlSerializeNode(Writer out)

xmlSerializeRootClose

public void xmlSerializeRootClose(Writer out)

xmlSerializeRootOpen

public void xmlSerializeRootOpen(Writer out)