HPCToolkit
ExprEval.hpp
Go to the documentation of this file.
1 // This file is a modified version from Expression Evaluator published at
2 // https://www.strchr.com/expression_evaluator
3 
4 #ifndef __ExprEval_H__
5 #define __ExprEval_H__
6 
7 #include <lib/support/BaseVarMap.hpp> // basic var map class
8 
9 // Error codes enumeration
16 };
17 
18 //typedef char EVAL_CHAR;
19 #define EVAL_CHAR char
20 
21 
22 // Parser class to evaluate math expression
23 // The math expression has to be simple operators:
24 // +,-,*, /, ( and )
25 // Other than those, it will emit error code
26 class ExprEval {
27 private:
31 
32  // variable maps for value substitution
34 
35  // Parse a number or an expression in parenthesis
36  double ParseAtom(EVAL_CHAR*& expr) ;
37 
38  // Parse multiplication and division
39  double ParseFactors(EVAL_CHAR*& expr) ;
40  //
41  // parse a sum or substraction
42  double ParseSummands(EVAL_CHAR*& expr) ;
43 
44 public:
45  // main method to evaluate a math expression
46  double Eval(EVAL_CHAR* expr, BaseVarMap *var_map);
47 
48  // get the error code
50 
51  // the character position of the error
53 
54 };
55 
56 #endif
BaseVarMap * _var_map
Definition: ExprEval.hpp:33
double ParseAtom(EVAL_CHAR *&expr)
Definition: ExprEval.cpp:17
#define EVAL_CHAR
Definition: ExprEval.hpp:19
double Eval(EVAL_CHAR *expr, BaseVarMap *var_map)
Definition: ExprEval.cpp:134
EXPR_EVAL_ERR _err
Definition: ExprEval.hpp:28
EVAL_CHAR * GetErrPos()
Definition: ExprEval.cpp:161
EVAL_CHAR * _err_pos
Definition: ExprEval.hpp:29
double ParseSummands(EVAL_CHAR *&expr)
Definition: ExprEval.cpp:114
double ParseFactors(EVAL_CHAR *&expr)
Definition: ExprEval.cpp:83
EXPR_EVAL_ERR GetErr()
Definition: ExprEval.cpp:156
EXPR_EVAL_ERR
Definition: ExprEval.hpp:10
int _paren_count
Definition: ExprEval.hpp:30