Mercurial > ~dholland > hg > ag > index.cgi
comparison tests/agcl/parsifal/good/tpia1.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 TPIA1_H | |
27 #include "tpia1.h" | |
28 #endif | |
29 | |
30 #ifndef TPIA1_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 tpia1_pcb_type tpia1_pcb; | |
44 #define PCB tpia1_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 static void ag_rp_1(int a, int b) { | |
54 /* Line -, tpia1.syn */ | |
55 printf("%c%c", a, b); | |
56 } | |
57 | |
58 | |
59 #define READ_COUNTS | |
60 #define WRITE_COUNTS | |
61 #undef V | |
62 #define V(i,t) (*t (&(PCB).vs[(PCB).ssx + i])) | |
63 #undef VS | |
64 #define VS(i) (PCB).vs[(PCB).ssx + i] | |
65 | |
66 #ifndef GET_CONTEXT | |
67 #define GET_CONTEXT CONTEXT = (PCB).input_context | |
68 #endif | |
69 | |
70 typedef enum { | |
71 ag_action_1, | |
72 ag_action_2, | |
73 ag_action_3, | |
74 ag_action_4, | |
75 ag_action_5, | |
76 ag_action_6, | |
77 ag_action_7, | |
78 ag_action_8, | |
79 ag_action_9, | |
80 ag_action_10, | |
81 ag_action_11, | |
82 ag_action_12 | |
83 } ag_parser_action; | |
84 | |
85 | |
86 #ifndef NULL_VALUE_INITIALIZER | |
87 #define NULL_VALUE_INITIALIZER = 0 | |
88 #endif | |
89 | |
90 static int const ag_null_value NULL_VALUE_INITIALIZER; | |
91 | |
92 static const unsigned char ag_rpx[] = { | |
93 0, 1 | |
94 }; | |
95 #define AG_TCV(x) (((int)(x) >= -1 && (int)(x) <= 255) ? ag_tcv[(x) + 1] : 0) | |
96 | |
97 static const unsigned char ag_tcv[] = { | |
98 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, | |
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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
103 2, 2, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
104 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 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 | |
113 }; | |
114 | |
115 #ifndef SYNTAX_ERROR | |
116 #define SYNTAX_ERROR fprintf(stderr,"%s, line %d, column %d\n", \ | |
117 (PCB).error_message, (PCB).line, (PCB).column) | |
118 #endif | |
119 | |
120 #ifndef FIRST_LINE | |
121 #define FIRST_LINE 1 | |
122 #endif | |
123 | |
124 #ifndef FIRST_COLUMN | |
125 #define FIRST_COLUMN 1 | |
126 #endif | |
127 | |
128 #ifndef PARSER_STACK_OVERFLOW | |
129 #define PARSER_STACK_OVERFLOW {fprintf(stderr, \ | |
130 "\nParser stack overflow, line %d, column %d\n",\ | |
131 (PCB).line, (PCB).column);} | |
132 #endif | |
133 | |
134 #ifndef REDUCTION_TOKEN_ERROR | |
135 #define REDUCTION_TOKEN_ERROR {fprintf(stderr, \ | |
136 "\nReduction token error, line %d, column %d\n", \ | |
137 (PCB).line, (PCB).column);} | |
138 #endif | |
139 | |
140 | |
141 #ifndef GET_INPUT | |
142 #define GET_INPUT ((PCB).input_code = getchar()) | |
143 #endif | |
144 | |
145 | |
146 #ifndef AG_NEWLINE | |
147 #define AG_NEWLINE 10 | |
148 #endif | |
149 | |
150 #ifndef AG_RETURN | |
151 #define AG_RETURN 13 | |
152 #endif | |
153 | |
154 #ifndef AG_FORMFEED | |
155 #define AG_FORMFEED 12 | |
156 #endif | |
157 | |
158 #ifndef AG_TABCHAR | |
159 #define AG_TABCHAR 9 | |
160 #endif | |
161 | |
162 static void ag_track(void) { | |
163 switch ((PCB).input_code) { | |
164 case AG_NEWLINE: | |
165 (PCB).column = 1, (PCB).line++; | |
166 case AG_RETURN: | |
167 case AG_FORMFEED: | |
168 break; | |
169 case AG_TABCHAR: | |
170 (PCB).column += (TAB_SPACING) - ((PCB).column - 1) % (TAB_SPACING); | |
171 break; | |
172 default: | |
173 (PCB).column++; | |
174 } | |
175 (PCB).read_flag = 1; | |
176 } | |
177 | |
178 | |
179 static void ag_prot(void) { | |
180 int ag_k; | |
181 ag_k = 128 - ++(PCB).btsx; | |
182 if (ag_k <= (PCB).ssx) { | |
183 (PCB).exit_flag = AG_STACK_ERROR_CODE; | |
184 PARSER_STACK_OVERFLOW; | |
185 return; | |
186 } | |
187 (PCB).bts[(PCB).btsx] = (PCB).sn; | |
188 (PCB).bts[ag_k] = (PCB).ssx; | |
189 (PCB).vs[ag_k] = (PCB).vs[(PCB).ssx]; | |
190 (PCB).ss[ag_k] = (PCB).ss[(PCB).ssx]; | |
191 } | |
192 | |
193 static void ag_undo(void) { | |
194 if ((PCB).drt == -1) return; | |
195 while ((PCB).btsx) { | |
196 int ag_k = 128 - (PCB).btsx; | |
197 (PCB).sn = (PCB).bts[(PCB).btsx--]; | |
198 (PCB).ssx = (PCB).bts[ag_k]; | |
199 (PCB).vs[(PCB).ssx] = (PCB).vs[ag_k]; | |
200 (PCB).ss[(PCB).ssx] = (PCB).ss[ag_k]; | |
201 } | |
202 (PCB).token_number = (tpia1_token_type) (PCB).drt; | |
203 (PCB).ssx = (PCB).dssx; | |
204 (PCB).sn = (PCB).dsn; | |
205 (PCB).drt = -1; | |
206 } | |
207 | |
208 | |
209 static const unsigned char ag_tstt[] = { | |
210 8,2,0,1,5,6,7, | |
211 2,0, | |
212 2,0,5, | |
213 8,0, | |
214 4,0,3, | |
215 4,0, | |
216 | |
217 }; | |
218 | |
219 | |
220 static unsigned const char ag_astt[19] = { | |
221 8,1,7,0,1,1,1,1,7,1,5,3,3,7,4,7,1,3,7 | |
222 }; | |
223 | |
224 | |
225 static const unsigned char ag_pstt[] = { | |
226 3,1,0,0,2,2,3, | |
227 4,1, | |
228 1,6,4, | |
229 7,3, | |
230 1,4,5, | |
231 2,5, | |
232 | |
233 }; | |
234 | |
235 | |
236 static const unsigned char ag_sbt[] = { | |
237 0, 7, 9, 12, 14, 17, 19 | |
238 }; | |
239 | |
240 | |
241 static const unsigned char ag_sbe[] = { | |
242 2, 8, 10, 13, 15, 18, 19 | |
243 }; | |
244 | |
245 | |
246 static const unsigned char ag_fl[] = { | |
247 1,0,4,1,2,0,1,2 | |
248 }; | |
249 | |
250 static const unsigned char ag_ptt[] = { | |
251 0, 3, 5, 6, 6, 7, 7, 1 | |
252 }; | |
253 | |
254 | |
255 static void ag_ra(void) | |
256 { | |
257 switch(ag_rpx[(PCB).ag_ap]) { | |
258 case 1: ag_rp_1(VS(-2), VS(-1)); break; | |
259 } | |
260 } | |
261 | |
262 #define TOKEN_NAMES tpia1_token_names | |
263 const char *const tpia1_token_names[9] = { | |
264 "grammar", | |
265 "grammar", | |
266 "letter", | |
267 "", | |
268 "'\\n'", | |
269 "", | |
270 "", | |
271 "", | |
272 "", | |
273 | |
274 }; | |
275 | |
276 #ifndef MISSING_FORMAT | |
277 #define MISSING_FORMAT "Missing %s" | |
278 #endif | |
279 #ifndef UNEXPECTED_FORMAT | |
280 #define UNEXPECTED_FORMAT "Unexpected %s" | |
281 #endif | |
282 #ifndef UNNAMED_TOKEN | |
283 #define UNNAMED_TOKEN "input" | |
284 #endif | |
285 | |
286 | |
287 static void ag_diagnose(void) { | |
288 int ag_snd = (PCB).sn; | |
289 int ag_k = ag_sbt[ag_snd]; | |
290 | |
291 if (*TOKEN_NAMES[ag_tstt[ag_k]] && ag_astt[ag_k + 1] == ag_action_8) { | |
292 sprintf((PCB).ag_msg, MISSING_FORMAT, TOKEN_NAMES[ag_tstt[ag_k]]); | |
293 } | |
294 else if (ag_astt[ag_sbe[(PCB).sn]] == ag_action_8 | |
295 && (ag_k = (int) ag_sbe[(PCB).sn] + 1) == (int) ag_sbt[(PCB).sn+1] - 1 | |
296 && *TOKEN_NAMES[ag_tstt[ag_k]]) { | |
297 sprintf((PCB).ag_msg, MISSING_FORMAT, TOKEN_NAMES[ag_tstt[ag_k]]); | |
298 } | |
299 else if ((PCB).token_number && *TOKEN_NAMES[(PCB).token_number]) { | |
300 sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, TOKEN_NAMES[(PCB).token_number]); | |
301 } | |
302 else if (isprint(((PCB).input_code)) && ((PCB).input_code) != '\\') { | |
303 char buf[20]; | |
304 sprintf(buf, "\'%c\'", (char) ((PCB).input_code)); | |
305 sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, buf); | |
306 } | |
307 else sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, UNNAMED_TOKEN); | |
308 (PCB).error_message = (PCB).ag_msg; | |
309 | |
310 | |
311 } | |
312 static int ag_action_1_r_proc(void); | |
313 static int ag_action_2_r_proc(void); | |
314 static int ag_action_3_r_proc(void); | |
315 static int ag_action_4_r_proc(void); | |
316 static int ag_action_1_s_proc(void); | |
317 static int ag_action_3_s_proc(void); | |
318 static int ag_action_1_proc(void); | |
319 static int ag_action_2_proc(void); | |
320 static int ag_action_3_proc(void); | |
321 static int ag_action_4_proc(void); | |
322 static int ag_action_5_proc(void); | |
323 static int ag_action_6_proc(void); | |
324 static int ag_action_7_proc(void); | |
325 static int ag_action_8_proc(void); | |
326 static int ag_action_9_proc(void); | |
327 static int ag_action_10_proc(void); | |
328 static int ag_action_11_proc(void); | |
329 static int ag_action_8_proc(void); | |
330 | |
331 | |
332 static int (*const ag_r_procs_scan[])(void) = { | |
333 ag_action_1_r_proc, | |
334 ag_action_2_r_proc, | |
335 ag_action_3_r_proc, | |
336 ag_action_4_r_proc | |
337 }; | |
338 | |
339 static int (*const ag_s_procs_scan[])(void) = { | |
340 ag_action_1_s_proc, | |
341 ag_action_2_r_proc, | |
342 ag_action_3_s_proc, | |
343 ag_action_4_r_proc | |
344 }; | |
345 | |
346 static int (*const ag_gt_procs_scan[])(void) = { | |
347 ag_action_1_proc, | |
348 ag_action_2_proc, | |
349 ag_action_3_proc, | |
350 ag_action_4_proc, | |
351 ag_action_5_proc, | |
352 ag_action_6_proc, | |
353 ag_action_7_proc, | |
354 ag_action_8_proc, | |
355 ag_action_9_proc, | |
356 ag_action_10_proc, | |
357 ag_action_11_proc, | |
358 ag_action_8_proc | |
359 }; | |
360 | |
361 | |
362 static int ag_action_10_proc(void) { | |
363 int ag_t = (PCB).token_number; | |
364 (PCB).btsx = 0, (PCB).drt = -1; | |
365 do { | |
366 ag_track(); | |
367 if ((PCB).read_flag) { | |
368 (PCB).read_flag = 0; | |
369 GET_INPUT; | |
370 }; | |
371 (PCB).token_number = (tpia1_token_type) AG_TCV((PCB).input_code); | |
372 } while ((PCB).token_number == (tpia1_token_type) ag_t); | |
373 return 1; | |
374 } | |
375 | |
376 static int ag_action_11_proc(void) { | |
377 int ag_t = (PCB).token_number; | |
378 | |
379 (PCB).btsx = 0, (PCB).drt = -1; | |
380 do { | |
381 (PCB).vs[(PCB).ssx] = (PCB).input_code; | |
382 (PCB).ssx--; | |
383 ag_track(); | |
384 ag_ra(); | |
385 if ((PCB).exit_flag != AG_RUNNING_CODE) return 0; | |
386 (PCB).ssx++; | |
387 if ((PCB).read_flag) { | |
388 (PCB).read_flag = 0; | |
389 GET_INPUT; | |
390 }; | |
391 (PCB).token_number = (tpia1_token_type) AG_TCV((PCB).input_code); | |
392 } | |
393 while ((PCB).token_number == (tpia1_token_type) ag_t); | |
394 return 1; | |
395 } | |
396 | |
397 static int ag_action_3_r_proc(void) { | |
398 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
399 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
400 (PCB).btsx = 0, (PCB).drt = -1; | |
401 (PCB).reduction_token = (tpia1_token_type) ag_ptt[(PCB).ag_ap]; | |
402 ag_ra(); | |
403 return (PCB).exit_flag == AG_RUNNING_CODE; | |
404 } | |
405 | |
406 static int ag_action_3_s_proc(void) { | |
407 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
408 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
409 (PCB).btsx = 0, (PCB).drt = -1; | |
410 (PCB).reduction_token = (tpia1_token_type) ag_ptt[(PCB).ag_ap]; | |
411 ag_ra(); | |
412 return (PCB).exit_flag == AG_RUNNING_CODE; | |
413 } | |
414 | |
415 static int ag_action_4_r_proc(void) { | |
416 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
417 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
418 (PCB).reduction_token = (tpia1_token_type) ag_ptt[(PCB).ag_ap]; | |
419 return 1; | |
420 } | |
421 | |
422 static int ag_action_2_proc(void) { | |
423 (PCB).btsx = 0, (PCB).drt = -1; | |
424 if ((PCB).ssx >= 128) { | |
425 (PCB).exit_flag = AG_STACK_ERROR_CODE; | |
426 PARSER_STACK_OVERFLOW; | |
427 } | |
428 (PCB).vs[(PCB).ssx] = (PCB).input_code; | |
429 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
430 (PCB).ssx++; | |
431 (PCB).sn = (PCB).ag_ap; | |
432 ag_track(); | |
433 return 0; | |
434 } | |
435 | |
436 static int ag_action_9_proc(void) { | |
437 if ((PCB).drt == -1) { | |
438 (PCB).drt=(PCB).token_number; | |
439 (PCB).dssx=(PCB).ssx; | |
440 (PCB).dsn=(PCB).sn; | |
441 } | |
442 ag_prot(); | |
443 (PCB).vs[(PCB).ssx] = ag_null_value; | |
444 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
445 (PCB).ssx++; | |
446 (PCB).sn = (PCB).ag_ap; | |
447 return (PCB).exit_flag == AG_RUNNING_CODE; | |
448 } | |
449 | |
450 static int ag_action_2_r_proc(void) { | |
451 (PCB).ssx++; | |
452 (PCB).sn = (PCB).ag_ap; | |
453 return 0; | |
454 } | |
455 | |
456 static int ag_action_7_proc(void) { | |
457 --(PCB).ssx; | |
458 (PCB).exit_flag = AG_SUCCESS_CODE; | |
459 return 0; | |
460 } | |
461 | |
462 static int ag_action_1_proc(void) { | |
463 ag_track(); | |
464 (PCB).exit_flag = AG_SUCCESS_CODE; | |
465 return 0; | |
466 } | |
467 | |
468 static int ag_action_1_r_proc(void) { | |
469 (PCB).exit_flag = AG_SUCCESS_CODE; | |
470 return 0; | |
471 } | |
472 | |
473 static int ag_action_1_s_proc(void) { | |
474 (PCB).exit_flag = AG_SUCCESS_CODE; | |
475 return 0; | |
476 } | |
477 | |
478 static int ag_action_4_proc(void) { | |
479 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
480 (PCB).reduction_token = (tpia1_token_type) ag_ptt[(PCB).ag_ap]; | |
481 (PCB).btsx = 0, (PCB).drt = -1; | |
482 (PCB).vs[(PCB).ssx] = (PCB).input_code; | |
483 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
484 else (PCB).ss[(PCB).ssx] = (PCB).sn; | |
485 ag_track(); | |
486 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
487 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
488 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
489 do { | |
490 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
491 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
492 else ag_t2 = ag_tx; | |
493 } while (ag_t1 < ag_t2); | |
494 (PCB).ag_ap = ag_pstt[ag_t1]; | |
495 if ((ag_s_procs_scan[ag_astt[ag_t1]])() == 0) break; | |
496 } | |
497 return 0; | |
498 } | |
499 | |
500 static int ag_action_3_proc(void) { | |
501 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
502 (PCB).btsx = 0, (PCB).drt = -1; | |
503 (PCB).vs[(PCB).ssx] = (PCB).input_code; | |
504 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
505 else (PCB).ss[(PCB).ssx] = (PCB).sn; | |
506 ag_track(); | |
507 (PCB).reduction_token = (tpia1_token_type) ag_ptt[(PCB).ag_ap]; | |
508 ag_ra(); | |
509 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
510 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
511 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
512 do { | |
513 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
514 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
515 else ag_t2 = ag_tx; | |
516 } while (ag_t1 < ag_t2); | |
517 (PCB).ag_ap = ag_pstt[ag_t1]; | |
518 if ((ag_s_procs_scan[ag_astt[ag_t1]])() == 0) break; | |
519 } | |
520 return 0; | |
521 } | |
522 | |
523 static int ag_action_8_proc(void) { | |
524 ag_undo(); | |
525 (PCB).exit_flag = AG_SYNTAX_ERROR_CODE; | |
526 ag_diagnose(); | |
527 SYNTAX_ERROR; | |
528 ag_track(); | |
529 return (PCB).exit_flag == AG_RUNNING_CODE; | |
530 } | |
531 | |
532 static int ag_action_5_proc(void) { | |
533 int ag_sd = ag_fl[(PCB).ag_ap]; | |
534 (PCB).btsx = 0, (PCB).drt = -1; | |
535 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
536 else { | |
537 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
538 } | |
539 (PCB).reduction_token = (tpia1_token_type) ag_ptt[(PCB).ag_ap]; | |
540 ag_ra(); | |
541 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
542 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
543 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
544 do { | |
545 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
546 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
547 else ag_t2 = ag_tx; | |
548 } while (ag_t1 < ag_t2); | |
549 (PCB).ag_ap = ag_pstt[ag_t1]; | |
550 if ((ag_r_procs_scan[ag_astt[ag_t1]])() == 0) break; | |
551 } | |
552 return (PCB).exit_flag == AG_RUNNING_CODE; | |
553 } | |
554 | |
555 static int ag_action_6_proc(void) { | |
556 int ag_sd = ag_fl[(PCB).ag_ap]; | |
557 (PCB).reduction_token = (tpia1_token_type) ag_ptt[(PCB).ag_ap]; | |
558 if ((PCB).drt == -1) { | |
559 (PCB).drt=(PCB).token_number; | |
560 (PCB).dssx=(PCB).ssx; | |
561 (PCB).dsn=(PCB).sn; | |
562 } | |
563 if (ag_sd) { | |
564 (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
565 } | |
566 else { | |
567 ag_prot(); | |
568 (PCB).vs[(PCB).ssx] = ag_null_value; | |
569 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
570 } | |
571 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
572 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
573 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
574 do { | |
575 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
576 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
577 else ag_t2 = ag_tx; | |
578 } while (ag_t1 < ag_t2); | |
579 (PCB).ag_ap = ag_pstt[ag_t1]; | |
580 if ((ag_r_procs_scan[ag_astt[ag_t1]])() == 0) break; | |
581 } | |
582 return (PCB).exit_flag == AG_RUNNING_CODE; | |
583 } | |
584 | |
585 | |
586 void init_tpia1(void) { | |
587 (PCB).read_flag = 1; | |
588 (PCB).ss[0] = (PCB).sn = (PCB).ssx = 0; | |
589 (PCB).exit_flag = AG_RUNNING_CODE; | |
590 (PCB).line = FIRST_LINE; | |
591 (PCB).column = FIRST_COLUMN; | |
592 (PCB).btsx = 0, (PCB).drt = -1; | |
593 } | |
594 | |
595 void tpia1(void) { | |
596 init_tpia1(); | |
597 (PCB).exit_flag = AG_RUNNING_CODE; | |
598 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
599 unsigned ag_t1 = ag_sbt[(PCB).sn]; | |
600 if (ag_tstt[ag_t1]) { | |
601 unsigned ag_t2 = ag_sbe[(PCB).sn] - 1; | |
602 if ((PCB).read_flag) { | |
603 (PCB).read_flag = 0; | |
604 GET_INPUT; | |
605 }; | |
606 (PCB).token_number = (tpia1_token_type) AG_TCV((PCB).input_code); | |
607 do { | |
608 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
609 if (ag_tstt[ag_tx] > (unsigned char)(PCB).token_number) | |
610 ag_t1 = ag_tx + 1; | |
611 else ag_t2 = ag_tx; | |
612 } while (ag_t1 < ag_t2); | |
613 if (ag_tstt[ag_t1] != (unsigned char)(PCB).token_number) | |
614 ag_t1 = ag_sbe[(PCB).sn]; | |
615 } | |
616 (PCB).ag_ap = ag_pstt[ag_t1]; | |
617 (ag_gt_procs_scan[ag_astt[ag_t1]])(); | |
618 } | |
619 } | |
620 | |
621 | |
622 | |
623 int main(void) { | |
624 tpia1(); | |
625 return 0; | |
626 } |