com.agentfactory.common.parser
Class Node

java.lang.Object
  extended by com.agentfactory.common.parser.Node

public class Node
extends java.lang.Object

This class implements a node in the parse tree that is generated by the parsing process. Each individual node in the parse tree holds a token and a handler that is delegated the visitor handling responsibility for that node (this has allowed us to maintain only one Node type rather than having to generate a different type of node for each token in the language). Each node also maintains a list of children nodes in the tree. Currently, some nodes may include only a handler. These are normally abstract nodes that are used to deal with cases where the underlying handler must deal with multiple problems. For example: a FOS can be both part of a statement and a statement in its own right. This causes problems with some of the visitors. TODO (Rem Collier): An alternative may be to subclass the FOSHandler in this case - must investigate.


Constructor Summary
Node(Handler handler)
          Construct a node with only a handler
Node(Token token, Handler handler)
          Construct a node object with a given token and handler/
 
Method Summary
 void accept(Visitor visitor)
          Method that accepts incoming visitor objects that are in the process of traversing the tree.
 void addChild(Node node)
          Add a child node to a given node.
 Node childAt(int index)
          Accessor that returns the child node at a given position in the children list.
 java.util.List<Node> getChildren()
          Accessor method that returns the children of this node.
 Token getToken()
          Accessor method that returns the token.
 boolean hasChildren()
          Accessor method that checks whether of not the node has children
 java.lang.String toString()
          Returns a string representation of the node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Node

public Node(Token token,
            Handler handler)
Construct a node object with a given token and handler/

Parameters:
token - the token that the node represents
handler - the handler for that token

Node

public Node(Handler handler)
Construct a node with only a handler

Parameters:
handler - the handler for that token
Method Detail

addChild

public void addChild(Node node)
Add a child node to a given node.

Parameters:
node - the child node to be added.

getToken

public Token getToken()
Accessor method that returns the token.

Returns:
the token held in the node

getChildren

public java.util.List<Node> getChildren()
Accessor method that returns the children of this node.

Returns:
a list of child nodes.

hasChildren

public boolean hasChildren()
Accessor method that checks whether of not the node has children

Returns:
true if there are children, false otherwise.

childAt

public Node childAt(int index)
Accessor that returns the child node at a given position in the children list.

Parameters:
index - the index of the child node to be returned
Returns:
the child at position index

toString

public java.lang.String toString()
Returns a string representation of the node. This implementation is recursive, and displays all descendents of this mode.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of the subtree rooted at this node.

accept

public void accept(Visitor visitor)
            throws SemanticError
Method that accepts incoming visitor objects that are in the process of traversing the tree. Responsibility for deciding what to do with a visitor is the responsibility of the associated handler.

Parameters:
visitor - a visitor object that is traversing the tree
Throws:
SemanticError