net.percederberg.grammatica.parser
Class Analyzer

java.lang.Object
  |
  +--net.percederberg.grammatica.parser.Analyzer

public class Analyzer
extends java.lang.Object

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).

Version:
1.0
Author:
Per Cederberg,

Constructor Summary
protected Analyzer()
          Creates a new parse tree analyzer.
 
Method Summary
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 process(Node node)
          Processes a parse tree node and creates a new node that is the result of processing all children recursively.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Analyzer

protected Analyzer()
Creates a new parse tree analyzer.

Method Detail

process

protected Node process(Node node)
                throws ParseException
Processes a parse tree node and creates a new node that is the result of processing all children recursively. The tree traversal is depth-first, and the appropriate callback methods will be called. This method is used to process a parse tree after creation.

Parameters:
node - the parse tree node to process
Returns:
the resulting parse tree node
Throws:
ParseException - if the node analysis discovered errors

enter

protected void enter(Node node)
              throws ParseException
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
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
Returns:
the node to add to the parse tree
Throws:
ParseException - if the node analysis discovered errors

child

protected void child(Production node,
                     Node child)
              throws ParseException
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
child - the child node, or null
Throws:
ParseException - if the node analysis discovered errors