Parser for expressions like "3 * cos(5 + 4) / a"
where a is a predeclared variable.
- Usage
- Using it is rather simple:
expr.parse(str);
if (expr.getSuccess())
{
if (!expr.getRemains().empty())
{
orxout(
user_warning) <<
"Expression could not be parsed to the end! Remains: '" << expr.getRemains() <<
'\'' << endl;
}
float result = expr.getResult();
}
else
getRemains() returns the expression after what could be parsed. For instance "2*3 text"
will return "text"
as remains.
The implementation of this class is really old and sort of a trial for
a first C++ class by Reto. That explains why it looks more like C than
C++... Also some of the variable names are in German. <br>
Explaining how it works exactly is probably not possible anymore, but it
is based on recursively parsing the expression character by character.
That much I can remember.
- Functions, operators and variables supported
- Variables:
- Functions:
- sin, asin, sinh, asinh
- cos, acos, cosh, acosh
- tan, atan, tanh, atanh
- int, floor, ceil, abs, sign
- pow, sqrt, exp, ln, log
- mod, div
- min, max
- radians, degrees
- Operators:
- +, -, ! (unary)
- +, -, *, /, %, ^, |, &, !, <, >, !=, <=, >=, =
- Note
- Operators may not be very consistent with C++ rules, but using the class for plus and minus should be perfectly ok.