Expression evaluation

I have written a program that takes an equation as an argument, converts it to postfix, evaluates it, and spits out the answer. For example, I can type in,

((2^16-1)+((5-3)*((9/3)*5)))/7

and I will get 9366.43 as the output. My question is this, where can I find information on how to perform more advanced expression evaluation? Like that used by compilers, for example. I do realize that the method I am using is similar to what the compiler is doing but I doubt that it is really this simple.

Exceter
LVL 8
ExceterAsked:
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.

ambienceCommented:
can you give a concrete example of the expressions you would like to be able to evaluate. The algorithm used by compilers can be same as the one you have used or it might be little different etc. but it all depends upon the language syntax and other things, but in the end it has to be something that works, and works for all legitimate expressions to be supported.
0
ExceterAuthor Commented:
>> can you give a concrete example of the expressions you would like to be able to evaluate.

It's not so much a peticular kind of expression that I want to evaluate, although I am working towards it being able to solve equations with unknowns, but rather I want to know how a compiler evaluates a source file, finds errors, recognizes function names, etc.

>> ...it has to be something that works, and works for all legitimate expressions to be supported.

That is what I want to know. What kind of algorithm is used to evaluate all of the possible expressions found in a CPP file?

Note: I don't need any code. All I need is an article/tutorial that explains how this is done. I can do the rest myself. I wrote what I have so far from scratch out of a plain text explanation of how to convert from infix to postfix, I even wrote my own dynamic stack and yes I do realize that that is reinventing the wheel. :-)

Exceter
0
Roshan DavisCommented:
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

ambienceCommented:
>> how a compiler evaluates a source file, finds errors, recognizes function names, etc.

that is very much implementation dependent, but in almost all the cases i've found out that compilers use state-machines and grammar rules etc. Maybe the best way for you to understand is to actualy have a look at something like the following

http://eic.sourceforge.net/overview/

this is an open-source C language interpreter. Maybe this can help you understand things.
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
akshayxxCommented:

>>>Note: I don't need any code. All I need is an >>>article/tutorial that explains how this is done. I can >>>do the rest myself. I wrote what I have so far from >>>scratch out of a plain text explanation of how to >>>convert from infix to postfix, I even wrote my own >>>dynamic stack and yes I do realize that that is >>>reinventing the wheel. :-)


nice .. i know this .. and i wud also have written something that much explicit..

sorry for irrelevant comment.. at least i can get notifications on this topic
0
burcarpatCommented:
for peer-reviewed, easy to use and complete parsing tool, recently accepted to boost.org, see,

   http://spirit.sourceforge.net/

this is a blazing fast parser, is not just a simple regex engine, and can be extended easily for future needs.  the introductory example is a simple expression evaluator so i am guessing it's a perfect match ;-)

0
ExceterAuthor Commented:
Please don't think I have forgotten about this question. It is going to take some time for me to sift through all of this information. :-)

Exceter
0
ExceterAuthor Commented:
Okay, I have looked at each of the links that you were good enough to send me. I beleive that the documentation that came with EIC(Extensible Interactive C), suggested by ambience, and the documentation that came with Boost's Spirit Parser, suggested by burcarpat, were the most helpful so I intend to split the points between them.

roshmon and thienpnguyen, I found the links you posted to be helpful as well and so I posting a 50 point question for each of you.

thienpnguyen,
http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_20535056.html

roshmon,
http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_20535057.html

ambience and burcarpat, a moderator should be showing up shortly.

Exceter
0
Computer101Commented:
Points reduced for a split.  You can now accept one experts comment as an answer.  After that, make another question in this topic area for the other expert.  Make the question for the amount of points intended.  Label the question, "Question for (Expert Name) and post this question number in the base of the question, i.e. For your assistance in question # --------


Computer101
E-E Admin
0
ExceterAuthor Commented:
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.