| java.lang.Object net.percederberg.grammatica.parser.Analyzer
All known Subclasses: net.percederberg.grammatica.GrammarAnalyzer, net.percederberg.grammatica.test.ArithmeticAnalyzer, net.percederberg.grammatica.test.RegexpAnalyzer, net.percederberg.grammatica.TreePrinter,
Analyzer | public class Analyzer (Code) | | A parse tree analyzer. This class provides callback methods that
may be used either during parsing, or for a parse tree traversal.
This class should be subclassed to provide adequate handling of the
parse tree nodes.
The general contract for the analyzer class does not guarantee a
strict call order for the callback methods. Depending on the type
of parser, the enter() and exit() methods for production nodes can
be called either in a top-down or a bottom-up fashion. The only
guarantee provided by this API, is that the calls for any given
node will always be in the order enter(), child(), and exit(). If
various child() calls are made, they will be made from left to
right as child nodes are added (to the right).
author: Per Cederberg, version: 1.1 |
Constructor Summary | |
public | Analyzer() Creates a new parse tree analyzer. |
Method Summary | |
public Node | analyze(Node node) Analyzes a parse tree node by traversing all it's child nodes. | protected void | child(Production node, Node child) Called when adding a child to a parse tree node. | protected void | enter(Node node) Called when entering a parse tree node. | protected Node | exit(Node node) Called when exiting a parse tree node. | protected Node | getChildAt(Node node, int pos) Returns a child at the specified position. | protected ArrayList | getChildValues(Node node) Returns all the node values for all child nodes. | protected Node | getChildWithId(Node node, int id) Returns the first child with the specified id. | protected int | getIntValue(Node node, int pos) Returns the node integer value at the specified position. | protected String | getStringValue(Node node, int pos) Returns the node string value at the specified position. | protected Object | getValue(Node node, int pos) Returns the node value at the specified position. |
Analyzer | public Analyzer()(Code) | | Creates a new parse tree analyzer.
|
analyze | public Node analyze(Node node) throws ParserLogException(Code) | | Analyzes a parse tree node by traversing all it's child nodes.
The tree traversal is depth-first, and the appropriate
callback methods will be called. If the node is a production
node, a new production node will be created and children will
be added by recursively processing the children of the
specified production node. This method is used to process a
parse tree after creation.
Parameters: node - the parse tree node to process the resulting parse tree node throws: ParserLogException - if the node analysis discovered errors |
child | protected void child(Production node, Node child) throws ParseException(Code) | | Called when adding a child to a parse tree node. By default
this method adds the child to the production node. A subclass
can override this method to handle each node separately. Note
that the child node may be null if the corresponding exit()
method returned null.
Parameters: node - the parent node Parameters: child - the child node, or null throws: ParseException - if the node analysis discovered errors |
enter | protected void enter(Node node) throws ParseException(Code) | | Called when entering a parse tree node. By default this method
does nothing. A subclass can override this method to handle
each node separately.
Parameters: node - the node being entered throws: ParseException - if the node analysis discovered errors |
exit | protected Node exit(Node node) throws ParseException(Code) | | Called when exiting a parse tree node. By default this method
returns the node. A subclass can override this method to handle
each node separately. If no parse tree should be created, this
method should return null.
Parameters: node - the node being exited the node to add to the parse tree, ornull if no parse tree should be created throws: ParseException - if the node analysis discovered errors |
getChildAt | protected Node getChildAt(Node node, int pos) throws ParseException(Code) | | Returns a child at the specified position. If either the node
or the child node is null, this method will throw a parse
exception with the internal error type.
Parameters: node - the parent node Parameters: pos - the child position the child node throws: ParseException - if either the node or the child node was null |
getChildValues | protected ArrayList getChildValues(Node node)(Code) | | Returns all the node values for all child nodes.
Parameters: node - the parse tree node a list with all the child node values since: 1.3 |
getChildWithId | protected Node getChildWithId(Node node, int id) throws ParseException(Code) | | Returns the first child with the specified id. If the node is
null, or no child with the specified id could be found, this
method will throw a parse exception with the internal error
type.
Parameters: node - the parent node Parameters: id - the child node id the child node throws: ParseException - if the node was null, or a child node couldn't be found |
getIntValue | protected int getIntValue(Node node, int pos) throws ParseException(Code) | | Returns the node integer value at the specified position. If
either the node is null, or the value is not an instance of
the Integer class, this method will throw a parse exception
with the internal error type.
Parameters: node - the parse tree node Parameters: pos - the child position the value object throws: ParseException - if either the node was null, or the value wasn't an integer |
getStringValue | protected String getStringValue(Node node, int pos) throws ParseException(Code) | | Returns the node string value at the specified position. If
either the node is null, or the value is not an instance of
the String class, this method will throw a parse exception
with the internal error type.
Parameters: node - the parse tree node Parameters: pos - the child position the value object throws: ParseException - if either the node was null, or the value wasn't a string |
getValue | protected Object getValue(Node node, int pos) throws ParseException(Code) | | Returns the node value at the specified position. If either
the node or the value is null, this method will throw a parse
exception with the internal error type.
Parameters: node - the parse tree node Parameters: pos - the child position the value object throws: ParseException - if either the node or the value was null |
|
|