Package com.singularsys.jep.parser
Interface Node
- All Known Implementing Classes:
ASTConstant
,ASTFunNode
,ASTOpNode
,ASTStart
,ASTVarNode
,SimpleNode
public interface Node
Interface defining a node in the parse-tree.
All AST nodes must implement this interface. It provides basic machinery for constructing the parent and child relationships between nodes.
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
Nodes can optional have hooks which add meta-data to the node. -
Method Summary
Modifier and TypeMethodDescriptionReturns an Iterator which iterates over the children of the Node.children()
Returns an Iterable object which can be used in a for/in loop.getHook
(Node.HookKey key) Get the object associated with the keyint
getId()
Returns the numeric id of a node type.getName()
Return the name associated with the node (if any).Return the operator associated with a Node (if any)getPFMC()
Return the pfmc of a node (if any)getValue()
Return the value associated with the node (if any).getVar()
Return the variable associated with a Node (if any)hookKeys()
Get all the keys defined for this node.jjtAccept
(ParserVisitor visitor, Object data) Accept the visitor.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.jjtGetChild
(int i) This method returns a child node.int
Return the number of children the node has.Gets the parent nodevoid
jjtOpen()
This method is called after the node has been made the current node.void
jjtSetParent
(Node n) Sets the parent node.removeHook
(Node.HookKey key) Remove the keysetHook
(Node.HookKey key, Object data) Set the data associated with a given key
-
Method Details
-
jjtOpen
void jjtOpen()This method is called after the node has been made the current node. It indicates that child nodes can now be added to it. -
jjtClose
void jjtClose()This method is called after all the child nodes have been added. -
jjtSetParent
Sets the parent node. -
jjtGetParent
Node jjtGetParent()Gets the parent node -
jjtAddChild
This method tells the node to add its argument to the node's list of children. -
jjtGetChild
This method returns a child node. The children are numbered from zero, left to right. -
jjtGetNumChildren
int jjtGetNumChildren()Return the number of children the node has.- Returns:
- the number of child nodes
-
jjtAccept
Accept the visitor.- Throws:
JepException
-
getValue
Object getValue()Return the value associated with the node (if any).- Returns:
- the value if an ASTConstant, ASTVarNode, null otherwise
-
getName
String getName()Return the name associated with the node (if any).- Returns:
- the name if an ASTVarNode, ASTFunNode, ASTOpNode, null otherwise
-
getPFMC
PostfixMathCommandI getPFMC()Return the pfmc of a node (if any)- Returns:
- the PostfixMathCommand for ASTFunNode and ASTOpNode, null otherwise
-
getOperator
Operator getOperator()Return the operator associated with a Node (if any)- Returns:
- The Operator for ASTOpNodes, null otherwise
-
getVar
Variable getVar()Return the variable associated with a Node (if any)- Returns:
- The Variable for ASTVarNodes, null otherwise
-
children
Returns an Iterable object which can be used in a for/in loop.for(Node child:node.children()) { ... }
-
childIterator
Returns an Iterator which iterates over the children of the Node. The remove method is unsupported.- Returns:
- a new Iterator
-
getId
int getId()Returns the numeric id of a node type. 2 = ASTOpNode, 3 = ASTVarNode, 4 = ASTFunNode, 5 = ASTConstant- See Also:
-
setHook
Set the data associated with a given key- Parameters:
key
- defining the type of datadata
- actual object- Returns:
- previous object associated with the key
-
getHook
Get the object associated with the key- Parameters:
key
-- Returns:
- the object associated with the key
-
hookKeys
Collection<Node.HookKey> hookKeys()Get all the keys defined for this node.- Returns:
- all the keys
-
removeHook
Remove the key- Parameters:
key
-- Returns:
- the object which was associated with the key
-