Class ASTPtRootNode
- java.lang.Object
-
- ptolemy.data.expr.ASTPtRootNode
-
- All Implemented Interfaces:
java.lang.Cloneable,Node
- Direct Known Subclasses:
ASTPtArrayConstructNode,ASTPtAssignmentNode,ASTPtBitwiseNode,ASTPtFunctionalIfNode,ASTPtFunctionApplicationNode,ASTPtFunctionDefinitionNode,ASTPtLeafNode,ASTPtLogicalNode,ASTPtMatrixConstructNode,ASTPtMethodCallNode,ASTPtPowerNode,ASTPtProductNode,ASTPtRecordConstructNode,ASTPtRelationalNode,ASTPtShiftNode,ASTPtSumNode,ASTPtUnaryNode,ASTPtUnionConstructNode
public class ASTPtRootNode extends java.lang.Object implements Node, java.lang.Cloneable
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.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.ArrayList_childrenThe children.protected int_idThe id.protected boolean_isConstantFlags whether the parse tree under this root evaluates to a constant.protected Node_parentThe parent node.protected Token_ptTokenEach node stores its type and state information in this variable.protected Type_ptTypeThe type of this node.
-
Constructor Summary
Constructors Constructor Description ASTPtRootNode(int i)ASTPtRootNode(PtParser p, int i)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description java.lang.Objectclone()Clone the parse tree node by invoking the clone() method of the base class (java.lang.Object).voiddisplayParseTree(java.lang.String prefix)Override this method if you want to customize how the node dumps out its children.TokenevaluateParseTree()Deprecated.Use a ParseTreeEvaluator instead.TokengetToken()Return the evaluated token value of this node.TypegetType()Return the type of this node.booleanisCongruent(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.booleanisConstant()Return true if this node represents a constant value.booleanisEvaluated()Return true if this node has had its token value set to something other than null.voidjjtAddChild(Node n, int i)This method tells the node to add its argument to the node's list of children.voidjjtClose()This method is called after all the child nodes have been added.NodejjtGetChild(int i)This method returns a child node.intjjtGetNumChildren()Return the number of children the node has.NodejjtGetParent()voidjjtOpen()This method is called after the node has been made the current node.voidjjtSetParent(Node n)This pair of methods are used to inform the node of its parent.voidsetConstant(boolean flag)Set whether this node is a constant.voidsetToken(Token token)Set the value of this node.voidsetType(Type type)Set the type of this node.java.lang.StringtoString()Return the string value of this node.java.lang.StringtoString(java.lang.String prefix)Return the prefix, followed by the string value of this node.voidvisit(ParseTreeVisitor visitor)Traverse this node with the given visitor.
-
-
-
Field Detail
-
_parent
protected Node _parent
The parent node.
-
_children
protected java.util.ArrayList _children
The children.
-
_id
protected int _id
The id.
-
_ptToken
protected Token _ptToken
Each node stores its type and state information in this variable.
-
_ptType
protected Type _ptType
The type of this node.
-
_isConstant
protected boolean _isConstant
Flags whether the parse tree under this root evaluates to a constant.
-
-
Constructor Detail
-
ASTPtRootNode
public ASTPtRootNode(int i)
-
ASTPtRootNode
public ASTPtRootNode(PtParser p, int i)
-
-
Method Detail
-
clone
public java.lang.Object clone() throws java.lang.CloneNotSupportedExceptionClone the parse tree node by invoking the clone() method of the base class (java.lang.Object).- Overrides:
clonein classjava.lang.Object- Returns:
- A new parse tree node.
- Throws:
java.lang.CloneNotSupportedException- If the superclass clone() method throws it.
-
displayParseTree
public void displayParseTree(java.lang.String prefix)
Override this method if you want to customize how the node dumps out its children.- Parameters:
prefix- The prefix, which is processed bytoString(String).
-
evaluateParseTree
@Deprecated public Token evaluateParseTree() throws IllegalActionException
Deprecated.Use a ParseTreeEvaluator instead.Evaluate the parse tree.- Returns:
- The token contained by the root node for the parse tree.
- Throws:
IllegalActionException- If an error occurs trying to evaluate the PtToken type and/or value to be stored in node in the tree.
-
getToken
public Token getToken()
Return the evaluated token value of this node. This value may be set during parsing, if this represents a constant value, or may be set during parse tree evaluation.- Returns:
- The evaluated token.
-
getType
public Type getType()
Return the type of this node. This value may be set during parsing, if this represents a constant value, or may be set during parse tree evaluation.- Returns:
- The type of this node.
-
isCongruent
public 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. Derived classes should extend this method to add additional necessary congruency checks.- Parameters:
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.- Returns:
- True if the node is congruent.
-
isConstant
public boolean isConstant()
Return true if this node represents a constant value. This will be set to true if the node is a constant leaf node (either it is a constant leaf node, or a pure function with constant children.)- Returns:
- True if the node represents a constant value.
-
isEvaluated
public boolean isEvaluated()
Return true if this node has had its token value set to something other than null.- Returns:
- True if this node has had its token value set to something other than null.
-
jjtAddChild
public void jjtAddChild(Node n, int i)
Description copied from interface:NodeThis method tells the node to add its argument to the node's list of children.- Specified by:
jjtAddChildin interfaceNode
-
jjtClose
public void jjtClose()
Description copied from interface:NodeThis method is called after all the child nodes have been added.
-
jjtGetChild
public Node jjtGetChild(int i)
Description copied from interface:NodeThis method returns a child node. The children are numbered from zero, left to right.- Specified by:
jjtGetChildin interfaceNode
-
jjtGetNumChildren
public int jjtGetNumChildren()
Description copied from interface:NodeReturn the number of children the node has.- Specified by:
jjtGetNumChildrenin interfaceNode
-
jjtGetParent
public Node jjtGetParent()
- Specified by:
jjtGetParentin interfaceNode
-
jjtOpen
public void jjtOpen()
Description copied from interface:NodeThis method is called after the node has been made the current node. It indicates that child nodes can now be added to it.
-
jjtSetParent
public void jjtSetParent(Node n)
Description copied from interface:NodeThis pair of methods are used to inform the node of its parent.- Specified by:
jjtSetParentin interfaceNode
-
setConstant
public void setConstant(boolean flag)
Set whether this node is a constant. In almost all cases this is statically determined when the parse tree is first parsed, and this method is not normally called. However, it can be useful to transform a parse tree, which can make parts of the parse tree constant which were not before. This method is provided for those transformations.- Parameters:
flag- If true, then this node is a constant.
-
setToken
public void setToken(Token token)
Set the value of this node. This may be set during parsing, if the node is a constant node, or during evaluation of the expression.- Parameters:
token- The value of this node.
-
setType
public void setType(Type type)
Set the type of this node. This may be set during parsing, if the node is a constant node, or during evaluation of the expression.- Parameters:
type- The type of this node.
-
toString
public java.lang.String toString()
Return the string value of this node. You can override these two methods in subclasses of RootNode to customize the way the node appears when the tree is dumped. If your output uses more than one line you should override toString(String), otherwise overriding toString() is probably all you need to do.- Overrides:
toStringin classjava.lang.Object- Returns:
- The string value of this node.
-
toString
public java.lang.String toString(java.lang.String prefix)
Return the prefix, followed by the string value of this node.- Parameters:
prefix- The prefix- Returns:
- The prefix followed by the string value of this node.
-
visit
public void visit(ParseTreeVisitor visitor) throws IllegalActionException
Traverse this node with the given visitor. Subclasses should override this method to invoke the appropriate method in the visitor.- Parameters:
visitor- The visitor.- Throws:
IllegalActionException- Always thrown in this base class the visit() method is not implemented here.
-
-