-
Notifications
You must be signed in to change notification settings - Fork 1
/
stmt.h
167 lines (144 loc) · 2.66 KB
/
stmt.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
#ifndef STMT_H
#define STMT_H
#include "expr.h"
typedef enum{
STATEMENT_SET,
STATEMENT_ARRAY,
STATEMENT_INPUT,
STATEMENT_IF,
STATEMENT_WHILE,
STATEMENT_BREAK,
STATEMENT_PRINT,
// STATEMENT_DO,
STATEMENT_BEGIN,
STATEMENT_ROUTINE,
STATEMENT_CALL,
STATEMENT_RETURN,
STATEMENT_CONTAINER,
STATEMENT_NOOP,
STATEMENT_END
} StatementType;
typedef struct Statement Statement;
typedef enum{
BLOCK_IF,
BLOCK_ELSE,
BLOCK_WHILE,
BLOCK_DO,
BLOCK_FOR,
BLOCK_NONE,
BLOCK_FUNC,
BLOCK_MAIN
} BlockType;
typedef struct{
int numStatements;
BlockType blockName;
Statement* statements;
} Block;
typedef struct{
Token pos;
} Break;
/*typedef struct{
Expression* expression;
} ExpressionStatement;
*/
// Function
typedef struct{
int line;
Expression* condition;
Block thenBranch;
Block elseBranch;
} If;
typedef struct{
int line;
int argCount;
Expression** expressions;
} Print;
typedef struct{
Expression *identifer;
Expression *initializerExpression;
} Initializer;
typedef struct{
int line;
int count;
Initializer *initializers;
} Set;
typedef struct{
int line;
Expression* condition;
Block body;
} While;
typedef struct{
int line;
int count;
Expression** initializers;
} ArrayInit;
typedef enum{
INPUT_ANY,
INPUT_INT,
INPUT_FLOAT
} InputDataType;
typedef enum{
INPUT_PROMPT,
INPUT_IDENTIFER
} InputType;
typedef struct{
InputType type;
union{
char *prompt;
struct{
InputDataType datatype;
char *identifer;
};
};
} Input;
typedef struct{
int line;
int count;
Input *inputs;
} InputStatement;
typedef struct{
int line;
char *name;
int arity;
char **arguments;
short isNative;
Block code;
} Routine;
typedef struct{
int line;
char *name;
int arity;
char **arguments;
Block constructor;
} Container;
typedef struct{
int line;
Expression *callee;
} CallStatement;
typedef struct{
int line;
Expression *value;
} ReturnStatement;
struct Statement{
StatementType type;
union{
Block blockStatement;
Break breakStatement;
// ExpressionStatement expressionStatement;
If ifStatement;
Print printStatement;
Set setStatement;
ArrayInit arrayStatement;
InputStatement inputStatement;
While whileStatement;
Routine routine;
Container container;
CallStatement callStatement;
ReturnStatement returnStatement;
};
};
typedef struct{
int count;
Statement *parts;
} Code;
#endif