EnglishFrenchGermanSpainItalianDutchPortugueseRussianKoreanJapaneseArabic Chinese Simplified

Tuesday, June 28, 2011

OOP Recursive Decent Parsing III

we are going to use the Production class as the base class for each one of our productions. Polymorphism with the Production class will come in shortly. Now the most basic production we have here is number. It’s a terminal production and can be implemented quite easily.


/**
* a class to parse a number from the input stream
*/
class Number : public Production {
private:
 double value;
public:
 Number(std::istream& in);
 ///Override
 double getValue();
}; 
 
/**
* Number
*/

Number::Number(std::istream& in) {
 ignoreSpace(in); //remove all preceding space
 in>>value;
 if(!in) {
  throw ParseError();
  return;
 }
 ignoreSpace(in); //remove all following space
}

///Override
double Number::getValue() {
 return value;
}
 

Artikel Terkait:

Comments :

0 comments to “OOP Recursive Decent Parsing III”

Post a Comment

 

Copyright © 2009 by Learn Technology

Template by Blogger Templates | Powered by Blogger