forked from AlphaMistral/Expression-Calculator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExpressionParser.hpp
89 lines (72 loc) · 2.27 KB
/
ExpressionParser.hpp
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//
// ExpressionParser.hpp
// Numerical Analysis
//
// Created by 于京平 on 16/7/22.
// Copyright © 2016年 于京平. All rights reserved.
//
#ifndef ExpressionParser_hpp
#define ExpressionParser_hpp
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <ctype.h>
#include <climits>
#include "Expression.hpp"
#include "Function.hpp"
using namespace std;
class ExpressionParser
{
const static int INCOMPLETE = -1;
const static int CORRECT = 0;
const static int SYNTAX = 1;
const static int BRACELET = 2;
const static int DIVIDEZERO = 3;
const static int NONEXIST = -1;
const static int SINGLE = 0;
const static int ADD = 1;
const static int SUB = 2;
const static int MUL = 3;
const static int DIV = 4;
const static int EXP = 5;
private :
Expression *originalExpr;
string parsedExpr;
int p_expr_size;
map < string, double > var_dic;
map < string, Function * > func_dic;
CalculationResult *result;
double GetValue (int, int);
double GetSingleValue (int, int);
double GetFuncValue (string, int, int);
double GetThreeItemOperationValue (int, double, double);
double GetUserDefinedFuncValue (string, int, int);
vector< pair < int, int > > *GetParameters (int, int);
int GetChildExpressionPos (int);
int OperatorReflection (char);
void CheckSingleExpression (CalculationResult *, int, int);
void CheckFunctionExpression (CalculationResult *, string, int, int);
void CheckThreeItemExpression (CalculationResult *, int, int);
public :
//Constructors
ExpressionParser ();
ExpressionParser (Expression *);
//Member Methods
void ParseExpression ();
void ParseExpression (Expression *);
CalculationResult *GetResult ();
CalculationResult *SetVariable (string, double);
CalculationResult *DeleteVariable (string);
CalculationResult *AddNewFunction (string, int, string);
CalculationResult *DeleteFunction (string);
CalculationResult *CheckExpression ();
void InitializeFunctionLib (map < string, Function * > *);
};
#endif /* ExpressionParser_hpp */