Changeset 7367 for code/branches/doc/src/libraries/util/ExprParser.h
- Timestamp:
- Sep 6, 2010, 3:51:29 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/doc/src/libraries/util/ExprParser.h
r6417 r7367 28 28 29 29 /** 30 31 30 @file 31 @brief Declaration of FloatParser 32 32 */ 33 33 … … 42 42 namespace orxonox 43 43 { 44 /** Parser for expressions like \c "3 * cos(5 + 4) / a" where \a a is a predeclared 45 variable. 46 @par Usage 47 Using it is rather simple: 48 @code 49 std::string str("3 + 4"); 50 ExprParser expr; 51 expr.parse(str); 52 if (expr.getSuccess()) 53 { 54 if (!expr.getRemains().empty()) 55 { 56 COUT(2) << "Warning: Expression could not be parsed to the end! Remains: '" << expr.getRemains() << '\'' << std::endl; 57 } 58 double result = expr.getResult(); 59 } 60 else 61 COUT(1) << "Error: Cannot calculate expression: Parse error." << std::endl; 62 @endcode 63 getRemains() returns the expression after what could be parsed. For instance 64 \c "2*3 text" will return \c "text" as remains. 65 @details 66 The implementation of this class is really old and sort of a trial for 67 a first C++ class by Reto. That explains why it looks more like C than 68 C++... Also some of the variable names are in German. <br> 69 Explaining how it works exactly is probably not possible anymore, but it 70 is based on recursively parsing the expression character by character. 71 That much I can remember. 72 @par Functions, operators and variables supported 73 - Variables: 74 - e 75 - pi 76 - Functions: 77 - sin, asin, sinh, asinh 78 - cos, acos, cosh, acosh 79 - tan, atan, tanh, atanh 80 - int, floor, ceil, abs, sign 81 - pow, sqrt, exp, ln, log 82 - mod, div 83 - min, max 84 - radians, degrees 85 - Operators: 86 - +, -, ! (unary) 87 - +, -, *, /, %, ^, |, &, !, <, >, !=, <=, >=, = 88 @note 89 Operators may not be very consistent with C++ rules, but using the class 90 for plus and minus should be perfectly ok. 91 */ 44 92 class _UtilExport ExprParser 45 93 {
Note: See TracChangeset
for help on using the changeset viewer.