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