|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectptolemy.data.expr.ASTPtRootNode
public class ASTPtRootNode
The parse tree created from the expression string consists of a hierarchy of node objects, each of which is an instance of a class derived from this class. This is because each node is a root node for the portion of the parse tree below it.
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.
PtParser
,
Token
Red (cxh) |
Yellow (nsmyth) |
Field Summary | |
---|---|
protected java.util.ArrayList |
_children
|
protected int |
_id
|
protected boolean |
_isConstant
Flags whether the parse tree under this root evaluates to a constant. |
protected Node |
_parent
|
protected Token |
_ptToken
Each node stores its type and state information in this variable. |
protected Type |
_ptType
The type of this node. |
Constructor Summary | |
---|---|
ASTPtRootNode(int i)
|
|
ASTPtRootNode(PtParser p,
int i)
|
Method Summary | |
---|---|
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 value of this node. |
java.lang.String |
toString()
You can override these two methods in subclasses of RootNode to customize the way the node appears when the tree is dumped. |
java.lang.String |
toString(java.lang.String prefix)
|
void |
visit(ParseTreeVisitor visitor)
Traverse this node with the given visitor. |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected Node _parent
protected java.util.ArrayList _children
protected int _id
protected Token _ptToken
protected Type _ptType
protected boolean _isConstant
Constructor Detail |
---|
public ASTPtRootNode(int i)
public ASTPtRootNode(PtParser p, int i)
Method Detail |
---|
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)
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
jjtClose
in interface 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
jjtOpen
in interface Node
public void jjtSetParent(Node n)
Node
jjtSetParent
in interface Node
public void setConstant(boolean flag)
public void setToken(Token token)
public void setType(Type type)
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toString(java.lang.String prefix)
public void visit(ParseTreeVisitor visitor) throws IllegalActionException
IllegalActionException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |