-
Notifications
You must be signed in to change notification settings - Fork 0
/
header.h
246 lines (230 loc) · 4.3 KB
/
header.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
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#ifndef MINI_HEADER_H
#define MINI_HEADER_H
#include "Libft/libft.h"
// c headers
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdbool.h>
#include <stdarg.h>
#include <math.h>
#include <assert.h>
#include <string.h>
// macros
#define in STDIN_FILENO
#define out STDOUT_FILENO
#define err STDERR_FILENO
#define DEBUG 0
// typedefs
typedef struct Node Node;
typedef struct Token Token;
typedef struct Token Value;
typedef struct List List;
typedef enum Type Type;
// for the stupid implicit declaration error
char *type_to_string(Type type);
Token *evaluate(Node *node);
void visualize_variables(void);
void undeclared_error(char *location, Token *token, char *type);
void see_token(Token *token);
void build_tokens();
Token *new_token(Type type);
long pow_ten(long exponent);
void output(Token *token);
bool check(Type to_find, ...);
void visualize_variables(void);
Node **bloc(); // bloc of code
Node *expr(); // expression
Node *assign(); // = += -= *= /=
Node *conditions(); // while, if, elif, else
Node *logic_or(); // || or
Node *logic_and(); // && and
Node *equality(); // == !=
Node *comparison(); // < > <= >=
Node *add_sub(); // + -
Node *mul_div(); // * /
Node *sign(); // sign -
Node *iteration(); // .len ... [0]
Node *prime(); // primary
Node *parents(); // ()
enum Type
{
zero_,
// like none data type
void_,
// data types
identifier_,
characters_,
boolean_,
number_,
array_,
obj_,
tuple_,
// asssigns
assign_,
add_assign_,
sub_assign_,
mul_assign_,
div_assign_,
mod_assign_,
// statements
while_,
if_,
elif_,
else_,
for_,
in_,
// end statement
dots_,
comma_,
// parents, brackets
lparent_,
rparent_,
lbracket_,
rbracket_,
lcbracket_,
rcbracket_,
// built in functions
output_,
input_,
range_,
// math operator
add_,
sub_,
mul_,
div_,
mod_,
less_than_,
more_than_,
less_than_or_equal_,
more_than_or_equal_,
// logic operator
and_,
or_,
not_,
equal_,
not_equal_,
// functions
func_dec_,
func_call_,
// key words
break_,
continue_,
return_,
// attribute
dot_,
attribute_,
att_type_,
key_iter,
index_iter,
// built in attributes
indexof_,
count_,
split_,
trim_,
base_,
starts_with_,
ends_with_,
// EOF
eof_,
};
struct Token
{
char *name;
Type type;
// positions
int line; // line where the var exists
int column; // column by index
int tab; // by tabs
int txt_pos;
union
{
// number
struct
{
long long number;
int exponent;
// bool is_float;
};
// characters
struct
{
char *characters;
bool is_char;
};
// array
struct
{
Node **array_head;
Token **array;
int array_len;
};
// object
struct
{
Node **object_head;
char **keys;
Token **object;
};
// params value
struct
{
Node **params_head;
Token **params;
int params_len;
};
// block
Node **bloc_head;
// data type value
Type value_type;
// boolean value
bool boolean;
};
};
typedef struct
{
char *name;
Type type;
} Typed_token;
typedef struct
{
char *special;
char replace;
} Special_characters;
struct Node
{
Node *left;
Node *right;
Token *token;
};
struct List
{
int val_index;
Token *variables[5000]; // to be modify after
List *next;
List *prev;
};
// globals
extern Special_characters *special_characters;
extern Typed_token *operators_tokens;
extern Typed_token *alpha_tokens;
extern char *text;
// text
extern char *text;
extern int txt_pos;
// tokens
extern Token **tokens;
extern int tk_len;
extern int tk_pos;
// position in file
extern int line;
extern int column;
extern int tab;
extern int start;
extern int exe_pos;
extern char *tab_space;
extern List *current;
extern Node *FUNCTIONS[5000]; // to be modified after
extern int func_index;
extern int scoop;
#endif