help-flex
[Top][All Lists]
Advanced

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

Is there way to complete my Calculator with Bison/Flex or other GNU tool


From: Wang Yige
Subject: Is there way to complete my Calculator with Bison/Flex or other GNU tools?
Date: Tue, 04 Jul 2006 01:12:03 +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 this->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 = calcer.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 an other word, Can yylex ,yyparse() be encapsulated in a C++ Class ?

Anybody 's any help is appreciated very much!

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




reply via email to

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