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