-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathkeySelagi.h
268 lines (191 loc) · 6.75 KB
/
keySelagi.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
// Bahasa Anak Indonesia untuk Komputer - BAIK
// Copyright Haris Hasanudin - 2005 - 2011
//
// Kupersembahkan untuk istriku tercinta Masako, anakku tersayang Takumi
// dan Tomoki serta seluruh putra putri Indonesia
void keySelagi ()
{
int i = 0, j = 0, k = 0;
int num_depth = 0; // for Selagi inside Selagi
int num_depth2 = 0; // for Selagi inside Selagi
int num_depth3 = 0; // for Selagi inside Selagi
VAL_LABEL valdat;
memset(&valdat, '\0', sizeof(valdat));
while_flag++;
// printf("before while_flag : %d \n", while_flag);
if(while_flag > MAX_LOOP_LEN) {
Error("Terlalu banyak pengulangan SELAGI");
}
posWhile[while_flag] = pg.pt;
backWhile[while_flag] = pg.back_pt;
i = 0;
do {
getlex();
i++;
} while (lex.type != _LAKUKAN);
whileLakuPos[while_flag] = pg.pt-1;
/* printf("lakupos %d\n", lakupos); */
pg.pt = posWhile[while_flag] ;
pg.back_pt = backWhile[while_flag];
/* Keep condition statement */
i=0;
pg.pt++;
do {
whileConditSource[while_flag][i] = pg.source[pg.pt++];
i++;
// printf("pg.pt %d char %c \n", pg.pt, pg.source[pg.pt]);
} while(pg.pt != whileLakuPos[while_flag]);
whileConditSource[while_flag][i-6] = '\0';
// printf("%d condit %s\n", while_flag, whileConditSource[while_flag]);
pg.pt = posWhile[while_flag];
pg.back_pt = backWhile[while_flag];
do{
getlex();
}while( lex.type != _LAKUKAN && lex.type != _EOF );
if( lex.type == _EOF )
Error("SELAGI tanpa LAKUKAN");
/* Keep Start Point to do WHILE loop */
posWhileStart[while_flag] = pg.pt;
backWhileStart[while_flag] = pg.back_pt;
// Please take care if there is(are) Selagi inside Selagi
do{
getlex();
// Check Selagi inside Selagi
if(lex.type == _SELAGI) {
num_depth++;
}
}while( lex.type != _BALIKLAGI && lex.type != _EOF );
if( lex.type == _EOF )
Error("SELAGI tanpa BALIKLAGI");
if(num_depth > 0) {
// there is(are) Selagi inside Selagi
for(j=0; j < num_depth; j++) {
do{
getlex();
// Check Selagi inside Selagi
if(lex.type == _SELAGI) {
num_depth2++;
}
}while( lex.type != _BALIKLAGI && lex.type != _EOF );
if( lex.type == _EOF )
Error("SELAGI tanpa BALIKLAGI");
if(num_depth2 > 0) {
// there is(are) Selagi inside Selagi
for(k=0; k < num_depth2; k++) {
do {
getlex();
// Check Selagi inside Selagi
if(lex.type == _SELAGI) {
num_depth3++;
}
} while( lex.type != _BALIKLAGI && lex.type != _EOF );
if( lex.type == _EOF )
Error("SELAGI tanpa BALIKLAGI");
if(num_depth3 > 0) {
// there is(are) Selagi inside Selagi
for(k=0; k < num_depth2; k++) {
do {
getlex();
} while( lex.type != _BALIKLAGI && lex.type != _EOF );
if( lex.type == _EOF )
Error("SELAGI tanpa BALIKLAGI");
}
}
}
}
}
}
/* Keep End Point of WHILE loop */
posWhileTemp[while_flag] = pg.pt;
backWhileTemp[while_flag] = pg.back_pt;
whileExecDone[while_flag] = 1; /* execute */
while( interpretWhileCondition(whileConditSource[while_flag],
posWhile[while_flag],
backWhile[while_flag]) &&
whileExecDone[while_flag]
) {
pg.pt = posWhileStart[while_flag];
pg.back_pt = backWhileStart[while_flag];
InterpreterWhileIncr(posWhileTemp[while_flag]);
pg.pt = posWhileTemp[while_flag];
pg.back_pt = backWhileTemp[while_flag];
// printf("after while 1 : %d -> %d\n", while_flag, whileExecDone[while_flag]);
}
pg.pt = posWhileTemp[while_flag];
pg.back_pt = backWhileTemp[while_flag];
whileExecDone[while_flag] = 0; /* done */
while_flag--;
// printf("after while 2 : %d -> %d\n", while_flag, whileExecDone[while_flag]);
if(currentClass != NULL && strlen(currentClass) > 0) {
// skip - do nothing
} else {
// go to the end of selagi
}
}
int interpretWhileCondition(char *src, int tmp_pt, int back_pt) {
VAL_LABEL valdat;
char *source;
char ident[MAX_IDENT_LEN];
int isSubstitut = 0;
int keep_pos = 0;
int back_pos = 0;
source = NULL;
source = src;
// printf("inside interpretForCondition\n");
/* valdat init */
memset(&valdat, '\0', sizeof(valdat));
valdat.val = 0;
memset(&ident, '\0', sizeof(ident));
memset(&valdat.str, '\0', sizeof(valdat.str));
tmp_source = pg.source;
pg.pt = 0;
pg.back_pt = 0;
pg.source = source;
//printf("inside source %s\n", pg.source);
/* throw out ';' or '(' symbol */
getlex();
/* skip if nothing */
getlex();
if(strncmp(lex.detail.string , ")", 1) == 0)
return (int)NULL;
if(strncmp(lex.detail.string , ";", 1) == 0)
return (int)NULL;
keep_pos = pg.pt;
back_pos = pg.back_pt;
if(lex.type == TYPE_IDENT) {
// printf("inside Condit ident %s\n", lex.detail.ident);
strcpy(ident, lex.detail.ident);
getlex();
if(strncmp(lex.detail.string , "=", 1) == 0) { // is equal
getlex();
if(strncmp(lex.detail.string , "=", 1) != 0) { // is not an equal
isSubstitut = 1;
}
//printf("substitut in selagi\n");
}
pg.pt = keep_pos;
pg.back_pt = back_pos;
}
ungetlex();
valdat = expression();
pg.source = tmp_source;
pg.pt = tmp_pt;
pg.back_pt = back_pt;
src = NULL;
//printf("inside result %d\n", valdat.val);
//printf("inside result ident %s\n", valdat.ident);
//printf("inside result str %s\n", valdat.str);
if(isSubstitut) {
// save ident value
ValLabel( ident, sub_deep, valdat, VAL_FLAG_SEARCH_W );
}
return valdat.val;
}
void InterpreterWhileIncr( int endPos )
{
/* Do as For - Function Program */
/* printf("inside interpret : %d \n", loop_flag);*/
do{
Interpreter();
}while( pg.pt <= endPos && lex.type != _BALIKLAGI && lex.type != _EOF );
}