• 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.
0
basant
Asked:
basant
  • 7
  • 3
  • 2
1 Solution
 
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
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.  

 
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
 
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

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