-
May 5th, 2014, 03:43 AM
#1
Implement an expression parser
|
HOW CAN WE IMPLEMENT AN EXPRESSION PARSER IN C++. CAN ANYONE PLSSSSSSSS HELP ME ..... ??? THANX IN ADVANCE.
NOTE :- ITS A LITTLE BIT URGENT ................
|
-
May 5th, 2014, 04:17 AM
#2
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!
Victor Nijegorodov
-
May 5th, 2014, 06:03 AM
#3
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.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
May 5th, 2014, 07:59 AM
#4
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
Tags for this Thread
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
|