Hi everyone,

I am a beginner of Flex and Bison and just know litter about them ,I need your help.

I want to encapsulate a C++ class ,which can works like a calculator,its structure seems like this:
Class Calc
{
public:
 calc(){};
 ~calc(){};

 void setExpr(char *cExpr){this.cExpr = cExpr;}
 char* getExpr(){ return this.cExpr;}

 double getResult(){return result;}

 void lexParse(){ yylex(this.cExpr);...}

 //in yylex, result will be evaluated...
 ....

private:
 char *cExpr;
 double result;
};

If somebody wants to use my Calc, he just use it like this:

Calc calcer;
calcer.setExpr("1+2*3");//the expression to calculate calcer.lexParse(); double dRet = calc.getResult();//the result of the expression As you know ,my calculator's core function in lexParse(), in which I want to use Flex & Bison, I have install Bison2.3 on my HP-Unix OS and I have view the bison manual and its example of calc++,but I find it is not as easy as my calculator in use.

There are more wonders on my calculator' structure than its functions(I just take it as an example ,even though it can only calculate "1+1").

In a word, Can yylex ,yyparse() be encapsulated into a C++ Class ?

Anybody 's any help is appreciated very much!

Thanks for Hans Aberg's help has offered to me!

_________________________________________________________________
享用世界上最大的电子邮件系统― MSN Hotmail。 http://www.hotmail.com


_______________________________________________
help-flex mailing list
help-flex@gnu.org
http://lists.gnu.org/mailman/listinfo/help-flex

Reply via email to