• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 464
  • Last Modified:

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.
  • 7
  • 3
  • 2
1 Solution
basantAuthor Commented:
Edited text of question.
See eval function:
I think, it is that you want.
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.
(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.

Get Certified for a Job in Cybersecurity

Want an exciting career in an emerging field? Earn your MS in Cybersecurity and get certified in ethical hacking or computer forensic investigation. WGU’s MSCSIA degree program was designed to meet the most recent U.S. Department of Homeland Security (DHS) and NSA guidelines.  

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.
basantAuthor Commented:
Give me some time to
evaluate your answer.

I have a simple parser, parsing logical expressions...If you want it just let me know!
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.

Sorry if I have kept you waiting! How shall I send it to you?
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.
I can mail it to you, only problem I do not have your e-mail address. I do not need any points.
basantAuthor Commented:
Thanks for ur kindness.
Sorry I forgot to write my
e-mail address.
my e-mail id is
basantAuthor Commented:
Though your code was applicable for
constants but even though it was a good

Featured Post

Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

  • 7
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now