com.agentfactory.common.parser
Class Handler
java.lang.Object
com.agentfactory.common.parser.Handler
public abstract class Handler
- extends java.lang.Object
This is an abstract base class that should be extended to implement support
for individual statement types within the source programming language.
Subclasses must implement two types of method:
- the generateParseTree(...) method is responsible for converting a list
of tokens into a node structure.
- the accept(Node, XXXVisitor) methods implement support for the various
types of visitor that are required by the compiler.
The first method is invoked directly by the parser, while the other methods
are invoked through method level reflection that is implemented in the
accept(Node, Visitor) method of this class.
|
Method Summary |
void |
accept(Node node,
Visitor visitor)
Implements part of the Visitor pattern for tree traversal. |
abstract Node |
generateParseTree(java.util.List<Token> statement)
Subclasses should implement this method, which is responsible for
converting a statement (in the form of a list of Tokens) into
a Node structure. |
java.lang.String |
toString(Node node)
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Handler
public Handler()
generateParseTree
public abstract Node generateParseTree(java.util.List<Token> statement)
throws SyntaxError
- Subclasses should implement this method, which is responsible for
converting a statement (in the form of a list of Tokens) into
a Node structure.
As part of its implementation, this method should check whether or
not the statement is of the corresponding type. That is, this
method may be passed statements that are not the responsibility of
this class. In such cases, this method should return null.
In the event that this method detects a syntax error in the statement,
the method should throw a SyntaxError exception.
- Parameters:
statement - a list of tokens that correspond to a single statement in the
source language.
- Returns:
- null if the statment is not the responsibility of this class,
and a node structure if it is the classes responsibility and the statement
is correctly formed.
- Throws:
a - syntax error exception if the statement is incorrectly formed.
SyntaxError
accept
public void accept(Node node,
Visitor visitor)
throws SemanticError
- Implements part of the Visitor pattern for tree traversal. This method
is invoked by all classes that implement the Visitor interface, and uses
reflection to invoke a corresponding accept(Node, XXXVisitor) method
in the concrete subclasses.
- Parameters:
node - the node that is currently being visitedvisitor - a visitor object that is currently traversing the parse tree
- Throws:
SemanticError
toString
public java.lang.String toString(Node node)