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
|
#include <stdint.h>
typedef enum types {
TI32 = 0,
TI64 = 1,
TU32 = 2,
TU64 = 3,
TChar = 4,
Tfloat = 5,
TArr = 6,
TVDef = 7,
} types;
// int types
typedef struct I32 {
int32_t data;
} I32;
typedef struct I64 {
int64_t data;
} I64;
// uint types
typedef struct U32 {
uint32_t data;
} U32;
typedef struct U64 {
uint64_t data;
} U64;
typedef struct Char {
char data;
} Char;
typedef struct Float {
float data;
} Float;
typedef struct Arr {
union literal *arr;
long len;
} Arr;
typedef struct Vdef {
char *id;
types type;
} Vdef;
typedef union literal {
I32 *i32;
I64 *i64;
U32 *u32;
I64 *u64;
Char *ch;
Float *fl;
Arr *arr;
Vdef *vdef;
} literal;
typedef struct var {
literal *value;
types type;
char *id;
} var;
// built in functions
typedef enum builtInFuncs {
// general
DEFUN = 0,
LET = 1,
SET = 2,
IF = 3,
ELIF = 4,
ELSE = 5,
FOR = 6,
WHILE = 7,
SYMBOL = 8,
// arithmetic
ADD = 10,
SUB = 11,
MUL = 12,
DIV = 13,
// comparison
EQ = 14,
NEQ = 15,
GT = 16,
LT = 17,
GTEQ = 18,
LTEQ = 19,
// misc
CAST = 20,
TYPEOF = 21,
EXIT = 22,
RETURN = 23,
WRITE = 24,
NIL = -1,
} builtInFuncs;
// function type
typedef struct functionToken {
int id; // a function id to avoid strings
char *name; // the code for the function
builtInFuncs builtInFunc; // a built in functions
} functionToken;
typedef struct ast_node ast_node;
typedef struct ast_node {
functionToken *func; // if it's not builtin then use this
literal **literalArgs; // the args of the node, this will be an array of literal values
ast_node **args; // the non litteral tokens
// if litteralArgs[x] is real then args[x] should be NULL, and vice versa
} ast_node;
|