Implement an expression parser
|
:wave::wave::wave: HOW CAN WE IMPLEMENT AN EXPRESSION PARSER IN C++. CAN ANYONE PLSSSSSSSS HELP ME ..... ??? THANX IN ADVANCE. :thumb::thumb::thumb:
NOTE :- ITS A LITTLE BIT URGENT ................
|
Re: Implement an expression parser
There is a lot of discussions about it like
http://stackoverflow.com/questions/1...ression-in-c-c
and others
And if it is "A LITTLE BIT URGENT" then you had to begin working on this problem "a little bit" earlier!
Re: Implement an expression parser
A lot of the complexity (or not) of this will be around what is deemed to be an 'expression'. If you haven't already got/done this then the first step is to define the 'language' of the expression - what are its basic elements (eg numbers, arithmetic symbols etc) and how can these elements be correctly combined to produce a valid expression. Once you have the 'language' defined then you can best determine the type of parser required. There are various types of parsers depending upon the 'language' that is required to be parsed. One of the more popular methods is the recursive descent parser See http://www.dreamincode.net/forums/to...ser-oop-style/ for an example
The method of parsing may also be influenced by the required output of the parser and how the output is to be used. eg do you need an expression tree that can be traversed or if the expression is simple do you just want reverse polish format output?
Sorry I can't provide more guidance at this stage as your initial query about building an expression parser is rather general.
Re: Implement an expression parser
The most famous parsing algorithm specifically for math expression parsing is the Shunting-yard algorithm by Dijkstra,
http://en.wikipedia.org/wiki/Shunting-yard_algorithm