PUMA Library Reference Manual
Puma::Builder Class Reference

#include <Puma/Builder.h>

+ Inheritance diagram for Puma::Builder:

Description

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.

Classes

class  Container
 Container class for collecting a set of syntax tree nodes. More...
 

Public Member Functions

virtual void destroyNode (CTree *node)
 Destroy the given syntax tree node. More...
 
void errors (ErrorSink &e)
 Print the collected error messages on the given error output stream. More...
 
ErrorSinkerr () const
 Get the collected errors. More...
 
void save_state ()
 Save the current state. More...
 
void forget_state ()
 Discard the saved state. More...
 
void restore_state ()
 Restore the saved state. More...
 
CTreetoken (Token *t)
 Create a new CT_Token object for the given token. More...
 
CTreeerror ()
 Create a new CT_Error object. More...
 
int nodes () const
 Get the current number of nodes on the builder stack. More...
 
CTreeget_node (int n=0) const
 Get the n-th node from the builder stack. More...
 
void setTokenCounter (unsigned long v)
 Reset the token counter. More...
 
unsigned long getTokenCounter () const
 Get the current token count. More...
 
- Public Member Functions inherited from Puma::PtrStack< CTree >
 PtrStack (long size=8192, long incr=8192)
 Construct a new layered stack. More...
 
virtual ~PtrStack ()
 Destructor. More...
 
void Push (const CTree *item)
 Add a new item on the top of the current layer. More...
 
void Pop ()
 Remove the top item from the current layer. More...
 
CTreeTop () const
 Get the top item from the current layer. More...
 
long Length () const
 Get the number of items added to the current layer. More...
 
CTreeGet (long n) const
 Get the n-th item on the current layer. More...
 
void New ()
 Create a new layer. More...
 
void Forget ()
 Remove the top layer and add its items to the underlying layer. More...
 
void Reject ()
 Remove the top layer. More...
 
void Destroy ()
 Remove the top layer and delete its items. More...
 
long Stacks () const
 Get the number of layers. More...
 
void Reset ()
 Remove all layers. More...
 

Static Public Member Functions

static void destroy (CTree *tree, bool recursive=true)
 Destroy the given syntax tree recursively. More...
 

Protected Member Functions

 Builder ()
 Constructor. More...
 
void Delete ()
 Destroy the top tree node of the builder stack. More...
 
CTreecontainer () const
 Put all nodes on the builder stack into a Container object. More...
 
CTreelist (CT_List *l) const
 Add all nodes on the builder stack to the given list node. More...
 
CTreecopy_list (CT_List *l, Container *c) const
 Add all nodes of the given container to the given list node. More...
 
- Protected Member Functions inherited from Puma::PtrStack< CTree >
virtual void Remove ()
 Remove the top item of the current layer. More...
 

Protected Attributes

ErrorCollector ec
 The error collector object. More...
 

Static Protected Attributes

static unsigned long int token_counter
 Counter for the created CT_Token object. More...
 

Constructor & Destructor Documentation

Puma::Builder::Builder ( )
inlineprotected

Constructor.

Member Function Documentation

CTree * Puma::Builder::container ( ) const
inlineprotected

Put all nodes on the builder stack into a Container object.

CTree* Puma::Builder::copy_list ( CT_List l,
Container c 
) const
protected

Add all nodes of the given container to the given list node.

Parameters
lThe list node.
cThe node container.
void Puma::Builder::Delete ( )
protectedvirtual

Destroy the top tree node of the builder stack.

Reimplemented from Puma::PtrStack< CTree >.

Reimplemented in Puma::CCBuilder.

static void Puma::Builder::destroy ( CTree tree,
bool  recursive = true 
)
static

Destroy the given syntax tree recursively.

Parameters
treeThe root node of the syntax tree.
recursiveDelete sub tree too.
virtual void Puma::Builder::destroyNode ( CTree node)
virtual

Destroy the given syntax tree node.

Child nodes are not destroyed.

Parameters
nodeThe node.
ErrorSink & Puma::Builder::err ( ) const
inline

Get the collected errors.

CTree* Puma::Builder::error ( )

Create a new CT_Error object.

void Puma::Builder::errors ( ErrorSink e)
inline

Print the collected error messages on the given error output stream.

Parameters
eThe error output stream.
void Puma::Builder::forget_state ( )
inline

Discard the saved state.

CTree * Puma::Builder::get_node ( int  n = 0) const
inline

Get the n-th node from the builder stack.

Parameters
nThe index of the node.
unsigned long Puma::Builder::getTokenCounter ( ) const
inline

Get the current token count.

CTree* Puma::Builder::list ( CT_List l) const
protected

Add all nodes on the builder stack to the given list node.

Parameters
lThe list node.
int Puma::Builder::nodes ( ) const
inline

Get the current number of nodes on the builder stack.

void Puma::Builder::restore_state ( )
inline

Restore the saved state.

void Puma::Builder::save_state ( )
inline

Save the current state.

void Puma::Builder::setTokenCounter ( unsigned long  v)
inline

Reset the token counter.

Parameters
vThe new counter value.
CTree* Puma::Builder::token ( Token t)

Create a new CT_Token object for the given token.

Parameters
tThe token.

Member Data Documentation

ErrorCollector Puma::Builder::ec
protected

The error collector object.

unsigned long int Puma::Builder::token_counter
staticprotected

Counter for the created CT_Token object.