-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmathparser.h
More file actions
57 lines (52 loc) · 764 Bytes
/
mathparser.h
File metadata and controls
57 lines (52 loc) · 764 Bytes
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
#pragma once
typedef int bool;
#define true 1
#define false 0
struct StMathTree;
typedef struct StMathTree * MathTree;
struct StMathTree
{
enum type {
NO_TOKEN,
CONST,
VARIABLE,
OPERATION,
FUNCTION,
LBRACKET,
RBRACKET,
} type;
union u {
enum operation {
ADD,
SUB,
MULT,
DIV,
MOD,
POW,
} operation;
enum function {
INT,
SQRT,
ABS,
EXP,
LOG,
SIN,
COS,
TAN,
SINH,
COSH,
TANH,
} function;
double val;
} u;
MathTree c1, c2;
};
enum error {
NO_ERROR,
TOKEN_ERROR,
PARSER_ERROR,
UNBALANCED_BRACKETS,
};
MathTree tokenize(char* s);
MathTree parse(MathTree l);
double evaluate(MathTree t, double x);