Files Classes Functions Hierarchy
#include <rawinterpreter.h>
Public Member Functions | |
| fdatainterp () | |
| ~fdatainterp () | |
| void | reset () |
| void | eval (string const &word) |
| void | process2_silent (istream &is) |
| template<typename T > | |
| void | process2 (istream &is, T &prnt) |
| void | add (fbuildbase *x) |
| template<typename T > | |
| void | addtodictionary (T) |
Public Attributes | |
| vector< fbuildbase * > | dicttable |
| map< string, fbuildbase * > | dict |
Definition at line 81 of file rawinterpreter.h.
| fdatainterp::fdatainterp | ( | ) |
| fdatainterp::~fdatainterp | ( | ) |
| void fdatainterp::add | ( | fbuildbase * | x | ) | [inline] |
| void fdatainterp::addtodictionary | ( | T | ) | [inline] |
Definition at line 119 of file rawinterpreter.h.
References fbuildbase::copy(), and dicttable.
Referenced by addtothedictionary< T >::addtothedictionary().
00120 { 00121 // No support for inc() dec() with building 00122 // functions. fn is copied twice and the 00123 // functions themselves are not persistant 00124 // with a reset. 00125 fbuildbase* fn = new fbuild< typename T::type>(); 00126 dicttable.push_back(fn); 00127 add(fn->copy()); 00128 }
| void fdatainterp::eval | ( | string const & | word | ) |
Definition at line 225 of file rawinterpreter.cpp.
References inputstatescope::cscope, dict, inputstatescope::evalimmediate, inputstatescope::evaloverride, and inputstatescope::evalpreserved.
Referenced by outerinput::eval(), innerinput::eval(), and test03().
00226 { 00227 // 1. Determine if word is a number else 00228 // 2. Determine if word is in the dictionary else 00229 // 3. assume word is a string. 00230 char ch = word[0]; 00231 00232 if ( (ch=='-') && (word.size()>1)) 00233 ch = word[1]; 00234 00235 if ( (ch=='.') && (word.size()>1)) 00236 ch = word[1]; 00237 00238 if ( isdigit(ch) ) 00239 { 00240 // Is the number real or integer. 00241 bool integertype=true; 00242 for (unsigned int i=0, imax=word.size(); i<imax; ++i) 00243 { 00244 if( word[i]=='.') 00245 { 00246 integertype=false; 00247 i=imax; 00248 } 00249 } 00250 00251 // Construct the number. 00252 if (integertype) 00253 new rpninteger( rpnprogramstackstate().ds(), integer(word) ); 00254 else 00255 new rpnreal( rpnprogramstackstate().ds(), real(word) ); 00256 00257 return; 00258 } 00259 00260 // Not a number 00261 00262 #ifdef DEBUG_INTERPRETER 00263 cout << "Input: Not a number." << endl; 00264 #endif 00265 00266 // The user can force a string onto the stack. 00267 /* 00268 if (ch=='"') 00269 { 00270 if (word.size()==1) 00271 return; 00272 00273 string w(word.begin()+1,word.end()); 00274 new rpnstring( rpnprogramstackstate().ds(), w ); 00275 00276 return; 00277 } 00278 */ 00279 00280 // Search the dictionary. 00281 00282 // The # symbol indicates the item should not be evaluated. 00283 // The @ symbol indicates the item should be evaluated. 00284 if ((ch=='#')||(ch=='@')) 00285 { 00286 if (word.size()<=2) 00287 { 00288 if (word.size()==1) 00289 return; // Ignore lone # or @ character. 00290 00291 // Setting the mode was so important that I took it away 00292 // from the standard function system. 00293 if (word=="@+") 00294 { // Set immediate evaluation mode. 00295 inputstatescope::cscope->evalimmediate = true; 00296 return; 00297 } 00298 00299 if (word=="@-") 00300 { // Unset immediate evaluation mode. 00301 inputstatescope::cscope->evalimmediate = false; 00302 return; 00303 } 00304 } 00305 00306 bool tmpeval = true; 00307 if (ch=='#') 00308 tmpeval = false; 00309 00310 string word2(word.begin()+1,word.end()); 00311 00312 map<string,fbuildbase*>::iterator i = dict.find(word2); 00313 if (i!=dict.end()) 00314 { 00315 inputstatescope::cscope->evaloverride = true; 00316 inputstatescope::cscope->evalpreserved = 00317 inputstatescope::cscope->evalimmediate; 00318 inputstatescope::cscope->evalimmediate = tmpeval; 00319 00320 i->second->make(); 00321 00322 inputstatescope::cscope->evalimmediate = 00323 inputstatescope::cscope->evalpreserved; 00324 inputstatescope::cscope->evaloverride = false; 00325 00326 return; 00327 } 00328 00329 } 00330 else 00331 { 00332 00333 #ifdef DEBUG_INTERPRETER 00334 cout << "Input: Not a evaluation directive, word=" << 00335 word << "." << endl; 00336 #endif 00337 00338 map<string,fbuildbase*>::iterator i = dict.find(word); 00339 if (i!=dict.end()) 00340 { 00341 i->second->make(); 00342 00343 return; 00344 } 00345 } 00346 00347 // Assume a string 00348 00349 #ifdef DEBUG_INTERPRETER 00350 cout << "Input: string*" << word << "*" << endl; 00351 #endif 00352 00353 new rpnstring( rpnprogramstackstate().ds(), word ); 00354 };
| void fdatainterp::process2 | ( | istream & | is, | |
| T & | prnt | |||
| ) | [inline] |
Definition at line 242 of file rawinterpreter.h.
00243 { 00244 char c; 00245 char const quote('"'); 00246 char const space(' '); 00247 char const ret('\n'); 00248 00249 string s; 00250 00251 string const quit("quit"); 00252 00253 while ((c = is.peek())) 00254 { 00255 s.clear(); 00256 00257 if (c==quote) 00258 { 00259 is.get(c); 00260 is.get(c); 00261 while (c!=quote) 00262 { 00263 s += c; 00264 is.get(c); 00265 } 00266 00267 new rpnstring( rpnprogramstackstate().ds(), s ); 00268 } 00269 else 00270 if (c=='(') 00271 { 00272 complex< long double > x; 00273 is >> x; 00274 00275 new rpncomplex( rpnprogramstackstate().ds(), x ); 00276 00277 00278 } 00279 else 00280 { 00281 is.get(c); 00282 if ((c!=space)&&(c!=ret)) 00283 { 00284 s += c; 00285 is.get(c); 00286 while ((c!=space)&&(c!=ret)) 00287 { 00288 s += c; 00289 is.get(c); 00290 } 00291 } 00292 00293 if (!s.empty()) 00294 SingletonPtr<inputstatescope>()->eval(s); 00295 00296 } 00297 00298 if (s==quit) 00299 break; 00300 00301 prnt(); 00302 } 00303 }
| void fdatainterp::process2_silent | ( | istream & | is | ) |
Definition at line 471 of file rawinterpreter.cpp.
00472 { 00473 char c; 00474 char const quote('"'); 00475 char const space(' '); 00476 char const ret('\n'); 00477 00478 string s; 00479 00480 string const quit("quit"); 00481 00482 while ((c = is.peek())) 00483 { 00484 //cout << "c=" << c << endl; 00485 s.clear(); 00486 00487 if (c==quote) 00488 { 00489 is.get(c); 00490 is.get(c); 00491 while (c!=quote) 00492 { 00493 s += c; 00494 is.get(c); 00495 if (!is) 00496 return; 00497 } 00498 00499 new rpnstring( rpnprogramstackstate().ds(), s ); 00500 } 00501 else 00502 if (c=='(') 00503 { 00504 complex< long double > x; 00505 is >> x; 00506 00507 new rpncomplex( rpnprogramstackstate().ds(), x ); 00508 00509 } 00510 else 00511 { 00512 is.get(c); 00513 if ((c!=space)&&(c!=ret)) 00514 { 00515 s += c; 00516 is.get(c); 00517 //cout << "c=" << c << endl; 00518 while ((c!=space)&&(c!=ret)) 00519 { 00520 s += c; 00521 is.get(c); 00522 //cout << "c=" << c << endl; 00523 if (!is) 00524 return; 00525 } 00526 } 00527 00528 if (!s.empty()) 00529 SingletonPtr<inputstatescope>()->eval(s); 00530 00531 } 00532 00533 if (!is) 00534 return; 00535 00536 if (s==quit) 00537 break; 00538 } 00539 }
| void fdatainterp::reset | ( | ) |
Definition at line 193 of file rawinterpreter.cpp.
References dicttable.
00194 { 00195 dictionarydelete(); 00196 00197 // Build the dictionary. 00198 for (unsigned int i=0, n=dicttable.size(); i<n; ++i) 00199 add( dicttable[i]->copy() ); 00200 }
| map<string,fbuildbase*> fdatainterp::dict |
| vector< fbuildbase* > fdatainterp::dicttable |
1.5.8