• C

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.
LVL 2
basantAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

basantAuthor Commented:
Edited text of question.
0
AlexVirochovskyCommented:
See eval function:
http://www.snippets.org/EVAL.C
http://www.snippets.org/EVAL.HOW
I think, it is that you want.
Alex
0
basantAuthor Commented:
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.

0
Managing Security Policy in a Changing Environment

The enterprise network environment is evolving rapidly as companies extend their physical data centers to embrace cloud computing and software-defined networking. This new reality means that the challenge of managing the security policy is much more dynamic and complex.

AlexVirochovskyCommented:
You can easy add this ability to eval:
simple before eval you must check
you expression, find names (i use for this delimeters: if something between delimeters is not '(' or is not operation  , it is name), count value of names,
replace in expression names to values, and use eval after that.
Alex
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
basantAuthor Commented:
Give me some time to
evaluate your answer.

Basant.
0
sa9813Commented:
I have a simple parser, parsing logical expressions...If you want it just let me know!
0
basantAuthor Commented:
Please give me your parser program.
I can start with that. It also
give me basic idea too.
I will wait for it.

Thnaks
0
sa9813Commented:
Sorry if I have kept you waiting! How shall I send it to you?
0
basantAuthor Commented:
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.
0
sa9813Commented:
I can mail it to you, only problem I do not have your e-mail address. I do not need any points.
0
basantAuthor Commented:
Thanks for ur kindness.
Sorry I forgot to write my
e-mail address.
my e-mail id is
basant_kukreja@hotmail.com
0
basantAuthor Commented:
Though your code was applicable for
constants but even though it was a good
help.
Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.