Mercurial > ~dholland > hg > ag > index.cgi
comparison tests/agcl/bugs/good/wraperror.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 * AnaGram, A System for Syntax Directed Programming | |
3 * Copyright 2006 David A. Holland. All Rights Reserved. | |
4 * See the file COPYING for license and usage terms. | |
5 * | |
6 * wraperror: test for wrappers and error token together | |
7 */ | |
8 | |
9 #include <stdio.h> | |
10 | |
11 | |
12 struct thingy { | |
13 const char *name; | |
14 int val; | |
15 | |
16 void g(const char *n, int v) { name = n; val = v; } | |
17 void g(const thingy &t) { name = t.name; val = t.val; } | |
18 | |
19 void m(const char *msg) { | |
20 printf("%s %s: %p, %d\n", msg, name, this, val); | |
21 } | |
22 | |
23 thingy(const char *n, int v) { g(n,v); m("Constructed new"); } | |
24 thingy(const thingy &t) { g(t); m("Copied"); } | |
25 void operator = (const thingy &t) { g(t); m("Assigned"); } | |
26 ~thingy() { m("Destroyed"); } | |
27 }; | |
28 | |
29 struct foo : public thingy { | |
30 foo(int v) : thingy("foo", v) {} | |
31 foo(const foo &f) : thingy(f) {} | |
32 void operator = (const foo &f) { thingy::operator = (f); } | |
33 ~foo() {} | |
34 }; | |
35 | |
36 struct bar : public thingy { | |
37 bar(int v) : thingy("bar", v) {} | |
38 bar(const bar &f) : thingy(f) {} | |
39 void operator = (const bar &f) { thingy::operator = (f); } | |
40 ~bar() {} | |
41 }; | |
42 | |
43 void do_foo(foo &f) { | |
44 f.m("do_foo"); | |
45 } | |
46 | |
47 void do_bar(bar &b) { | |
48 b.m("do_bar"); | |
49 } | |
50 | |
51 | |
52 /* | |
53 * AnaGram, A System for Syntax Directed Programming | |
54 * File generated by: ... | |
55 * | |
56 * AnaGram Parsing Engine | |
57 * Copyright 1993-2002 Parsifal Software. All Rights Reserved. | |
58 * | |
59 * This software is provided 'as-is', without any express or implied | |
60 * warranty. In no event will the authors be held liable for any damages | |
61 * arising from the use of this software. | |
62 * | |
63 * Permission is granted to anyone to use this software for any purpose, | |
64 * including commercial applications, and to alter it and redistribute it | |
65 * freely, subject to the following restrictions: | |
66 * | |
67 * 1. The origin of this software must not be misrepresented; you must not | |
68 * claim that you wrote the original software. If you use this software | |
69 * in a product, an acknowledgment in the product documentation would be | |
70 * appreciated but is not required. | |
71 * 2. Altered source versions must be plainly marked as such, and must not be | |
72 * misrepresented as being the original software. | |
73 * 3. This notice may not be removed or altered from any source distribution. | |
74 */ | |
75 | |
76 #ifndef WRAPERROR_H | |
77 #include "wraperror.h" | |
78 #endif | |
79 | |
80 #ifndef WRAPERROR_H | |
81 #error Mismatched header file | |
82 #endif | |
83 | |
84 #include <ctype.h> | |
85 #include <stdio.h> | |
86 | |
87 #define RULE_CONTEXT (&((PCB).cs[(PCB).ssx])) | |
88 #define ERROR_CONTEXT ((PCB).cs[(PCB).error_frame_ssx]) | |
89 #define CONTEXT ((PCB).cs[(PCB).ssx]) | |
90 | |
91 | |
92 | |
93 wraperror_pcb_type wraperror_pcb; | |
94 #define PCB wraperror_pcb | |
95 static void ag_delete_wrappers(void); | |
96 #ifndef DELETE_WRAPPERS | |
97 #define DELETE_WRAPPERS ag_delete_wrappers() | |
98 #endif | |
99 | |
100 /* Line -, wraperror.syn */ | |
101 int main() { | |
102 wraperror(); | |
103 return 0; | |
104 } | |
105 | |
106 | |
107 #ifndef CONVERT_CASE | |
108 #define CONVERT_CASE(c) (c) | |
109 #endif | |
110 #ifndef TAB_SPACING | |
111 #define TAB_SPACING 8 | |
112 #endif | |
113 | |
114 static inline void ag_rp_1(foo &f) { | |
115 /* Line -, wraperror.syn */ | |
116 do_foo(f); | |
117 } | |
118 | |
119 static inline void ag_rp_2(bar b) { | |
120 /* Line -, wraperror.syn */ | |
121 do_bar(b); | |
122 } | |
123 | |
124 static inline foo ag_rp_3(void) { | |
125 /* Line -, wraperror.syn */ | |
126 return foo(1); | |
127 } | |
128 | |
129 static inline bar ag_rp_4(void) { | |
130 /* Line -, wraperror.syn */ | |
131 return bar(2); | |
132 } | |
133 | |
134 | |
135 #define READ_COUNTS | |
136 #define WRITE_COUNTS | |
137 #undef V | |
138 #define V(i,t) (*t (&(PCB).vs[(PCB).ssx + i])) | |
139 #undef VS | |
140 #define VS(i) (PCB).vs[(PCB).ssx + i] | |
141 | |
142 #ifndef GET_CONTEXT | |
143 #define GET_CONTEXT CONTEXT = (PCB).input_context | |
144 #endif | |
145 | |
146 typedef enum { | |
147 ag_action_1, | |
148 ag_action_2, | |
149 ag_action_3, | |
150 ag_action_4, | |
151 ag_action_5, | |
152 ag_action_6, | |
153 ag_action_7, | |
154 ag_action_8, | |
155 ag_action_9, | |
156 ag_action_10, | |
157 ag_action_11, | |
158 ag_action_12 | |
159 } ag_parser_action; | |
160 | |
161 | |
162 #ifndef NULL_VALUE_INITIALIZER | |
163 #define NULL_VALUE_INITIALIZER = { 0 } | |
164 #endif | |
165 | |
166 | |
167 static const char ag_wdf[] = { | |
168 0, 0, 0, 0, 4, 0, 0, 0, 0 | |
169 }; | |
170 | |
171 #undef VW | |
172 #define VW(i,t) *(t) (&(PCB).vs[(PCB).ssx + (i)]) | |
173 #undef VNO | |
174 #define VNO new(&(PCB).vs[(PCB).ssx]) | |
175 #undef VRO | |
176 #define VRO(to,v) ag_replace_object((to) &(PCB).vs[(PCB).ssx], v) | |
177 #undef VWD | |
178 #define VWD(i,t) ag_delete_object((t) &(PCB).vs[(PCB).ssx + (i)]); | |
179 #undef VDO | |
180 #define VDO(to, v) ag_delete_object((to) &(PCB).vs[(PCB).ssx], v) | |
181 | |
182 template <class NewObject, class OldObject> | |
183 static inline void ag_replace_object(AgObjectWrapper<OldObject> *p, const NewObject &o) { | |
184 delete p; | |
185 new(p) AgObjectWrapper<NewObject >(o); | |
186 } | |
187 | |
188 template <class Object> | |
189 static inline void ag_delete_object(AgObjectWrapper<Object> *p) { | |
190 delete p; | |
191 } | |
192 | |
193 template <class NewObject, class OldObject> | |
194 static inline const NewObject &ag_delete_object(AgObjectWrapper<OldObject> *p, const NewObject &o) { | |
195 delete p; | |
196 return o; | |
197 } | |
198 | |
199 | |
200 #undef AG_WRAP_4 | |
201 #define AG_WRAP_4 AgObjectWrapper<foo > | |
202 | |
203 static void ag_delete_wrappers(void) { | |
204 int sn = (PCB).sn; | |
205 int sx = (PCB).ssx; | |
206 while (sx--) { | |
207 switch (ag_wdf[sn]) { | |
208 case 4: ag_delete_object((AG_WRAP_4 *) &(PCB).vs[sx]); break; | |
209 default: break; | |
210 } | |
211 sn = (PCB).ss[sx]; | |
212 } | |
213 } | |
214 | |
215 void ag_delete_object(void) { | |
216 int sn = PCB.sn; | |
217 (PCB).sn = (PCB).ss[--(PCB).ssx]; | |
218 switch (ag_wdf[sn]) { | |
219 case 4: { | |
220 AG_WRAP_4 *wrapper = (AG_WRAP_4 *) (&(PCB).vs[(PCB).ssx]); | |
221 delete wrapper; | |
222 break; | |
223 } | |
224 default: break; | |
225 } | |
226 } | |
227 | |
228 static wraperror_vs_type const ag_null_value NULL_VALUE_INITIALIZER; | |
229 | |
230 static const unsigned char ag_rpx[] = { | |
231 0, 0, 0, 0, 0, 1, 2, 0, 0, 3, 4 | |
232 }; | |
233 #define AG_TCV(x) (((int)(x) >= 0 && (int)(x) <= 255) ? ag_tcv[(x)] : 0) | |
234 | |
235 static const unsigned char ag_tcv[] = { | |
236 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, | |
237 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
238 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
239 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
240 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
241 0, 0, 0, 0, 0, 0, 0, 13, 12, 0, 0, 0, 10, 0, 0, 0, 0, 0, | |
242 0, 0, 0, 11, 0, 0, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
243 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
244 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
245 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
246 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
247 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
248 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
249 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
250 0, 0, 0, 0 | |
251 }; | |
252 | |
253 #ifndef SYNTAX_ERROR | |
254 #define SYNTAX_ERROR fprintf(stderr,"%s, line %d, column %d\n", \ | |
255 (PCB).error_message, (PCB).line, (PCB).column) | |
256 #endif | |
257 | |
258 #ifndef FIRST_LINE | |
259 #define FIRST_LINE 1 | |
260 #endif | |
261 | |
262 #ifndef FIRST_COLUMN | |
263 #define FIRST_COLUMN 1 | |
264 #endif | |
265 | |
266 #ifndef PARSER_STACK_OVERFLOW | |
267 #define PARSER_STACK_OVERFLOW {fprintf(stderr, \ | |
268 "\nParser stack overflow, line %d, column %d\n",\ | |
269 (PCB).line, (PCB).column);} | |
270 #endif | |
271 | |
272 #ifndef REDUCTION_TOKEN_ERROR | |
273 #define REDUCTION_TOKEN_ERROR {fprintf(stderr, \ | |
274 "\nReduction token error, line %d, column %d\n", \ | |
275 (PCB).line, (PCB).column);} | |
276 #endif | |
277 | |
278 | |
279 #ifndef GET_INPUT | |
280 #define GET_INPUT ((PCB).input_code = getchar()) | |
281 #endif | |
282 | |
283 | |
284 #ifndef AG_NEWLINE | |
285 #define AG_NEWLINE 10 | |
286 #endif | |
287 | |
288 #ifndef AG_RETURN | |
289 #define AG_RETURN 13 | |
290 #endif | |
291 | |
292 #ifndef AG_FORMFEED | |
293 #define AG_FORMFEED 12 | |
294 #endif | |
295 | |
296 #ifndef AG_TABCHAR | |
297 #define AG_TABCHAR 9 | |
298 #endif | |
299 | |
300 static void ag_track(void) { | |
301 switch ((PCB).input_code) { | |
302 case AG_NEWLINE: | |
303 (PCB).column = 1, (PCB).line++; | |
304 case AG_RETURN: | |
305 case AG_FORMFEED: | |
306 break; | |
307 case AG_TABCHAR: | |
308 (PCB).column += (TAB_SPACING) - ((PCB).column - 1) % (TAB_SPACING); | |
309 break; | |
310 default: | |
311 (PCB).column++; | |
312 } | |
313 (PCB).read_flag = 1; | |
314 } | |
315 | |
316 | |
317 static void ag_prot(void) { | |
318 int ag_k; | |
319 ag_k = 128 - ++(PCB).btsx; | |
320 if (ag_k <= (PCB).ssx) { | |
321 (PCB).exit_flag = AG_STACK_ERROR_CODE; | |
322 PARSER_STACK_OVERFLOW; | |
323 return; | |
324 } | |
325 (PCB).bts[(PCB).btsx] = (PCB).sn; | |
326 (PCB).bts[ag_k] = (PCB).ssx; | |
327 (PCB).vs[ag_k] = (PCB).vs[(PCB).ssx]; | |
328 (PCB).ss[ag_k] = (PCB).ss[(PCB).ssx]; | |
329 } | |
330 | |
331 static void ag_undo(void) { | |
332 if ((PCB).drt == -1) return; | |
333 while ((PCB).btsx) { | |
334 int ag_k = 128 - (PCB).btsx; | |
335 (PCB).sn = (PCB).bts[(PCB).btsx--]; | |
336 (PCB).ssx = (PCB).bts[ag_k]; | |
337 (PCB).vs[(PCB).ssx] = (PCB).vs[ag_k]; | |
338 (PCB).ss[(PCB).ssx] = (PCB).ss[ag_k]; | |
339 } | |
340 (PCB).token_number = (wraperror_token_type) (PCB).drt; | |
341 (PCB).ssx = (PCB).dssx; | |
342 (PCB).sn = (PCB).dsn; | |
343 (PCB).drt = -1; | |
344 } | |
345 | |
346 | |
347 static const unsigned char ag_tstt[] = { | |
348 12,10,9,7,0,1,2,4,5,6,8, | |
349 13,0, | |
350 11,0, | |
351 7,0, | |
352 7,0, | |
353 12,10,9,7,3,0,4,6,8, | |
354 3,0, | |
355 14,0, | |
356 11,0, | |
357 | |
358 }; | |
359 | |
360 | |
361 static unsigned const char ag_astt[34] = { | |
362 1,1,1,1,7,0,1,1,1,1,1,1,7,1,7,2,7,2,7,1,1,3,9,5,7,3,1,1,3,7,2,7,2,7 | |
363 }; | |
364 | |
365 | |
366 static const unsigned char ag_pstt[] = { | |
367 1,2,5,5,0,0,6,5,5,4,3, | |
368 7,1, | |
369 8,2, | |
370 6,3, | |
371 5,4, | |
372 1,2,3,3,4,5,3,4,3, | |
373 1,6, | |
374 10,7, | |
375 9,8, | |
376 | |
377 }; | |
378 | |
379 | |
380 static const unsigned char ag_sbt[] = { | |
381 0, 11, 13, 15, 17, 19, 28, 30, 32, 34 | |
382 }; | |
383 | |
384 | |
385 static const unsigned char ag_sbe[] = { | |
386 4, 12, 14, 16, 18, 24, 29, 31, 33, 34 | |
387 }; | |
388 | |
389 | |
390 static const unsigned char ag_fl[] = { | |
391 1,2,1,2,1,2,2,1,1,3,3 | |
392 }; | |
393 | |
394 static const unsigned char ag_ptt[] = { | |
395 0, 1, 5, 5, 2, 4, 4, 4, 4, 6, 8 | |
396 }; | |
397 | |
398 | |
399 static void ag_ra(void) | |
400 { | |
401 switch(ag_rpx[(PCB).ag_ap]) { | |
402 case 1: ag_rp_1(VW(0, AG_WRAP_4 *)); | |
403 VWD(0, AG_WRAP_4 *); break; | |
404 case 2: ag_rp_2(V(0,(bar *))); break; | |
405 case 3: VNO AG_WRAP_4(ag_rp_3()); break; | |
406 case 4: V(0,(bar *)) = ag_rp_4(); break; | |
407 } | |
408 } | |
409 | |
410 #define TOKEN_NAMES wraperror_token_names | |
411 const char *const wraperror_token_names[15] = { | |
412 "file", | |
413 "file", | |
414 "declarations", | |
415 "eof", | |
416 "declaration", | |
417 "", | |
418 "foo decl", | |
419 "'\\n'", | |
420 "bar decl", | |
421 "error", | |
422 "'f'", | |
423 "'o'", | |
424 "'b'", | |
425 "'a'", | |
426 "'r'", | |
427 | |
428 }; | |
429 | |
430 #ifndef MISSING_FORMAT | |
431 #define MISSING_FORMAT "Missing %s" | |
432 #endif | |
433 #ifndef UNEXPECTED_FORMAT | |
434 #define UNEXPECTED_FORMAT "Unexpected %s" | |
435 #endif | |
436 #ifndef UNNAMED_TOKEN | |
437 #define UNNAMED_TOKEN "input" | |
438 #endif | |
439 | |
440 | |
441 static void ag_diagnose(void) { | |
442 int ag_snd = (PCB).sn; | |
443 int ag_k = ag_sbt[ag_snd]; | |
444 | |
445 if (*TOKEN_NAMES[ag_tstt[ag_k]] && ag_astt[ag_k + 1] == ag_action_8) { | |
446 sprintf((PCB).ag_msg, MISSING_FORMAT, TOKEN_NAMES[ag_tstt[ag_k]]); | |
447 } | |
448 else if (ag_astt[ag_sbe[(PCB).sn]] == ag_action_8 | |
449 && (ag_k = (int) ag_sbe[(PCB).sn] + 1) == (int) ag_sbt[(PCB).sn+1] - 1 | |
450 && *TOKEN_NAMES[ag_tstt[ag_k]]) { | |
451 sprintf((PCB).ag_msg, MISSING_FORMAT, TOKEN_NAMES[ag_tstt[ag_k]]); | |
452 } | |
453 else if ((PCB).token_number && *TOKEN_NAMES[(PCB).token_number]) { | |
454 sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, TOKEN_NAMES[(PCB).token_number]); | |
455 } | |
456 else if (isprint(((PCB).input_code)) && ((PCB).input_code) != '\\') { | |
457 char buf[20]; | |
458 sprintf(buf, "\'%c\'", (char) ((PCB).input_code)); | |
459 sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, buf); | |
460 } | |
461 else sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, UNNAMED_TOKEN); | |
462 (PCB).error_message = (PCB).ag_msg; | |
463 | |
464 | |
465 } | |
466 static int ag_action_1_r_proc(void); | |
467 static int ag_action_2_r_proc(void); | |
468 static int ag_action_3_r_proc(void); | |
469 static int ag_action_4_r_proc(void); | |
470 static int ag_action_1_s_proc(void); | |
471 static int ag_action_3_s_proc(void); | |
472 static int ag_action_1_proc(void); | |
473 static int ag_action_2_proc(void); | |
474 static int ag_action_3_proc(void); | |
475 static int ag_action_4_proc(void); | |
476 static int ag_action_5_proc(void); | |
477 static int ag_action_6_proc(void); | |
478 static int ag_action_7_proc(void); | |
479 static int ag_action_8_proc(void); | |
480 static int ag_action_9_proc(void); | |
481 static int ag_action_10_proc(void); | |
482 static int ag_action_11_proc(void); | |
483 static int ag_action_8_proc(void); | |
484 | |
485 | |
486 static int (*const ag_r_procs_scan[])(void) = { | |
487 ag_action_1_r_proc, | |
488 ag_action_2_r_proc, | |
489 ag_action_3_r_proc, | |
490 ag_action_4_r_proc | |
491 }; | |
492 | |
493 static int (*const ag_s_procs_scan[])(void) = { | |
494 ag_action_1_s_proc, | |
495 ag_action_2_r_proc, | |
496 ag_action_3_s_proc, | |
497 ag_action_4_r_proc | |
498 }; | |
499 | |
500 static int (*const ag_gt_procs_scan[])(void) = { | |
501 ag_action_1_proc, | |
502 ag_action_2_proc, | |
503 ag_action_3_proc, | |
504 ag_action_4_proc, | |
505 ag_action_5_proc, | |
506 ag_action_6_proc, | |
507 ag_action_7_proc, | |
508 ag_action_8_proc, | |
509 ag_action_9_proc, | |
510 ag_action_10_proc, | |
511 ag_action_11_proc, | |
512 ag_action_8_proc | |
513 }; | |
514 | |
515 | |
516 static int ag_action_1_er_proc(void); | |
517 static int ag_action_2_er_proc(void); | |
518 static int ag_action_3_er_proc(void); | |
519 static int ag_action_4_er_proc(void); | |
520 | |
521 static int (*const ag_er_procs_scan[])(void) = { | |
522 ag_action_1_er_proc, | |
523 ag_action_2_er_proc, | |
524 ag_action_3_er_proc, | |
525 ag_action_4_er_proc | |
526 }; | |
527 | |
528 | |
529 static void ag_error_resynch(void) { | |
530 int ag_k; | |
531 int ag_ssx = (PCB).ssx; | |
532 | |
533 ag_diagnose(); | |
534 SYNTAX_ERROR; | |
535 if ((PCB).exit_flag != AG_RUNNING_CODE) return; | |
536 while (1) { | |
537 ag_k = ag_sbt[(PCB).sn]; | |
538 while (ag_tstt[ag_k] != 9 && ag_tstt[ag_k]) ag_k++; | |
539 if (ag_tstt[ag_k] || (PCB).ssx == 0) break; | |
540 ag_delete_object(); | |
541 } | |
542 if (ag_tstt[ag_k] == 0) { | |
543 (PCB).sn = PCB.ss[(PCB).ssx = ag_ssx]; | |
544 (PCB).exit_flag = AG_SYNTAX_ERROR_CODE; | |
545 return; | |
546 } | |
547 ag_k = ag_sbt[(PCB).sn]; | |
548 while (ag_tstt[ag_k] != 9 && ag_tstt[ag_k]) ag_k++; | |
549 (PCB).ag_ap = ag_pstt[ag_k]; | |
550 (ag_er_procs_scan[ag_astt[ag_k]])(); | |
551 while (1) { | |
552 ag_k = ag_sbt[(PCB).sn]; | |
553 while (ag_tstt[ag_k] != (unsigned char) (PCB).token_number && ag_tstt[ag_k]) | |
554 ag_k++; | |
555 if (ag_tstt[ag_k] && ag_astt[ag_k] != ag_action_10) break; | |
556 if ((PCB).token_number == 3) | |
557 {(PCB).exit_flag = AG_SYNTAX_ERROR_CODE; return;} | |
558 ag_track(); | |
559 if ((PCB).read_flag) { | |
560 (PCB).read_flag = 0; | |
561 GET_INPUT; | |
562 }; | |
563 (PCB).token_number = (wraperror_token_type) AG_TCV((PCB).input_code); | |
564 } | |
565 } | |
566 | |
567 | |
568 static int ag_action_10_proc(void) { | |
569 int ag_t = (PCB).token_number; | |
570 (PCB).btsx = 0, (PCB).drt = -1; | |
571 do { | |
572 ag_track(); | |
573 if ((PCB).read_flag) { | |
574 (PCB).read_flag = 0; | |
575 GET_INPUT; | |
576 }; | |
577 (PCB).token_number = (wraperror_token_type) AG_TCV((PCB).input_code); | |
578 } while ((PCB).token_number == (wraperror_token_type) ag_t); | |
579 return 1; | |
580 } | |
581 | |
582 static int ag_action_11_proc(void) { | |
583 int ag_t = (PCB).token_number; | |
584 | |
585 (PCB).btsx = 0, (PCB).drt = -1; | |
586 do { | |
587 (*(int *) &(PCB).vs[(PCB).ssx]) = (PCB).input_code; | |
588 (PCB).ssx--; | |
589 ag_track(); | |
590 ag_ra(); | |
591 if ((PCB).exit_flag != AG_RUNNING_CODE) return 0; | |
592 (PCB).ssx++; | |
593 if ((PCB).read_flag) { | |
594 (PCB).read_flag = 0; | |
595 GET_INPUT; | |
596 }; | |
597 (PCB).token_number = (wraperror_token_type) AG_TCV((PCB).input_code); | |
598 } | |
599 while ((PCB).token_number == (wraperror_token_type) ag_t); | |
600 return 1; | |
601 } | |
602 | |
603 static int ag_action_3_r_proc(void) { | |
604 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
605 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
606 (PCB).btsx = 0, (PCB).drt = -1; | |
607 (PCB).reduction_token = (wraperror_token_type) ag_ptt[(PCB).ag_ap]; | |
608 ag_ra(); | |
609 return (PCB).exit_flag == AG_RUNNING_CODE; | |
610 } | |
611 | |
612 static int ag_action_3_s_proc(void) { | |
613 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
614 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
615 (PCB).btsx = 0, (PCB).drt = -1; | |
616 (PCB).reduction_token = (wraperror_token_type) ag_ptt[(PCB).ag_ap]; | |
617 ag_ra(); | |
618 return (PCB).exit_flag == AG_RUNNING_CODE; | |
619 } | |
620 | |
621 static int ag_action_4_r_proc(void) { | |
622 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
623 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
624 (PCB).reduction_token = (wraperror_token_type) ag_ptt[(PCB).ag_ap]; | |
625 return 1; | |
626 } | |
627 | |
628 static int ag_action_2_proc(void) { | |
629 (PCB).btsx = 0, (PCB).drt = -1; | |
630 if ((PCB).ssx >= 128) { | |
631 (PCB).exit_flag = AG_STACK_ERROR_CODE; | |
632 PARSER_STACK_OVERFLOW; | |
633 } | |
634 (*(int *) &(PCB).vs[(PCB).ssx]) = (PCB).input_code; | |
635 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
636 (PCB).ssx++; | |
637 (PCB).sn = (PCB).ag_ap; | |
638 ag_track(); | |
639 return 0; | |
640 } | |
641 | |
642 static int ag_action_9_proc(void) { | |
643 if ((PCB).drt == -1) { | |
644 (PCB).drt=(PCB).token_number; | |
645 (PCB).dssx=(PCB).ssx; | |
646 (PCB).dsn=(PCB).sn; | |
647 } | |
648 ag_prot(); | |
649 (PCB).vs[(PCB).ssx] = ag_null_value; | |
650 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
651 (PCB).ssx++; | |
652 (PCB).sn = (PCB).ag_ap; | |
653 return (PCB).exit_flag == AG_RUNNING_CODE; | |
654 } | |
655 | |
656 static int ag_action_2_r_proc(void) { | |
657 (PCB).ssx++; | |
658 (PCB).sn = (PCB).ag_ap; | |
659 return 0; | |
660 } | |
661 | |
662 static int ag_action_7_proc(void) { | |
663 --(PCB).ssx; | |
664 (PCB).exit_flag = AG_SUCCESS_CODE; | |
665 return 0; | |
666 } | |
667 | |
668 static int ag_action_1_proc(void) { | |
669 ag_track(); | |
670 (PCB).exit_flag = AG_SUCCESS_CODE; | |
671 return 0; | |
672 } | |
673 | |
674 static int ag_action_1_r_proc(void) { | |
675 (PCB).exit_flag = AG_SUCCESS_CODE; | |
676 return 0; | |
677 } | |
678 | |
679 static int ag_action_1_s_proc(void) { | |
680 (PCB).exit_flag = AG_SUCCESS_CODE; | |
681 return 0; | |
682 } | |
683 | |
684 static int ag_action_4_proc(void) { | |
685 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
686 (PCB).reduction_token = (wraperror_token_type) ag_ptt[(PCB).ag_ap]; | |
687 (PCB).btsx = 0, (PCB).drt = -1; | |
688 (*(int *) &(PCB).vs[(PCB).ssx]) = (PCB).input_code; | |
689 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
690 else (PCB).ss[(PCB).ssx] = (PCB).sn; | |
691 ag_track(); | |
692 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
693 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
694 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
695 do { | |
696 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
697 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
698 else ag_t2 = ag_tx; | |
699 } while (ag_t1 < ag_t2); | |
700 (PCB).ag_ap = ag_pstt[ag_t1]; | |
701 if ((ag_s_procs_scan[ag_astt[ag_t1]])() == 0) break; | |
702 } | |
703 return 0; | |
704 } | |
705 | |
706 static int ag_action_3_proc(void) { | |
707 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
708 (PCB).btsx = 0, (PCB).drt = -1; | |
709 (*(int *) &(PCB).vs[(PCB).ssx]) = (PCB).input_code; | |
710 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
711 else (PCB).ss[(PCB).ssx] = (PCB).sn; | |
712 ag_track(); | |
713 (PCB).reduction_token = (wraperror_token_type) ag_ptt[(PCB).ag_ap]; | |
714 ag_ra(); | |
715 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
716 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
717 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
718 do { | |
719 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
720 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
721 else ag_t2 = ag_tx; | |
722 } while (ag_t1 < ag_t2); | |
723 (PCB).ag_ap = ag_pstt[ag_t1]; | |
724 if ((ag_s_procs_scan[ag_astt[ag_t1]])() == 0) break; | |
725 } | |
726 return 0; | |
727 } | |
728 | |
729 static int ag_action_8_proc(void) { | |
730 int ag_k = ag_sbt[(PCB).sn]; | |
731 while (ag_tstt[ag_k] != 9 && ag_tstt[ag_k]) ag_k++; | |
732 if (ag_tstt[ag_k] == 0) ag_undo(); | |
733 ag_error_resynch(); | |
734 return (PCB).exit_flag == AG_RUNNING_CODE; | |
735 } | |
736 | |
737 static int ag_action_5_proc(void) { | |
738 int ag_sd = ag_fl[(PCB).ag_ap]; | |
739 (PCB).btsx = 0, (PCB).drt = -1; | |
740 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
741 else { | |
742 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
743 } | |
744 (PCB).reduction_token = (wraperror_token_type) ag_ptt[(PCB).ag_ap]; | |
745 ag_ra(); | |
746 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
747 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
748 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
749 do { | |
750 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
751 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
752 else ag_t2 = ag_tx; | |
753 } while (ag_t1 < ag_t2); | |
754 (PCB).ag_ap = ag_pstt[ag_t1]; | |
755 if ((ag_r_procs_scan[ag_astt[ag_t1]])() == 0) break; | |
756 } | |
757 return (PCB).exit_flag == AG_RUNNING_CODE; | |
758 } | |
759 | |
760 static int ag_action_6_proc(void) { | |
761 int ag_sd = ag_fl[(PCB).ag_ap]; | |
762 (PCB).reduction_token = (wraperror_token_type) ag_ptt[(PCB).ag_ap]; | |
763 if ((PCB).drt == -1) { | |
764 (PCB).drt=(PCB).token_number; | |
765 (PCB).dssx=(PCB).ssx; | |
766 (PCB).dsn=(PCB).sn; | |
767 } | |
768 if (ag_sd) { | |
769 (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
770 } | |
771 else { | |
772 ag_prot(); | |
773 (PCB).vs[(PCB).ssx] = ag_null_value; | |
774 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
775 } | |
776 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
777 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
778 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
779 do { | |
780 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
781 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
782 else ag_t2 = ag_tx; | |
783 } while (ag_t1 < ag_t2); | |
784 (PCB).ag_ap = ag_pstt[ag_t1]; | |
785 if ((ag_r_procs_scan[ag_astt[ag_t1]])() == 0) break; | |
786 } | |
787 return (PCB).exit_flag == AG_RUNNING_CODE; | |
788 } | |
789 | |
790 | |
791 static int ag_action_2_er_proc(void) { | |
792 (PCB).btsx = 0, (PCB).drt = -1; | |
793 (*(int *) &(PCB).vs[(PCB).ssx]) = (PCB).input_code; | |
794 (PCB).ssx++; | |
795 (PCB).sn = (PCB).ag_ap; | |
796 return 0; | |
797 } | |
798 | |
799 static int ag_action_1_er_proc(void) { | |
800 (PCB).btsx = 0, (PCB).drt = -1; | |
801 (PCB).exit_flag = AG_SUCCESS_CODE; | |
802 return 0; | |
803 } | |
804 | |
805 static int ag_action_4_er_proc(void) { | |
806 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
807 (PCB).btsx = 0, (PCB).drt = -1; | |
808 (PCB).reduction_token = (wraperror_token_type) ag_ptt[(PCB).ag_ap]; | |
809 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
810 else (PCB).ss[(PCB).ssx] = (PCB).sn; | |
811 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
812 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
813 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
814 do { | |
815 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
816 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
817 else ag_t2 = ag_tx; | |
818 } while (ag_t1 < ag_t2); | |
819 (PCB).ag_ap = ag_pstt[ag_t1]; | |
820 if ((ag_s_procs_scan[ag_astt[ag_t1]])() == 0) break; | |
821 } | |
822 return 0; | |
823 } | |
824 | |
825 static int ag_action_3_er_proc(void) { | |
826 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
827 (PCB).btsx = 0, (PCB).drt = -1; | |
828 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
829 else (PCB).ss[(PCB).ssx] = (PCB).sn; | |
830 (PCB).reduction_token = (wraperror_token_type) ag_ptt[(PCB).ag_ap]; | |
831 ag_ra(); | |
832 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
833 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
834 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
835 do { | |
836 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
837 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
838 else ag_t2 = ag_tx; | |
839 } while (ag_t1 < ag_t2); | |
840 (PCB).ag_ap = ag_pstt[ag_t1]; | |
841 if ((ag_s_procs_scan[ag_astt[ag_t1]])() == 0) break; | |
842 } | |
843 return 0; | |
844 } | |
845 | |
846 | |
847 void init_wraperror(void) { | |
848 (PCB).read_flag = 1; | |
849 (PCB).ss[0] = (PCB).sn = (PCB).ssx = 0; | |
850 (PCB).exit_flag = AG_RUNNING_CODE; | |
851 (PCB).line = FIRST_LINE; | |
852 (PCB).column = FIRST_COLUMN; | |
853 (PCB).btsx = 0, (PCB).drt = -1; | |
854 } | |
855 | |
856 void wraperror(void) { | |
857 init_wraperror(); | |
858 (PCB).exit_flag = AG_RUNNING_CODE; | |
859 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
860 unsigned ag_t1 = ag_sbt[(PCB).sn]; | |
861 if (ag_tstt[ag_t1]) { | |
862 unsigned ag_t2 = ag_sbe[(PCB).sn] - 1; | |
863 if ((PCB).read_flag) { | |
864 (PCB).read_flag = 0; | |
865 GET_INPUT; | |
866 }; | |
867 (PCB).token_number = (wraperror_token_type) AG_TCV((PCB).input_code); | |
868 do { | |
869 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
870 if (ag_tstt[ag_tx] > (unsigned char)(PCB).token_number) | |
871 ag_t1 = ag_tx + 1; | |
872 else ag_t2 = ag_tx; | |
873 } while (ag_t1 < ag_t2); | |
874 if (ag_tstt[ag_t1] != (unsigned char)(PCB).token_number) | |
875 ag_t1 = ag_sbe[(PCB).sn]; | |
876 } | |
877 (PCB).ag_ap = ag_pstt[ag_t1]; | |
878 (ag_gt_procs_scan[ag_astt[ag_t1]])(); | |
879 } | |
880 } | |
881 | |
882 |