-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMath Parser.h
66 lines (59 loc) · 1.33 KB
/
Math Parser.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 ParserH
#define ParserH
#include "XS.h"
class Parser {
static char *mpe;
char *error,state,type;
XS last_error;
int depth;
enum { VAR, VAL, ADD, SUB, MUL,
DIV, POW, NEG, FUNC, ROOT
}; // Òèïû óçëîâ
enum { SIN, COS, TG, CTG, SEC, COSEC,
ARCSIN, ARCCOS, ARCTG, ARCCTG,
SH, CH, TGH, CTGH, LOG, EXP, ABS
}; // Òèïû ôóíêöèé
typedef struct PTS {
int type;
union {
struct {
PTS *r;
union {
PTS *l;
int func;
};
};
double val;
};
} *PT;// Óçåë
PT pres;
static int GetPriority(PT a) {
if (!a) return 0;
switch(a->type) {
case ADD:
case SUB: return 1;
case MUL:
case DIV: return 2;
case POW: return 3;
case NEG: return 4;
case ROOT: return 5;
default: return 6;
}
} // Îïðåäåëåíèå ïðèîðèòåòà îïåðàòîðà
void Destroy(PT); // Äåñòðóêòîð äåðåâà
double Eval(PT,const double &); // Âû÷èñëåíèå äåðåâà
double Eval(const double);
XS LP(char *&); // Ëåêñè÷åñêèé ïàðñåð
PT SP(char *&); // Ñèíòàêñè÷åñêèé ïàðñåð
void Error(const char*,const char*); // Îò÷¸ò îá îøèáêå
//PT Derivate(PT);
public:
Parser(); // default ctor
Parser(const XS&); // parsing ctor
~Parser(); // dtor
double operator ()(double); // Âû÷èñëåíèå
double operator ()(); // Âû÷èñëåíèå áåç ïåðåìåííîé
bool operator ()(const XS&); // Ïàðñèíã
XS GetLastError(); // Ïðîñìîòð ïîñëåäíåé îøèáêè
};
#endif