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

Interpret Class Reference

#include <interpret.h>

Collaboration diagram for Interpret:

Collaboration graph
[legend]

Public Member Functions

 Interpret (Lexer &SedLex)
 ~Interpret (void)
const bool Run (void)

Protected Member Functions

virtual void Initialize (void)
virtual void ShiftRule (const int TopSymbol)
virtual const bool ReduceRule (const int TopSymbol)

Private Attributes

LexerduraLex

Constructor & Destructor Documentation

Interpret::Interpret Lexer SedLex  ) 
 

Definition at line 90 of file interpret.cpp.

References Initialize().

00091 : duraLex( SedLex )
00092 {
00093         Initialize();
00094 }

Interpret::~Interpret void   )  [inline]
 

Definition at line 75 of file interpret.h.

00076         {
00077                 for( deque<TreeNode *>::iterator it = begin() ; it != end() ; ++it )
00078                         delete (*it);
00079                 clear();
00080         };


Member Function Documentation

void Interpret::Initialize void   )  [protected, virtual]
 

Definition at line 142 of file interpret.cpp.

References duraLex, and Lexer::EofId().

Referenced by Interpret().

00143 {
00144         clear();
00145         push_back( new TreeNode( duraLex.EofId() ) );
00146 }

const bool Interpret::ReduceRule const int  TopSymbol  )  [protected, virtual]
 

Definition at line 156 of file interpret.cpp.

References TreeNode::child, and TreeNode::next.

Referenced by Run().

00157 {
00158         TreeNode *tn = back();
00159         pop_back();
00160         TreeNode *tn2 = back();
00161         back()->next = 0;
00162         tn->next = tn->child;
00163         tn->child = back()->child;
00164         back()->child = tn;
00165 
00166         return true;
00167 }

const bool Interpret::Run void   ) 
 

case of Error

Definition at line 105 of file interpret.cpp.

References Lexer::atSr(), duraLex, Lexer::GetConstant(), Lexer::GetTopSymbol(), ReduceRule(), and ShiftRule().

Referenced by Ars::ExprIntParser::Eval(), Ars::ExprParser::Eval(), and ExprParser::Eval().

00106 {
00107         int     ts = duraLex.GetTopSymbol();
00108 
00109         while( ts != -1 )
00110         {
00111                 switch( duraLex.atSr( back()->symbolId , ts ) )
00112                 {
00113                         default :
00114                         case ' ' :      
00115                         {       printf( "syntax error:\n" );
00116                                 for( deque<TreeNode*>::iterator it = begin() ; it != end() ; ++it )
00117                                 {
00118                                         const char      *s = (*it)->constant.empty() ? "" : (*it)->constant.c_str();
00119                                         printf( "%s\t" , s );
00120                                 }
00121                                 printf( "\nwith terminal symbol: %s\n" , duraLex.GetConstant().c_str() );
00122                         }
00123                                 return false;
00124 
00125                         case '=' :      //      Shift the stack... according to the grammar rule
00126                         case '<' :      //      Shift the stack... according to the grammar rule
00127                                 ShiftRule( ts );
00128                                 ts = duraLex.GetTopSymbol();
00129                                 break;
00130 
00131                         case '>' :      //      Reduce
00132                                 if( !ReduceRule( ts ) )
00133                                         return false;
00134                                 break;
00135                         case '$' :
00136                                 return true;
00137                 }
00138         }
00139         return true;
00140 }

void Interpret::ShiftRule const int  TopSymbol  )  [protected, virtual]
 

Definition at line 148 of file interpret.cpp.

References duraLex, Lexer::GetConstant(), and TreeNode::next.

Referenced by Run().

00149 {
00150         TreeNode *tn2 = back();
00151         back()->next = new TreeNode( TopSymbol , duraLex.GetConstant() );
00152         push_back( back()->next );
00153         tn2 = back();
00154 }


Field Documentation

Lexer& Interpret::duraLex [private]
 

Definition at line 69 of file interpret.h.

Referenced by Initialize(), Run(), and ShiftRule().


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