-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathast.h
63 lines (45 loc) · 815 Bytes
/
ast.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
#ifndef AST_H_
#define AST_H_
#include "./lexer.h"
typedef struct M_Expression M_Expression;
typedef enum {
M_EK_NUMBER = 0,
M_EK_BINARY,
} M_Expression_Kind;
typedef enum {
M_OP_PLUS = 0,
M_OP_TIMES,
M_OP_DIVIDE,
M_OP_SUBTRACT,
M_OP_MOD,
M_OP_POW,
} M_Expression_Operator;
struct M_Expression {
M_Expression_Kind kind;
union {
// when the kind is M_EK_NUMBER
double number;
// when the kind is M_EK_BINARY
struct {
M_Expression_Operator operator;
M_Expression *left;
M_Expression *right;
} binary;
};
};
M_Expression *parse_expression(M_Token **tokens);
#endif // AST_H_
/*
3 + 4 * 2 = 11
+
/ \
3 *
/ \
4 2
(3 + 4) * 2 = 14
*
/ \
+ 2
/ \
3 4
*/