I want to parse expressions such as res = ((a*(2+b))/c)+5.603+(6*(d^5)). I want to do it in c++ only.
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Correctly parse PDF paragraphs with Python
- Why does const allow implicit conversion of refere
- thread_local variables initialization
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- How do I get from a type to the TryParse method?
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
There is a thorough treatment of a possible approach to here:
http://www.ibm.com/developerworks/library/j-w3eval/index.html
The code is in java, but is quite portable to C++.
Have a look at the "Available C++ Libraries" FAQ
Stroustrup explains how you'd evaluate expressions like
((1*(2+3))/4)+5.603+(6*(11^5))
. Basically, you build an evaluation tree for all subexpressions.Your example has three extra steps. In parsing, you have to note the variables
a
, and in evaluating you have to replace the variables with their current values. Finally, you need to assign the result to variables.You can use a
std::map<std::string, double>
to hold the variable names and values.