-
Notifications
You must be signed in to change notification settings - Fork 1
/
decl.h
273 lines (215 loc) · 4.31 KB
/
decl.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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
#define NumberValue 1
#define StringValue 2
#define V_value 3
#define V_operator 4
#define V_expression 5
#define V_call 6
#define S_ifthen 6
#define S_goto 7
#define S_input 8
#define S_print 9
#define S_assign 10
#define S_array 11
#define S_for 12
#define S_gosub 13
#define S_return 14
#define S_next 15
#define CTRUE 20
#define CFALSE 21
int statsize = 1;
int trastatpos = 0;
int chpos = 0;
char tknlb [30][20];
int dim = 30;
int currentpos = 0;
int sizeelem = 0;
int savesize[5];
int setinjump = 0;
int fntabidx = 0;
int untilReturn = 0;
#define FN_SIZE 100
#define STAT_MAX 3000
#define STACK_SIZE 200
struct optoken
{
char cop;
int nop;
};
struct CExpression* expression();
struct CExpression* catomic ();
struct CExpression* coperator();
struct CExpression* condexpression();
//Various states token might be in.
enum TokenizeState {
TS_DEFAULT , TS_WORD, TS_NUMBER, TS_STRING, TS_COMMENT};
// Token types
enum TokenType {
TT_WORD = 20, TT_NUMBER, TT_STRING, TT_LABEL, TT_LINE,
TT_EQUAL, TT_OPERATOR, TT_LEFT_PAREN, TT_RIGHT_PAREN,
TT_GREATEROREQUAL, TT_LESSOREQUAL,TT_REQUAL, TT_NOTEQUAL,
TT_GREATER, TT_LESS,
TT_COMMA, TT_TT_EOF};
struct optoken aroptoken[12] = {{'\n', TT_LINE}, {'=', TT_EQUAL},{'+', TT_OPERATOR},{'-', TT_OPERATOR},{'*',TT_OPERATOR},{'/', TT_OPERATOR},{'%', TT_OPERATOR},{',', TT_COMMA},
{'<', TT_OPERATOR},{'>', TT_OPERATOR}, {'(', TT_LEFT_PAREN}, {')', TT_RIGHT_PAREN}};
const int aroptokenlen = 12;
enum Reword {
DIM, FOR, PRINT, DEF, IF, READ, INPUT, NEXT, RETURN, STOP, END, GOTO, GOSUB, THEN, LET, DATA, TO,STEP, REM};
typedef struct Clist
{
char* text;
int type;
struct Clist* next;
}Clist;
typedef struct CStringValue
{
char* value;
}CStringValue;
typedef struct CNumberValue
{
double value;
}CNumberValue;
typedef struct CValue
{
int vtype;
void * value;
}CValue;
typedef struct LExpression
{
struct CExpression* arg;
struct LExpression* next;
} LExpression;
typedef struct FuncCall
{
int argSize;
struct LExpression* LexpList;
char *name;
int tableIndex;
} FuncCall;
struct CExpression
{
int extype;
union
{
struct COperatorExpression* operatorexpression;
struct CVariableExpression* variableexpression;
CValue* valueexpression;
FuncCall* funCall;
};
};
struct COperatorExpression
{
struct CExpression* left;
struct CExpression* right;
int coperator;
};
struct CVariableExpression
{
char* name;
};
typedef struct env
{
char* key;
CValue* vval;
struct env* next;
}env;
typedef struct CPrintStatement
{
struct LExpression* expression;
}CPrintStatement ;
typedef struct CInputStatement
{
char* name;
}CInputStatement;
typedef struct CAssignStatement
{
char* name;
struct CExpression* value;
}CAssignStatement;
typedef struct CGotoStatement
{
char* label;
int nlab;
}CGotoStatement;
typedef struct CGosubStatement
{
int label;
int jumpto;
}CGosubStatement;
typedef struct CNextStatement
{
struct CExpression* var;
}CNextStatement;
typedef struct CReturnStatement
{
char dummy;
}CReturnStatement;
typedef struct CIfThenStatement
{
struct CExpression* condition;
char* label;
}CIfThenStatement;
typedef struct CArrayStatement
{
struct CExpression* exp;
struct CExpression* opt;
char* varname;
}CArrayStatement;
typedef struct CStatement
{
int stype;
void* statement;
struct CStatement* next;
}CStatement;
typedef struct CForStatement
{
struct CExpression* indexpress;
struct CExpression* endex;
CStatement* lforstat;
env* lenv;
int ssize;
char* index;
}CForStatement;
CForStatement* forstat;
typedef struct CSave
{
CStatement* shead;
CStatement* stail;
}CSave;
typedef struct CSFor
{
CForStatement* lcfor;
}CSFor;
typedef struct parList
{
struct CExpression* name;
struct parList* next;
} parList;
typedef struct FuncAbstraction
{
int parSize;
parList* plist;
struct CExpression* body;
char* name;
} FuncAbstraction;
typedef struct Clabels
{
int key;
int cindex;
CStatement* st;
}Clabels;
struct labelList
{
int top;
Clabels* clabs[STAT_MAX];
};
struct labels
{
int stsize;
char* label;
struct labels* next;
};
typedef struct ReturnStack
{
int idx;
int stack[STACK_SIZE];
}ReturnStack;