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

Ars::ExprParser Class Reference

#include <exprint.h>


Public Member Functions

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

Private Member Functions

void WalkTree (TreeNode *tn, Context &ctx)


Constructor & Destructor Documentation

Ars::ExprParser::ExprParser void   )  [inline]
 

Definition at line 83 of file ars/exprint.h.

00084         {
00085         }


Member Function Documentation

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

Definition at line 95 of file ars/exprint.h.

References WalkTree().

00096         {
00097                 Context ctx( variables );
00098                 WalkTree( tn , ctx );
00099                 return new SumRandom( *ctx.rdm );
00100         }

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

Definition at line 87 of file ars/exprint.h.

References Interpret::Run().

00088         {
00089                 Expr    lex( aBuffer );
00090                 Interpret       itp( lex );
00091                 itp.Run();
00092                 return itp.back();
00093         }

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

< Value

< Identifier: check if already existing if not create it

Definition at line 104 of file ars/exprint.h.

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

Referenced by Apply().

00105         {
00106                 if( tn )
00107                 {
00108                         Context lctx( ctx );
00109                         if( tn->child != 0 )
00110                                 WalkTree( tn->child , lctx );
00111 
00112                         Context rctx( ctx );
00113                         if( tn->next != 0 )
00114                                 WalkTree( tn->next , rctx );
00115 
00116                         if( tn->symbolId == 9 )         
00117                                 ctx.val = atof( tn->constant.c_str() );
00118                         else if( tn->symbolId == 5 )
00119                         {
00120                                 map<string,double>::iterator    pos = ctx.variables.find( tn->constant );
00121                                 if( pos != ctx.variables.end() )
00122                                         ctx.val = pos->second;
00123                         }
00124                         else
00125                         {
00126                                 ctx = lctx;     
00127 
00128                                 switch( tn->constant.c_str()[0] )
00129                                 {
00130                                         case '+' : ctx += rctx; break;
00131                                         case '-' : ctx -= rctx; break;
00132                                         case '*' : ctx *= rctx; break;
00133                                         case '/' : ctx /= rctx; break;
00134                                         case '|' : ctx |= rctx; break;
00135                                         default:
00136                                                 if( lctx.val != 0 )
00137                                                         ctx = lctx;
00138                                                 if( rctx.val != 0 )
00139                                                         if( ctx.val == 0 )
00140                                                                 ctx = rctx;
00141                                                         else
00142                                                                 printf( "ERROR\n" );
00143                                                 break;
00144                                 }
00145                         }
00146                 }
00147         }


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