Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals

ExprParser Class Reference

#include <expr.h>

Collaboration diagram for ExprParser:

Collaboration graph
[legend]

Public Member Functions

 ExprParser (void)
virtual ~ExprParser (void)
TreeNodeEval (const string &aBuffer)
SumRandomApply (TreeNode *tn)

Static Public Attributes

vector< Uniform * > toDelinExprParser

Private Member Functions

void WalkTree (TreeNode *tn, Context &ctx)

Private Attributes

map< string, Random * > variables
Interpretitp

Constructor & Destructor Documentation

ExprParser::ExprParser void   )  [inline]
 

Definition at line 113 of file expr.h.

References itp.

00113                            : itp( 0 )
00114         {
00115         }

virtual ExprParser::~ExprParser void   )  [inline, virtual]
 

Definition at line 117 of file expr.h.

References itp.

00118         {
00119                 if( itp )
00120                         delete itp;
00121                 itp = 0;
00122 
00123         }


Member Function Documentation

SumRandom* ExprParser::Apply TreeNode tn  )  [inline]
 

Definition at line 135 of file expr.h.

References ExprParser::Context::rdm, variables, and WalkTree().

Referenced by Parameters::CreateGalaxy(), Parameters::SetupPlanetInfo(), and Parameters::SetupStarInfo().

00136         {
00137                 if( tn )
00138                 {
00139                         Context ctx( variables );
00140                         WalkTree( tn , ctx );
00141                         return new SumRandom( *ctx.rdm );
00142                 }
00143                 return 0;
00144         }

TreeNode* ExprParser::Eval const string &  aBuffer  )  [inline]
 

Definition at line 125 of file expr.h.

References itp, and Interpret::Run().

Referenced by Parameters::CreateGalaxy(), Parameters::SetupPlanetInfo(), and Parameters::SetupStarInfo().

00126         {
00127                 Expr    lex( aBuffer );
00128                 itp = new Interpret( lex );
00129                 itp->Run();
00130                 if( !itp->empty() )
00131                         return itp->back();
00132                 return 0;
00133         }

void ExprParser::WalkTree TreeNode tn,
Context ctx
[inline, private]
 

< Value

< Identifier: check if already existing if not create it

Definition at line 150 of file expr.h.

References TreeNode::child, TreeNode::constant, TreeNode::next, ExprParser::Context::rdm, TreeNode::symbolId, toDelinExprParser, ExprParser::Context::val, and ExprParser::Context::variables.

Referenced by Apply().

00151         {
00152                 if( tn )
00153                 {
00154                         Context lctx( ctx );
00155                         if( tn->child != 0 )
00156                                 WalkTree( tn->child , lctx );
00157 
00158                         Context rctx( ctx );
00159                         if( tn->next != 0 )
00160                                 WalkTree( tn->next , rctx );
00161 
00162                         if( tn->symbolId == 9 )         
00163                                 ctx.val = atof( tn->constant.c_str() );
00164                         else if( tn->symbolId == 5 )
00165                         {
00166                                 map<string,Random *>::iterator  pos = ctx.variables.find( tn->constant );
00167                                 if( pos == ctx.variables.end() )
00168                                 {
00169                                         ctx.variables.insert( make_pair( tn->constant , ctx.rdm = new Uniform ) );
00170                                         toDelinExprParser.push_back( dynamic_cast<Uniform *>( ctx.rdm ) );
00171                                 }
00172                                  else
00173                                          ctx.rdm = pos->second;
00174                         }
00175                         else
00176                         {
00177                                 ctx = lctx;     
00178 
00179                                 switch( tn->constant.c_str()[0] )
00180                                 {
00181                                         case '+' : ctx += rctx; break;
00182                                         case '-' : ctx -= rctx; break;
00183                                         case '*' : ctx *= rctx; break;
00184                                         case '/' : ctx /= rctx; break;
00185                                         case '|' : ctx |= rctx; break;
00186                                         default:
00187                                                 if( lctx.rdm != 0 )
00188                                                         ctx = lctx;
00189                                                 if( rctx.rdm != 0 )
00190                                                         if( ctx.rdm == 0 )
00191                                                                 ctx = rctx;
00192                                                         else
00193                                                                 printf( "ERROR\n" );
00194                                                 break;
00195                                 }
00196                         }
00197                 }
00198         }


Field Documentation

Interpret* ExprParser::itp [private]
 

Definition at line 109 of file expr.h.

Referenced by Eval(), ExprParser(), and ~ExprParser().

vector< Uniform * > ExprParser::toDelinExprParser [static]
 

Definition at line 63 of file expr.cpp.

Referenced by WalkTree(), and MainGame::~MainGame().

map<string,Random *> ExprParser::variables [private]
 

Definition at line 22 of file expr.h.

Referenced by Apply().


The documentation for this class was generated from the following files:
Generated on Fri Dec 5 04:06:20 2003 for Borqueror by doxygen 1.3.3