Grammatica
|
A parse tree analyzer. More...
Public Member Functions | |
Analyzer () | |
Creates a new parse tree analyzer. | |
virtual void | Reset () |
Resets this analyzer when the parser is reset for another input stream. More... | |
Node | Analyze (Node node) |
Analyzes a parse tree node by traversing all it's child nodes. More... | |
virtual Production | NewProduction (ProductionPattern pattern) |
Factory method to create a new production node. More... | |
virtual void | Enter (Node node) |
Called when entering a parse tree node. More... | |
virtual Node | Exit (Node node) |
Called when exiting a parse tree node. More... | |
virtual void | Child (Production node, Node child) |
Called when adding a child to a parse tree node. More... | |
Protected Member Functions | |
Node | GetChildAt (Node node, int pos) |
Returns a child at the specified position. More... | |
Node | GetChildWithId (Node node, int id) |
Returns the first child with the specified id. More... | |
object | GetValue (Node node, int pos) |
Returns the node value at the specified position. More... | |
int | GetIntValue (Node node, int pos) |
Returns the node integer value at the specified position. More... | |
string | GetStringValue (Node node, int pos) |
Returns the node string value at the specified position. More... | |
ArrayList | GetChildValues (Node node) |
Returns all the node values for all child nodes. More... | |
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).
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.
node | the parse tree node to process |
ParserLogException | if the node analysis discovered errors |
|
inlinevirtual |
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.
node | the parent node |
child | the child node, or null |
ParseException | if the node analysis discovered errors |
|
inlinevirtual |
Called when entering a parse tree node.
By default this method does nothing. A subclass can override this method to handle each node separately.
node | the node being entered |
ParseException | if the node analysis discovered errors |
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.
node | the node being exited |
ParseException | if the node analysis discovered errors |
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.
node | the parent node |
pos | the child position |
ParseException | if either the node or the child node was null |
|
inlineprotected |
Returns all the node values for all child nodes.
node | the parse tree node |
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.
node | the parent node |
id | the child node id |
ParseException | if the node was null, or a child node couldn't be found |
|
inlineprotected |
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.
node | the parse tree node |
pos | the child position |
ParseException | if either the node was null, or the value wasn't an integer |
|
inlineprotected |
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.
node | the parse tree node |
pos | the child position |
ParseException | if either the node was null, or the value wasn't a string |
|
inlineprotected |
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.
node | the parse tree node |
pos | the child position |
ParseException | if either the node or the value was null |
|
inlinevirtual |
Factory method to create a new production node.
This method can be overridden to provide other production implementations than the default one.
pattern | the production pattern |
|
inlinevirtual |
Resets this analyzer when the parser is reset for another input stream.
The default implementation of this method does nothing.