-
Notifications
You must be signed in to change notification settings - Fork 0
/
expEvaluator.h
66 lines (49 loc) · 2.35 KB
/
expEvaluator.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#ifndef EXP_EVALUATOR_H
#define EXP_EVALUATOR_H
//**************************************************************************************
#include <map>
#include <string>
using namespace std;
typedef map<string,float> floatVarValueTable;
//A variable table recording the names (strings) of variables
//and the current floating point values of these variables
typedef vector<string> expVector;
//An expression vector is a vector of token strings
class ExpressionEvaluator
{
public:
static int precedenceLevel(const string & opToken);
//return the precedence level of an operator toekn
static bool postfixEvaluator( const expVector & postfixExp,
float & expValue );
//Evaluate the value of the postfix expression in postfixExp
//with respect to the variables and their current values in varTable.
//finally store the value of the expresson in expValue.
//If postfixExp is not a valid postfix expression, return false; otherwsie return true.
static bool infixToPostfixConversion( const expVector & infixExp, expVector & postfixExp );
//Convert the infix expression in infixExp into a corresponding postfix expression.
//Store the corresponding postfix expression in postfixExp.
//If infixExp is not a valid infix expression, return false; otherwsie return true.
static bool infixEvaluator ( const expVector & infixExp,
float& expValue
);
//Evaluate the value of the infix expression in postfixExp
//with respect to the variables and their current values in varTable.
//finally store the value of the expresson in expValue.
//If postfixExp is not a valid postfix expression, return false; otherwsie return true.
static bool infixEvaluator( expVector::iterator begin,
expVector::iterator end,
float &expValue
);
//Evaluate the value of an infix expression
//that is embedded within an expression vector
//The two expVector::iterator iterators: begin and end specify
//where the infix expression is embedded.
//
//Evaluate the value of an infix expression
//with respect to the variables and their current values in varTable.
//finally store the value of the expresson in expValue.
//If postfixExp is not a valid postfix expression, return false; otherwsie return true.
};
//**************************************************************************************
#endif // Matching the starting #ifndef EXP_EVALUATOR_H