Link to home
Start Free TrialLog in
Avatar of basant
basant

asked on

Expression Evaluation code & Algorithm

Dear Experts,
   Can u please tell me where
can I find the code for
( 1) Parsing a expression string
(2) evaluating the expression

I think I may get it in many data
structures book but I don't have
many of them with me now.

Can I find it on internet.

What I know is that I can
parse the string, make a binary tree
and evaluate that.

I can write the code but I am sure
it will be available free of cost
on internet.


Does C/C++ library give support for that ?
Can I find it in Linux Source code ?

Ex of Expression :
"(a<3) OR (( b> 4) AND ( c != 5 ) )"


If some of u have the code , can
you give it to me.

Thanks in Advance.
Avatar of basant
basant

ASKER

Edited text of question.
See eval function:
http://www.snippets.org/EVAL.C
http://www.snippets.org/EVAL.HOW
I think, it is that you want.
Alex
Avatar of basant

ASKER

Thanks Alex for giving me such
a good web site reference but
my problem is bit different.

This algorithm works good if you
want to evaluate a expression once.
But I want to evaluate an expression
n No Of Times depends on Variable
Names. My Expression consist of
variable names and constant integers
and strings.
E.g.
(a == 5) AND (( b == "Hello") OR ( c == 10.4)


I want to evaluate the expression based on different values of a,b and c.
For this to work I had to make a tree
 representing the expression and then
evaluate it using traversal.

Even then your code will give me a lot of help to start with.

Thanks Any way.

ASKER CERTIFIED SOLUTION
Avatar of AlexVirochovsky
AlexVirochovsky

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of basant

ASKER

Give me some time to
evaluate your answer.

Basant.
I have a simple parser, parsing logical expressions...If you want it just let me know!
Avatar of basant

ASKER

Please give me your parser program.
I can start with that. It also
give me basic idea too.
I will wait for it.

Thnaks
Sorry if I have kept you waiting! How shall I send it to you?
Avatar of basant

ASKER

Sorry I completed that part of
the project. But even though I
would like to see it.
Can you mail it in form of
ZIP file.

Also I don't know whom to give
point for this question.
I can mail it to you, only problem I do not have your e-mail address. I do not need any points.
Avatar of basant

ASKER

Thanks for ur kindness.
Sorry I forgot to write my
e-mail address.
my e-mail id is
basant_kukreja@hotmail.com
Avatar of basant

ASKER

Though your code was applicable for
constants but even though it was a good
help.
Thanks.