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