aboutsummaryrefslogtreecommitdiff
path: root/include/expr.h
blob: 93b92047cab2efecd582a3753a65abf50999be97 (plain) (blame)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#ifndef CERC_EXPR_H
#define CERC_EXPR_H
#include <stdbool.h>
#include "lex.h"
#include "type.h"

struct grouping_e {
	struct disjunction_e *inner;
};

struct number_e {
	struct number value;
	struct type type;
};

struct array_e {
	struct cer_array meta;
	struct disjunction_e *elems;
	int elemsz, elemlen;
};

enum literal {
	LIT_BOOL,
	LIT_STRING,
	LIT_NUMBER,
	LIT_ARRAY,
};

struct literal_e {
	enum literal kind;
	union {
		bool b;
		const char *str;
		struct number_e num;
		struct array_e arr;
	} lit;
};

struct path {
	const char **segments;
	int segsz, seglen;
};

struct call_e {
	struct path path;
	struct disjunction_e *args;
	int argsz, arglen;
};

enum primary {
	PRM_GROUPING,
	PRM_LITERAL,
	PRM_CALL,
	PRM_PATH,
};

struct primary_e {
	enum primary kind;
	union {
		struct grouping_e grp;
		struct literal_e lit;
		struct call_e call;
		struct path path;
	} prim;
};

enum unary_postfix {
	UPS_DEREF,
	UPS_TRY,
	UPS_ASSERT,
};

struct unarypost_e {
	enum unary_postfix op;
	struct primary_e prim;
};

enum unary_prefix {
	UPR_NUMNEG,
	UPR_BOOLNEG,
	UPR_BITNEG,
};

struct unarypre_e {
	enum unary_prefix op;
	struct unarypost_e post;
};

struct bitfactor_e {
	struct unarypre_e lhs, *rhs;
	int rhssz, rhslen;
};

struct bitsummand_e {
	struct bitfactor_e lhs, *rhs;
	int rhssz, rhslen;
};

struct bin_e {
	struct bitsummand_e lhs, *rhs;
	int rhssz, rhslen;
};

enum factor {
	FCT_MUL,
	FCT_DIV,
	FCT_REM,
};

struct factor_rhs {
	enum factor factor;
	struct bin_e bin;
};

struct factor_e {
	struct bin_e lhs;
	struct factor_rhs *rhs;
	int rhssz, rhslen;
};

enum numeral {
	NUM_ADD,
	NUM_SUB,
};

struct num_rhs {
	enum numeral num;
	struct factor_e factor;
};

struct num_e {
	struct factor_e lhs;
	struct num_rhs *rhs;
	int rhssz, rhslen;
};

enum term {
	TRM_NUM,
	TRM_SHL,
	TRM_SHR,
};

struct term_e {
	enum term term;
	struct num_e lhs, rhs;
};

enum comparison {
	CMP_LT,
	CMP_LE,
	CMP_GT,
	CMP_GE,
};

struct cmp_rhs {
	enum comparison cmp;
	struct term_e term;
};

struct cmp_e {
	struct term_e lhs;
	struct cmp_rhs *rhs;
	int rhssz, rhslen;
};

struct eq_e {
	bool invert;
	struct cmp_e lhs, rhs;
};

enum boolean {
	B_EQ,
	B_CMP,
};

struct bool_e {
	enum boolean kind;
	union {
		struct eq_e eq;
		struct cmp_e cmp;
	} cond;
};

struct conjunction_e {
	// At least one required
	struct bool_e *bools;
	int boolsz, boollen;
};

// Entry point
struct disjunction_e {
	// At least one required
	struct conjunction_e *cons;
	int consz, conlen;
};

#endif