help-flex
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

what should I do if I want to make this?


From: Wang Yige
Subject: what should I do if I want to make this?
Date: Mon, 03 Jul 2006 09:47:18 +0000

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]