Syntax tree builder base class.
Implements the basic infrastructure for building CTree based syntax trees.
Tree builders are used in the syntax analysis to create the nodes of the syntax tree according to the accepted grammar (see class Syntax). A syntax tree shall be destroyed using the tree builder that has created it by calling its method Builder::destroy(CTree*) with the root node of the syntax tree as its argument.
The builder is organized as a multi-level stack. If a grammar rule is parsed then a new stack level is created. The sub-trees of the syntax tree representing the parsed grammer rule are pushed on this level of the stack. If the grammar rule is parsed successfully then these sub-trees are used to build the syntax tree representing the parsed grammar rule (and thus the corresponding source code). The current stack level is then discarded and the created syntax tree is pushed on the stack of the previous level (which is now the top level of the stack). If the grammar rule could not be parsed successfully then the current stack level is discarded and all the sub-trees pushed on it are destroyed.
|
virtual void | destroyNode (CTree *node) |
| Destroy the given syntax tree node.
|
|
void | errors (ErrorSink &e) |
| Print the collected error messages on the given error output stream.
|
|
ErrorSink & | err () const |
| Get the collected errors.
|
|
void | save_state () |
| Save the current state.
|
|
void | forget_state () |
| Discard the saved state.
|
|
void | restore_state () |
| Restore the saved state.
|
|
CTree * | token (Token *t) |
| Create a new CT_Token object for the given token.
|
|
CTree * | error () |
| Create a new CT_Error object.
|
|
int | nodes () const |
| Get the current number of nodes on the builder stack.
|
|
CTree * | get_node (int n=0) const |
| Get the n-th node from the builder stack.
|
|
void | setTokenCounter (unsigned long v) |
| Reset the token counter.
|
|
unsigned long | getTokenCounter () const |
| Get the current token count.
|
|
| PtrStack (long size=8192, long incr=8192) |
| Construct a new layered stack.
|
|
virtual | ~PtrStack () |
| Destructor.
|
|
void | Push (const CTree *item) |
| Add a new item on the top of the current layer.
|
|
void | Pop () |
| Remove the top item from the current layer.
|
|
CTree * | Top () const |
| Get the top item from the current layer.
|
|
long | Length () const |
| Get the number of items added to the current layer.
|
|
CTree * | Get (long n) const |
| Get the n-th item on the current layer.
|
|
void | New () |
| Create a new layer.
|
|
void | Forget () |
| Remove the top layer and add its items to the underlying layer.
|
|
void | Reject () |
| Remove the top layer.
|
|
void | Destroy () |
| Remove the top layer and delete its items.
|
|
long | Stacks () const |
| Get the number of layers.
|
|
void | Reset () |
| Remove all layers.
|
|