-
September 13th, 2012, 01:37 PM
#1
Please Provide an Algorithm and Source Code
I hve an assignment to make
i have to make a C/C++ Program that automatically identifies any expression entered and solves the answer..
Example if i enter an expression like 3.14+(14-23*4/6)*7 it should evaulate it according to the precedence of the operator and give a numeric answer...
I need to generate a Grammar and then a parse tree and then finally evaluate that parse tree...but i dont know where to start and how to code.
please provide the source code and flowchart also (if possible)....
-
September 13th, 2012, 02:31 PM
#2
Re: Please Provide an Algorithm and Source Code
See this http://forums.codeguru.com/showthrea...ork-assignment regarding what this forum can help you with
-
September 14th, 2012, 03:35 AM
#3
Re: Please Provide an Algorithm and Source Code
Originally Posted by krprashant1
I need to generate a Grammar and then a parse tree and then finally evaluate that parse tree...but i dont know where to start and how to code.
If this is done as part of some course you should know what to do but if not you could try a Recursive Descent Parser. It's simple and straightfoward so there are plenty of resources on the net you can look for. Here's one,
http://en.wikipedia.org/wiki/Recursive_descent_parser
You start by developing the grammar making sure it's LL(1). Then the actual parser follows almost automatically from the grammar.
For the evaluation you have two options. Either evaluate immediately during parsing or generate a parse tree which is evaluated afterwards. It's virtually the same because the recursive parsing process will walk through an implicit parse tree. It's your choise whether you evaluate by making it explicit or not.
Last edited by nuzzle; September 14th, 2012 at 03:46 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|