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