public class ASTPtRootNode extends java.lang.Object implements Node, java.lang.Cloneable
Each node in the parse tree stores its type and state information in a ptolemy.data.Token variable. A parent node uses the type and value of the ptolemy.data.Tokens contained in its child nodes to evaluate the type and value of the ptolemy.data.Token it should contain.
When a node has more than one child nodes, the lexical tokens relating the child nodes are stored in the parent node. Thus if we parsed a string such as "2+4-9", the child nodes would be leaf nodes containing ptolemy.data.Token's with values 2, 4 and 9, and the parent node would store the lexical tokens representing the "+" and the "-".
The tree is evaluated in a top down manner, calling evaluateParseTree() on the children of each node before resolving the type of the current node.
Modifier and Type | Field and Description |
---|---|
protected java.util.ArrayList |
_children
The children.
|
protected int |
_id
The id.
|
protected boolean |
_isConstant
Flags whether the parse tree under this root evaluates to a constant.
|
protected Node |
_parent
The parent node.
|
protected Token |
_ptToken
Each node stores its type and state information in this variable.
|
protected Type |
_ptType
The type of this node.
|
Constructor and Description |
---|
ASTPtRootNode(int i) |
ASTPtRootNode(PtParser p,
int i) |
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
clone()
Clone the parse tree node by invoking the clone() method of
the base class (java.lang.Object).
|
void |
displayParseTree(java.lang.String prefix)
Override this method if you want to customize how the node dumps
out its children.
|
Token |
evaluateParseTree()
Deprecated.
Use a ParseTreeEvaluator instead.
|
Token |
getToken()
Return the evaluated token value of this node.
|
Type |
getType()
Return the type of this node.
|
boolean |
isCongruent(ASTPtRootNode node,
java.util.Map renaming)
Return true if this node is (hierarchically) congruent to the
given node, under the given renaming of bound identifiers.
|
boolean |
isConstant()
Return true if this node represents a constant value.
|
boolean |
isEvaluated()
Return true if this node has had its token value set to something
other than null.
|
void |
jjtAddChild(Node n,
int i)
This method tells the node to add its argument to the node's
list of children.
|
void |
jjtClose()
This method is called after all the child nodes have been
added.
|
Node |
jjtGetChild(int i)
This method returns a child node.
|
int |
jjtGetNumChildren()
Return the number of children the node has.
|
Node |
jjtGetParent() |
void |
jjtOpen()
This method is called after the node has been made the current
node.
|
void |
jjtSetParent(Node n)
This pair of methods are used to inform the node of its
parent.
|
void |
setConstant(boolean flag)
Set whether this node is a constant.
|
void |
setToken(Token token)
Set the value of this node.
|
void |
setType(Type type)
Set the type of this node.
|
java.lang.String |
toString()
Return the string value of this node.
|
java.lang.String |
toString(java.lang.String prefix)
Return the prefix, followed by the string value of this node.
|
void |
visit(ParseTreeVisitor visitor)
Traverse this node with the given visitor.
|
protected Node _parent
protected java.util.ArrayList _children
protected int _id
protected Token _ptToken
protected Type _ptType
protected boolean _isConstant
public ASTPtRootNode(int i)
public ASTPtRootNode(PtParser p, int i)
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
- If the superclass clone()
method throws it.public void displayParseTree(java.lang.String prefix)
prefix
- The prefix, which is processed by
toString(String)
.@Deprecated public Token evaluateParseTree() throws IllegalActionException
IllegalActionException
- If an error occurs
trying to evaluate the PtToken type and/or value to be stored in
node in the tree.public Token getToken()
public Type getType()
public boolean isCongruent(ASTPtRootNode node, java.util.Map renaming)
node
- The node to compare to.renaming
- A map from String to String that gives a
renaming from identifiers in this node to identifiers in the
given node.public boolean isConstant()
public boolean isEvaluated()
public void jjtAddChild(Node n, int i)
Node
jjtAddChild
in interface Node
public void jjtClose()
Node
public Node jjtGetChild(int i)
Node
jjtGetChild
in interface Node
public int jjtGetNumChildren()
Node
jjtGetNumChildren
in interface Node
public Node jjtGetParent()
jjtGetParent
in interface Node
public void jjtOpen()
Node
public void jjtSetParent(Node n)
Node
jjtSetParent
in interface Node
public void setConstant(boolean flag)
flag
- If true, then this node is a constant.public void setToken(Token token)
token
- The value of this node.public void setType(Type type)
type
- The type of this node.public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toString(java.lang.String prefix)
prefix
- The prefixpublic void visit(ParseTreeVisitor visitor) throws IllegalActionException
visitor
- The visitor.IllegalActionException
- Always thrown in this base
class the visit() method is not implemented here.