Grammar Class Reference

Grammar Abstract Class. More...

#include <Grammar.hpp>

Inheritance diagram for Grammar:

Function GExpr GStart GTerm FAdd FArgument FConst FDiv FMul FSub GOp List of all members.

Public Member Functions

std::string getGrammarID () const
virtual Resultexecute (Context &context)=0
virtual std::string toString (Context &context)=0
void setExpression (std::vector< Grammar * > *pvpgramExpression, int iRule)
int getExpression (std::vector< Grammar * > *&pvpgramExpression) const
int getNumArguments () const
GrammargetArgument (int iArgument) const
void deleteExpression ()
int getDepth () const
void setDepth (int iDepth)
virtual Grammarclone ()=0

Protected Member Functions

void clone (Grammar *pgramClone)

Detailed Description

Grammar Abstract Class.

Author:
Stephen E. Baker
Date:
2006-2007
Version:
1.0
Abstract class which is inherited by all symbols in the grammar, and indirectly by all functions. This class defines basic methods for interaction between symbols and the rest of the GP system.


Member Function Documentation

void Grammar::clone ( Grammar pgramClone  )  [protected]

Performs common operations for cloning symbols. Specifically this method copies the children nodes and the depth.

Parameters:
[in,out] pgramClone The clone node being produced

virtual Grammar* Grammar::clone (  )  [pure virtual]

Creates a subtree identical to this one in new memory and returns a pointer to it.

Implemented in FAdd, FArgument, FConst, FDiv, FMul, FSub, GExpr, GOp, GStart, and GTerm.

void Grammar::deleteExpression (  ) 

Removes this nodes children and their subtrees, freeing the corresponding memory.

virtual Result* Grammar::execute ( Context context  )  [pure virtual]

Executes the symbol. In the case of non-functions this method calls the appropriate child arguments, coordinating resulting values. In functions this method performs the necessary computation.

Parameters:
[in,out] context The context or key-value pairs to be passed to the functions
Returns:
The result of the primary argument

Implemented in FAdd, FArgument, FConst, FDiv, FMul, FSub, GExpr, GOp, GStart, and GTerm.

Grammar * Grammar::getArgument ( int  iArgument  )  const

Returns a pointer to a particular child of this node.

Parameters:
[in] iArgument The child to be returned

int Grammar::getDepth (  )  const

Returns the depth of this particular node in the symbol tree.

int Grammar::getExpression ( std::vector< Grammar * > *&  pvpgramExpression  )  const

Returns the children of this node.

Parameters:
[out] pvpgramExpression A vector of symbols which follow from this symbol, NULL if there is none.
Returns:
The corresponding rule number from GrammarRules, -1 if there is none.

string Grammar::getGrammarID (  )  const

Returns a string reprsenting the particular grammar symbol the object represents.

int Grammar::getNumArguments (  )  const

Returns the number of children this node has.

void Grammar::setDepth ( int  iDepth  ) 

Sets the depth of this node in the symbol tree.

Parameters:
[in] iDepth The depth

void Grammar::setExpression ( std::vector< Grammar * > *  pvpgramExpression,
int  iRule 
)

Sets the child nodes of this grammar. These nodes are typically created by GrammarRules to match the given grammar.

Parameters:
[in] pvpgramExpression A vector of symbols which follow from this symbol
[in] iRule The corresponding rule number from GrammarRules. May be useful if different rules must be put together differently, for example if a symbol may either be followed by a function and two terminals or by a single terminal then the object must know which it currently must handle.

virtual std::string Grammar::toString ( Context context  )  [pure virtual]

Determines how this symbol and its children are represented when a string is used to represent the program.

Parameters:
[in] context Unused currently, a reimplementation may use the context to determine actual/formal parameter pairs or to print out global variables
Returns:
A string representing this node and all of its arguments

Implemented in Function, GExpr, GOp, GStart, and GTerm.


The documentation for this class was generated from the following files:
Generated on Mon Jan 15 01:21:05 2007 for Creatively Named Grammar Guided Genetic Programming System by  doxygen 1.4.7