Mercurial > ~dholland > hg > ag > index.cgi
comparison tests/agcl/parsifal/good/iaptest.c @ 0:13d2b8934445
Import AnaGram (near-)release tree into Mercurial.
author | David A. Holland |
---|---|
date | Sat, 22 Dec 2007 17:52:45 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:13d2b8934445 |
---|---|
1 | |
2 /* | |
3 * AnaGram, A System for Syntax Directed Programming | |
4 * File generated by: ... | |
5 * | |
6 * AnaGram Parsing Engine | |
7 * Copyright 1993-2002 Parsifal Software. All Rights Reserved. | |
8 * | |
9 * This software is provided 'as-is', without any express or implied | |
10 * warranty. In no event will the authors be held liable for any damages | |
11 * arising from the use of this software. | |
12 * | |
13 * Permission is granted to anyone to use this software for any purpose, | |
14 * including commercial applications, and to alter it and redistribute it | |
15 * freely, subject to the following restrictions: | |
16 * | |
17 * 1. The origin of this software must not be misrepresented; you must not | |
18 * claim that you wrote the original software. If you use this software | |
19 * in a product, an acknowledgment in the product documentation would be | |
20 * appreciated but is not required. | |
21 * 2. Altered source versions must be plainly marked as such, and must not be | |
22 * misrepresented as being the original software. | |
23 * 3. This notice may not be removed or altered from any source distribution. | |
24 */ | |
25 | |
26 #ifndef IAPTEST_H | |
27 #include "iaptest.h" | |
28 #endif | |
29 | |
30 #ifndef IAPTEST_H | |
31 #error Mismatched header file | |
32 #endif | |
33 | |
34 #include <ctype.h> | |
35 #include <stdio.h> | |
36 | |
37 #define RULE_CONTEXT (&((PCB).cs[(PCB).ssx])) | |
38 #define ERROR_CONTEXT ((PCB).cs[(PCB).error_frame_ssx]) | |
39 #define CONTEXT ((PCB).cs[(PCB).ssx]) | |
40 | |
41 | |
42 | |
43 iaptest_pcb_type iaptest_pcb; | |
44 #define PCB iaptest_pcb | |
45 | |
46 #ifndef CONVERT_CASE | |
47 #define CONVERT_CASE(c) (c) | |
48 #endif | |
49 #ifndef TAB_SPACING | |
50 #define TAB_SPACING 8 | |
51 #endif | |
52 | |
53 #define ag_rp_1(d) (printf("%d\n", d)) | |
54 | |
55 #define ag_rp_2(d, i) (10*d + 1) | |
56 | |
57 #define ag_rp_3(d) (printf("%d\n", d)) | |
58 | |
59 | |
60 #define READ_COUNTS | |
61 #define WRITE_COUNTS | |
62 #undef V | |
63 #define V(i,t) (*t (&(PCB).vs[(PCB).ssx + i])) | |
64 #undef VS | |
65 #define VS(i) (PCB).vs[(PCB).ssx + i] | |
66 | |
67 #ifndef GET_CONTEXT | |
68 #define GET_CONTEXT CONTEXT = (PCB).input_context | |
69 #endif | |
70 | |
71 typedef enum { | |
72 ag_action_1, | |
73 ag_action_2, | |
74 ag_action_3, | |
75 ag_action_4, | |
76 ag_action_5, | |
77 ag_action_6, | |
78 ag_action_7, | |
79 ag_action_8, | |
80 ag_action_9, | |
81 ag_action_10, | |
82 ag_action_11, | |
83 ag_action_12 | |
84 } ag_parser_action; | |
85 | |
86 | |
87 #ifndef NULL_VALUE_INITIALIZER | |
88 #define NULL_VALUE_INITIALIZER = 0 | |
89 #endif | |
90 | |
91 static int const ag_null_value NULL_VALUE_INITIALIZER; | |
92 | |
93 static const unsigned char ag_rpx[] = { | |
94 0, 1, 2, 3 | |
95 }; | |
96 #define AG_TCV(x) (((int)(x) >= 0 && (int)(x) <= 255) ? ag_tcv[(x)] : 0) | |
97 | |
98 static const unsigned char ag_tcv[] = { | |
99 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
100 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
101 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, | |
102 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
103 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
104 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, | |
105 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
106 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
107 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
108 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
109 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
110 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
111 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
112 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
113 0, 0, 0, 0 | |
114 }; | |
115 | |
116 #ifndef SYNTAX_ERROR | |
117 #define SYNTAX_ERROR fprintf(stderr,"%s, line %d, column %d\n", \ | |
118 (PCB).error_message, (PCB).line, (PCB).column) | |
119 #endif | |
120 | |
121 #ifndef FIRST_LINE | |
122 #define FIRST_LINE 1 | |
123 #endif | |
124 | |
125 #ifndef FIRST_COLUMN | |
126 #define FIRST_COLUMN 1 | |
127 #endif | |
128 | |
129 #ifndef PARSER_STACK_OVERFLOW | |
130 #define PARSER_STACK_OVERFLOW {fprintf(stderr, \ | |
131 "\nParser stack overflow, line %d, column %d\n",\ | |
132 (PCB).line, (PCB).column);} | |
133 #endif | |
134 | |
135 #ifndef REDUCTION_TOKEN_ERROR | |
136 #define REDUCTION_TOKEN_ERROR {fprintf(stderr, \ | |
137 "\nReduction token error, line %d, column %d\n", \ | |
138 (PCB).line, (PCB).column);} | |
139 #endif | |
140 | |
141 | |
142 #ifndef GET_INPUT | |
143 #define GET_INPUT ((PCB).input_code = getchar()) | |
144 #endif | |
145 | |
146 | |
147 #ifndef AG_NEWLINE | |
148 #define AG_NEWLINE 10 | |
149 #endif | |
150 | |
151 #ifndef AG_RETURN | |
152 #define AG_RETURN 13 | |
153 #endif | |
154 | |
155 #ifndef AG_FORMFEED | |
156 #define AG_FORMFEED 12 | |
157 #endif | |
158 | |
159 #ifndef AG_TABCHAR | |
160 #define AG_TABCHAR 9 | |
161 #endif | |
162 | |
163 static void ag_track(void) { | |
164 switch ((PCB).input_code) { | |
165 case AG_NEWLINE: | |
166 (PCB).column = 1, (PCB).line++; | |
167 case AG_RETURN: | |
168 case AG_FORMFEED: | |
169 break; | |
170 case AG_TABCHAR: | |
171 (PCB).column += (TAB_SPACING) - ((PCB).column - 1) % (TAB_SPACING); | |
172 break; | |
173 default: | |
174 (PCB).column++; | |
175 } | |
176 (PCB).read_flag = 1; | |
177 } | |
178 | |
179 | |
180 static void ag_prot(void) { | |
181 int ag_k; | |
182 ag_k = 128 - ++(PCB).btsx; | |
183 if (ag_k <= (PCB).ssx) { | |
184 (PCB).exit_flag = AG_STACK_ERROR_CODE; | |
185 PARSER_STACK_OVERFLOW; | |
186 return; | |
187 } | |
188 (PCB).bts[(PCB).btsx] = (PCB).sn; | |
189 (PCB).bts[ag_k] = (PCB).ssx; | |
190 (PCB).vs[ag_k] = (PCB).vs[(PCB).ssx]; | |
191 (PCB).ss[ag_k] = (PCB).ss[(PCB).ssx]; | |
192 } | |
193 | |
194 static void ag_undo(void) { | |
195 if ((PCB).drt == -1) return; | |
196 while ((PCB).btsx) { | |
197 int ag_k = 128 - (PCB).btsx; | |
198 (PCB).sn = (PCB).bts[(PCB).btsx--]; | |
199 (PCB).ssx = (PCB).bts[ag_k]; | |
200 (PCB).vs[(PCB).ssx] = (PCB).vs[ag_k]; | |
201 (PCB).ss[(PCB).ssx] = (PCB).ss[ag_k]; | |
202 } | |
203 (PCB).token_number = (iaptest_token_type) (PCB).drt; | |
204 (PCB).ssx = (PCB).dssx; | |
205 (PCB).sn = (PCB).dsn; | |
206 (PCB).drt = -1; | |
207 } | |
208 | |
209 | |
210 static const unsigned char ag_tstt[] = { | |
211 4,2,0,1, | |
212 2,0,5, | |
213 2,0,3, | |
214 2,0, | |
215 2,0, | |
216 | |
217 }; | |
218 | |
219 | |
220 static unsigned const char ag_astt[14] = { | |
221 1,1,7,0,4,7,1,4,7,1,3,7,2,7 | |
222 }; | |
223 | |
224 | |
225 static const unsigned char ag_pstt[] = { | |
226 1,2,0,0, | |
227 3,1,3, | |
228 1,2,4, | |
229 4,3, | |
230 2,4, | |
231 | |
232 }; | |
233 | |
234 | |
235 static const unsigned char ag_sbt[] = { | |
236 0, 4, 7, 10, 12, 14 | |
237 }; | |
238 | |
239 | |
240 static const unsigned char ag_sbe[] = { | |
241 2, 5, 8, 11, 13, 14 | |
242 }; | |
243 | |
244 | |
245 static const unsigned char ag_fl[] = { | |
246 1,0,3,0,3 | |
247 }; | |
248 | |
249 static const unsigned char ag_ptt[] = { | |
250 0, 3, 1, 5, 1 | |
251 }; | |
252 | |
253 | |
254 static void ag_ra(void) | |
255 { | |
256 switch(ag_rpx[(PCB).ag_ap]) { | |
257 case 1: ag_rp_1(VS(-1)); break; | |
258 case 2: ag_rp_2(VS(0), VS(2)); break; | |
259 case 3: ag_rp_3(VS(-1)); break; | |
260 } | |
261 } | |
262 | |
263 #define TOKEN_NAMES iaptest_token_names | |
264 const char *const iaptest_token_names[6] = { | |
265 "grammar", | |
266 "grammar", | |
267 "", | |
268 "", | |
269 "", | |
270 "", | |
271 | |
272 }; | |
273 | |
274 #ifndef MISSING_FORMAT | |
275 #define MISSING_FORMAT "Missing %s" | |
276 #endif | |
277 #ifndef UNEXPECTED_FORMAT | |
278 #define UNEXPECTED_FORMAT "Unexpected %s" | |
279 #endif | |
280 #ifndef UNNAMED_TOKEN | |
281 #define UNNAMED_TOKEN "input" | |
282 #endif | |
283 | |
284 | |
285 static void ag_diagnose(void) { | |
286 int ag_snd = (PCB).sn; | |
287 int ag_k = ag_sbt[ag_snd]; | |
288 | |
289 if (*TOKEN_NAMES[ag_tstt[ag_k]] && ag_astt[ag_k + 1] == ag_action_8) { | |
290 sprintf((PCB).ag_msg, MISSING_FORMAT, TOKEN_NAMES[ag_tstt[ag_k]]); | |
291 } | |
292 else if (ag_astt[ag_sbe[(PCB).sn]] == ag_action_8 | |
293 && (ag_k = (int) ag_sbe[(PCB).sn] + 1) == (int) ag_sbt[(PCB).sn+1] - 1 | |
294 && *TOKEN_NAMES[ag_tstt[ag_k]]) { | |
295 sprintf((PCB).ag_msg, MISSING_FORMAT, TOKEN_NAMES[ag_tstt[ag_k]]); | |
296 } | |
297 else if ((PCB).token_number && *TOKEN_NAMES[(PCB).token_number]) { | |
298 sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, TOKEN_NAMES[(PCB).token_number]); | |
299 } | |
300 else if (isprint(((PCB).input_code)) && ((PCB).input_code) != '\\') { | |
301 char buf[20]; | |
302 sprintf(buf, "\'%c\'", (char) ((PCB).input_code)); | |
303 sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, buf); | |
304 } | |
305 else sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, UNNAMED_TOKEN); | |
306 (PCB).error_message = (PCB).ag_msg; | |
307 | |
308 | |
309 } | |
310 static int ag_action_1_r_proc(void); | |
311 static int ag_action_2_r_proc(void); | |
312 static int ag_action_3_r_proc(void); | |
313 static int ag_action_4_r_proc(void); | |
314 static int ag_action_1_s_proc(void); | |
315 static int ag_action_3_s_proc(void); | |
316 static int ag_action_1_proc(void); | |
317 static int ag_action_2_proc(void); | |
318 static int ag_action_3_proc(void); | |
319 static int ag_action_4_proc(void); | |
320 static int ag_action_5_proc(void); | |
321 static int ag_action_6_proc(void); | |
322 static int ag_action_7_proc(void); | |
323 static int ag_action_8_proc(void); | |
324 static int ag_action_9_proc(void); | |
325 static int ag_action_10_proc(void); | |
326 static int ag_action_11_proc(void); | |
327 static int ag_action_8_proc(void); | |
328 | |
329 | |
330 static int (*const ag_r_procs_scan[])(void) = { | |
331 ag_action_1_r_proc, | |
332 ag_action_2_r_proc, | |
333 ag_action_3_r_proc, | |
334 ag_action_4_r_proc | |
335 }; | |
336 | |
337 static int (*const ag_s_procs_scan[])(void) = { | |
338 ag_action_1_s_proc, | |
339 ag_action_2_r_proc, | |
340 ag_action_3_s_proc, | |
341 ag_action_4_r_proc | |
342 }; | |
343 | |
344 static int (*const ag_gt_procs_scan[])(void) = { | |
345 ag_action_1_proc, | |
346 ag_action_2_proc, | |
347 ag_action_3_proc, | |
348 ag_action_4_proc, | |
349 ag_action_5_proc, | |
350 ag_action_6_proc, | |
351 ag_action_7_proc, | |
352 ag_action_8_proc, | |
353 ag_action_9_proc, | |
354 ag_action_10_proc, | |
355 ag_action_11_proc, | |
356 ag_action_8_proc | |
357 }; | |
358 | |
359 | |
360 static int ag_action_10_proc(void) { | |
361 int ag_t = (PCB).token_number; | |
362 (PCB).btsx = 0, (PCB).drt = -1; | |
363 do { | |
364 ag_track(); | |
365 if ((PCB).read_flag) { | |
366 (PCB).read_flag = 0; | |
367 GET_INPUT; | |
368 }; | |
369 (PCB).token_number = (iaptest_token_type) AG_TCV((PCB).input_code); | |
370 } while ((PCB).token_number == (iaptest_token_type) ag_t); | |
371 return 1; | |
372 } | |
373 | |
374 static int ag_action_11_proc(void) { | |
375 int ag_t = (PCB).token_number; | |
376 | |
377 (PCB).btsx = 0, (PCB).drt = -1; | |
378 do { | |
379 (PCB).vs[(PCB).ssx] = (PCB).input_code; | |
380 (PCB).ssx--; | |
381 ag_track(); | |
382 ag_ra(); | |
383 if ((PCB).exit_flag != AG_RUNNING_CODE) return 0; | |
384 (PCB).ssx++; | |
385 if ((PCB).read_flag) { | |
386 (PCB).read_flag = 0; | |
387 GET_INPUT; | |
388 }; | |
389 (PCB).token_number = (iaptest_token_type) AG_TCV((PCB).input_code); | |
390 } | |
391 while ((PCB).token_number == (iaptest_token_type) ag_t); | |
392 return 1; | |
393 } | |
394 | |
395 static int ag_action_3_r_proc(void) { | |
396 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
397 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
398 (PCB).btsx = 0, (PCB).drt = -1; | |
399 (PCB).reduction_token = (iaptest_token_type) ag_ptt[(PCB).ag_ap]; | |
400 ag_ra(); | |
401 return (PCB).exit_flag == AG_RUNNING_CODE; | |
402 } | |
403 | |
404 static int ag_action_3_s_proc(void) { | |
405 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
406 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
407 (PCB).btsx = 0, (PCB).drt = -1; | |
408 (PCB).reduction_token = (iaptest_token_type) ag_ptt[(PCB).ag_ap]; | |
409 ag_ra(); | |
410 return (PCB).exit_flag == AG_RUNNING_CODE; | |
411 } | |
412 | |
413 static int ag_action_4_r_proc(void) { | |
414 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
415 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
416 (PCB).reduction_token = (iaptest_token_type) ag_ptt[(PCB).ag_ap]; | |
417 return 1; | |
418 } | |
419 | |
420 static int ag_action_2_proc(void) { | |
421 (PCB).btsx = 0, (PCB).drt = -1; | |
422 if ((PCB).ssx >= 128) { | |
423 (PCB).exit_flag = AG_STACK_ERROR_CODE; | |
424 PARSER_STACK_OVERFLOW; | |
425 } | |
426 (PCB).vs[(PCB).ssx] = (PCB).input_code; | |
427 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
428 (PCB).ssx++; | |
429 (PCB).sn = (PCB).ag_ap; | |
430 ag_track(); | |
431 return 0; | |
432 } | |
433 | |
434 static int ag_action_9_proc(void) { | |
435 if ((PCB).drt == -1) { | |
436 (PCB).drt=(PCB).token_number; | |
437 (PCB).dssx=(PCB).ssx; | |
438 (PCB).dsn=(PCB).sn; | |
439 } | |
440 ag_prot(); | |
441 (PCB).vs[(PCB).ssx] = ag_null_value; | |
442 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
443 (PCB).ssx++; | |
444 (PCB).sn = (PCB).ag_ap; | |
445 return (PCB).exit_flag == AG_RUNNING_CODE; | |
446 } | |
447 | |
448 static int ag_action_2_r_proc(void) { | |
449 (PCB).ssx++; | |
450 (PCB).sn = (PCB).ag_ap; | |
451 return 0; | |
452 } | |
453 | |
454 static int ag_action_7_proc(void) { | |
455 --(PCB).ssx; | |
456 (PCB).exit_flag = AG_SUCCESS_CODE; | |
457 return 0; | |
458 } | |
459 | |
460 static int ag_action_1_proc(void) { | |
461 ag_track(); | |
462 (PCB).exit_flag = AG_SUCCESS_CODE; | |
463 return 0; | |
464 } | |
465 | |
466 static int ag_action_1_r_proc(void) { | |
467 (PCB).exit_flag = AG_SUCCESS_CODE; | |
468 return 0; | |
469 } | |
470 | |
471 static int ag_action_1_s_proc(void) { | |
472 (PCB).exit_flag = AG_SUCCESS_CODE; | |
473 return 0; | |
474 } | |
475 | |
476 static int ag_action_4_proc(void) { | |
477 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
478 (PCB).reduction_token = (iaptest_token_type) ag_ptt[(PCB).ag_ap]; | |
479 (PCB).btsx = 0, (PCB).drt = -1; | |
480 (PCB).vs[(PCB).ssx] = (PCB).input_code; | |
481 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
482 else (PCB).ss[(PCB).ssx] = (PCB).sn; | |
483 ag_track(); | |
484 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
485 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
486 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
487 do { | |
488 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
489 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
490 else ag_t2 = ag_tx; | |
491 } while (ag_t1 < ag_t2); | |
492 (PCB).ag_ap = ag_pstt[ag_t1]; | |
493 if ((ag_s_procs_scan[ag_astt[ag_t1]])() == 0) break; | |
494 } | |
495 return 0; | |
496 } | |
497 | |
498 static int ag_action_3_proc(void) { | |
499 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
500 (PCB).btsx = 0, (PCB).drt = -1; | |
501 (PCB).vs[(PCB).ssx] = (PCB).input_code; | |
502 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
503 else (PCB).ss[(PCB).ssx] = (PCB).sn; | |
504 ag_track(); | |
505 (PCB).reduction_token = (iaptest_token_type) ag_ptt[(PCB).ag_ap]; | |
506 ag_ra(); | |
507 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
508 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
509 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
510 do { | |
511 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
512 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
513 else ag_t2 = ag_tx; | |
514 } while (ag_t1 < ag_t2); | |
515 (PCB).ag_ap = ag_pstt[ag_t1]; | |
516 if ((ag_s_procs_scan[ag_astt[ag_t1]])() == 0) break; | |
517 } | |
518 return 0; | |
519 } | |
520 | |
521 static int ag_action_8_proc(void) { | |
522 ag_undo(); | |
523 (PCB).exit_flag = AG_SYNTAX_ERROR_CODE; | |
524 ag_diagnose(); | |
525 SYNTAX_ERROR; | |
526 ag_track(); | |
527 return (PCB).exit_flag == AG_RUNNING_CODE; | |
528 } | |
529 | |
530 static int ag_action_5_proc(void) { | |
531 int ag_sd = ag_fl[(PCB).ag_ap]; | |
532 (PCB).btsx = 0, (PCB).drt = -1; | |
533 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
534 else { | |
535 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
536 } | |
537 (PCB).reduction_token = (iaptest_token_type) ag_ptt[(PCB).ag_ap]; | |
538 ag_ra(); | |
539 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
540 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
541 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
542 do { | |
543 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
544 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
545 else ag_t2 = ag_tx; | |
546 } while (ag_t1 < ag_t2); | |
547 (PCB).ag_ap = ag_pstt[ag_t1]; | |
548 if ((ag_r_procs_scan[ag_astt[ag_t1]])() == 0) break; | |
549 } | |
550 return (PCB).exit_flag == AG_RUNNING_CODE; | |
551 } | |
552 | |
553 static int ag_action_6_proc(void) { | |
554 int ag_sd = ag_fl[(PCB).ag_ap]; | |
555 (PCB).reduction_token = (iaptest_token_type) ag_ptt[(PCB).ag_ap]; | |
556 if ((PCB).drt == -1) { | |
557 (PCB).drt=(PCB).token_number; | |
558 (PCB).dssx=(PCB).ssx; | |
559 (PCB).dsn=(PCB).sn; | |
560 } | |
561 if (ag_sd) { | |
562 (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
563 } | |
564 else { | |
565 ag_prot(); | |
566 (PCB).vs[(PCB).ssx] = ag_null_value; | |
567 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
568 } | |
569 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
570 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
571 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
572 do { | |
573 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
574 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
575 else ag_t2 = ag_tx; | |
576 } while (ag_t1 < ag_t2); | |
577 (PCB).ag_ap = ag_pstt[ag_t1]; | |
578 if ((ag_r_procs_scan[ag_astt[ag_t1]])() == 0) break; | |
579 } | |
580 return (PCB).exit_flag == AG_RUNNING_CODE; | |
581 } | |
582 | |
583 | |
584 void init_iaptest(void) { | |
585 (PCB).read_flag = 1; | |
586 (PCB).ss[0] = (PCB).sn = (PCB).ssx = 0; | |
587 (PCB).exit_flag = AG_RUNNING_CODE; | |
588 (PCB).line = FIRST_LINE; | |
589 (PCB).column = FIRST_COLUMN; | |
590 (PCB).btsx = 0, (PCB).drt = -1; | |
591 } | |
592 | |
593 void iaptest(void) { | |
594 init_iaptest(); | |
595 (PCB).exit_flag = AG_RUNNING_CODE; | |
596 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
597 unsigned ag_t1 = ag_sbt[(PCB).sn]; | |
598 if (ag_tstt[ag_t1]) { | |
599 unsigned ag_t2 = ag_sbe[(PCB).sn] - 1; | |
600 if ((PCB).read_flag) { | |
601 (PCB).read_flag = 0; | |
602 GET_INPUT; | |
603 }; | |
604 (PCB).token_number = (iaptest_token_type) AG_TCV((PCB).input_code); | |
605 do { | |
606 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
607 if (ag_tstt[ag_tx] > (unsigned char)(PCB).token_number) | |
608 ag_t1 = ag_tx + 1; | |
609 else ag_t2 = ag_tx; | |
610 } while (ag_t1 < ag_t2); | |
611 if (ag_tstt[ag_t1] != (unsigned char)(PCB).token_number) | |
612 ag_t1 = ag_sbe[(PCB).sn]; | |
613 } | |
614 (PCB).ag_ap = ag_pstt[ag_t1]; | |
615 (ag_gt_procs_scan[ag_astt[ag_t1]])(); | |
616 } | |
617 } | |
618 | |
619 | |
620 | |
621 int main(void) { | |
622 iaptest(); | |
623 return 0; | |
624 } |