Mercurial > ~dholland > hg > ag > index.cgi
comparison tests/agcl/parsifal/good/eval-p.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 EVALKERN.SYN | |
3 | |
4 evaluateExpression: A Simple Expression Evaluator | |
5 Copyright (c) 1996 Parsifal Software, All Rights Reserved. | |
6 See the file COPYING for license and usage terms. | |
7 | |
8 EVALKERN.SYN is the kernel of the example, consisting | |
9 of the expression parser itself. Support functions are | |
10 defined in EVALWRAP.C. A test program is defined in | |
11 EVALDEMO.C. Global declarations are contained in | |
12 EVALDEFS.H. | |
13 | |
14 The parse function defined in EVALKERN.SYN is called | |
15 evalKernel. All communication with evalKernel is via | |
16 the parser control block. The wrapper function, | |
17 evaluateExpression, defined in EVALWRAP.C, provides | |
18 a more convenient interface for the function. | |
19 | |
20 The expression syntax is borrowed from C but with the | |
21 addition of the FORTRAN exponentiation operator (**). | |
22 | |
23 The cast, increment, and decrement operators are not | |
24 implemented, nor are operations that are defined only | |
25 for integers: | |
26 Bitwise logical operators: &, |, ^, ~, &=, |=, ^= | |
27 Remainder operators: %, %= | |
28 Shift operators: <<, >>, >>=, <<= | |
29 | |
30 The supported operations are: | |
31 Assignment operators: =, +=, -=, *=, /= | |
32 Conditional expressions: ? : | |
33 Logical operators: !, &&, || | |
34 Comparison operators: ==, !=, <, <=, >, >= | |
35 Binary arithmetic operators: +, -, *, / | |
36 Exponentiation: ** | |
37 Unary arithmetic operators: +, - | |
38 Parentheses | |
39 Function calls | |
40 | |
41 All arithmetic is double precision floating point. | |
42 | |
43 Input strings may contain any number of expressions, separated by | |
44 commas or semicolons. White space may be used freely, including | |
45 both C and C++ style comments. | |
46 | |
47 eval makes the following external calls: | |
48 void pushChar(int character); | |
49 Push the specified character onto a character stack. | |
50 | |
51 double *locateVariable(int nameLength); | |
52 Pop the last nameLength characters from the character stack | |
53 and, treating them as the name of a variable, return a pointer | |
54 to the location where the value of the variable is stored. | |
55 | |
56 void pushArg(double value); | |
57 Push the specified value onto an argument stack. | |
58 | |
59 double callFunction(nameLength, int argCount); | |
60 Pop the last nameLength characters from the character stack | |
61 and, treating them as the name of a function, identify the | |
62 function and invoke it with argCount arguments popped from | |
63 the argument stack. | |
64 | |
65 double checkZero(double value); | |
66 Verify that value is not zero. | |
67 | |
68 Overrides for macros defined by AnaGram, such as SYNTAX_ERROR | |
69 should are included in EVALDEFS.H | |
70 | |
71 EVALKERN.SYN is compiled with the AnaGram parser generator | |
72 yielding EVALKERN.H and EVALKERN.C. | |
73 | |
74 For information about AnaGram, visit http://www.parsifalsoft.com. | |
75 */ | |
76 | |
77 #include <math.h> | |
78 #include "evaldefs.h" // defines external interface | |
79 | |
80 | |
81 /* | |
82 * AnaGram, A System for Syntax Directed Programming | |
83 * File generated by: ... | |
84 * | |
85 * AnaGram Parsing Engine | |
86 * Copyright 1993-2002 Parsifal Software. All Rights Reserved. | |
87 * | |
88 * This software is provided 'as-is', without any express or implied | |
89 * warranty. In no event will the authors be held liable for any damages | |
90 * arising from the use of this software. | |
91 * | |
92 * Permission is granted to anyone to use this software for any purpose, | |
93 * including commercial applications, and to alter it and redistribute it | |
94 * freely, subject to the following restrictions: | |
95 * | |
96 * 1. The origin of this software must not be misrepresented; you must not | |
97 * claim that you wrote the original software. If you use this software | |
98 * in a product, an acknowledgment in the product documentation would be | |
99 * appreciated but is not required. | |
100 * 2. Altered source versions must be plainly marked as such, and must not be | |
101 * misrepresented as being the original software. | |
102 * 3. This notice may not be removed or altered from any source distribution. | |
103 */ | |
104 | |
105 #ifndef EVAL-P_H | |
106 #include "eval-p.h" | |
107 #endif | |
108 | |
109 #ifndef EVAL-P_H | |
110 #error Mismatched header file | |
111 #endif | |
112 | |
113 #include <ctype.h> | |
114 #include <stdio.h> | |
115 | |
116 #define RULE_CONTEXT (&((PCB).cs[(PCB).ssx])) | |
117 #define ERROR_CONTEXT ((PCB).cs[(PCB).error_frame_ssx]) | |
118 #define CONTEXT ((PCB).cs[(PCB).ssx]) | |
119 | |
120 | |
121 | |
122 evalKernel_pcb_type evalKernel_pcb; | |
123 #define PCB evalKernel_pcb | |
124 | |
125 /* Line -, eval-p.syn */ | |
126 #define SYNTAX_ERROR printf("%s in %s, line %d, column %d\n", \ | |
127 (PCB).error_message, TOKEN_NAMES[(PCB).error_frame_token], (PCB).line, (PCB).column) | |
128 | |
129 | |
130 #ifndef CONVERT_CASE | |
131 #define CONVERT_CASE(c) (c) | |
132 #endif | |
133 #ifndef TAB_SPACING | |
134 #define TAB_SPACING 8 | |
135 #endif | |
136 | |
137 #define ag_rp_1(k, x) (*locateVariable(k) = x) | |
138 | |
139 #define ag_rp_2(k, x) (*locateVariable(k) += x) | |
140 | |
141 #define ag_rp_3(k, x) (*locateVariable(k) -= x) | |
142 | |
143 #define ag_rp_4(k, x) (*locateVariable(k) *= x) | |
144 | |
145 #define ag_rp_5(k, x) (*locateVariable(k) /= x) | |
146 | |
147 #define ag_rp_6(c, x, y) (c?x:y) | |
148 | |
149 #define ag_rp_7(x, y) (x||y) | |
150 | |
151 #define ag_rp_8(x, y) (x&&y) | |
152 | |
153 #define ag_rp_9(x, y) (x==y) | |
154 | |
155 #define ag_rp_10(x, y) (x!=y) | |
156 | |
157 #define ag_rp_11(x, y) (x<y) | |
158 | |
159 #define ag_rp_12(x, y) (x<=y) | |
160 | |
161 #define ag_rp_13(x, y) (x>y) | |
162 | |
163 #define ag_rp_14(x, y) (x>=y) | |
164 | |
165 #define ag_rp_15(x, y) (x+y) | |
166 | |
167 #define ag_rp_16(x, y) (x-y) | |
168 | |
169 #define ag_rp_17(x, y) (x*y) | |
170 | |
171 #define ag_rp_18(x, y) (x/checkZero(y)) | |
172 | |
173 #define ag_rp_19(x, y) (pow(x,y)) | |
174 | |
175 #define ag_rp_20(k) (*locateVariable(k)) | |
176 | |
177 #define ag_rp_21(k, n) (callFunction(k,n)) | |
178 | |
179 #define ag_rp_22(x) (x) | |
180 | |
181 #define ag_rp_23(x) (-x) | |
182 | |
183 #define ag_rp_24(x) (x) | |
184 | |
185 #define ag_rp_25(x) (!x) | |
186 | |
187 #define ag_rp_26() (0) | |
188 | |
189 #define ag_rp_27(x) (pushArg(x), 1) | |
190 | |
191 #define ag_rp_28(k, x) (pushArg(x), k+1) | |
192 | |
193 #define ag_rp_29(x, e) (x*pow(10,e)) | |
194 | |
195 #define ag_rp_30(x, e) (x*pow(10,-e)) | |
196 | |
197 #define ag_rp_31(i, f) (i+f) | |
198 | |
199 #define ag_rp_32(f) (f) | |
200 | |
201 #define ag_rp_33(d) (d-'0') | |
202 | |
203 #define ag_rp_34(x, d) (10*x + d-'0') | |
204 | |
205 #define ag_rp_35(d) ((d-'0')/10.) | |
206 | |
207 #define ag_rp_36(d, f) ((d-'0' + f)/10.) | |
208 | |
209 #define ag_rp_37(d) (d-'0') | |
210 | |
211 #define ag_rp_38(x, d) (10*x + d-'0') | |
212 | |
213 #define ag_rp_39(c) (pushChar(c), 1) | |
214 | |
215 #define ag_rp_40(k, c) (pushChar(c), k+1) | |
216 | |
217 | |
218 #define READ_COUNTS | |
219 #define WRITE_COUNTS | |
220 #undef V | |
221 #define V(i,t) (*t (&(PCB).vs[(PCB).ssx + i])) | |
222 #undef VS | |
223 #define VS(i) (PCB).vs[(PCB).ssx + i] | |
224 | |
225 #ifndef GET_CONTEXT | |
226 #define GET_CONTEXT CONTEXT = (PCB).input_context | |
227 #endif | |
228 | |
229 typedef enum { | |
230 ag_action_1, | |
231 ag_action_2, | |
232 ag_action_3, | |
233 ag_action_4, | |
234 ag_action_5, | |
235 ag_action_6, | |
236 ag_action_7, | |
237 ag_action_8, | |
238 ag_action_9, | |
239 ag_action_10, | |
240 ag_action_11, | |
241 ag_action_12 | |
242 } ag_parser_action; | |
243 | |
244 | |
245 #ifndef NULL_VALUE_INITIALIZER | |
246 #define NULL_VALUE_INITIALIZER = { 0 } | |
247 #endif | |
248 | |
249 static evalKernel_vs_type const ag_null_value NULL_VALUE_INITIALIZER; | |
250 | |
251 static const unsigned char ag_rpx[] = { | |
252 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 0, 6, 0, 7, 0, 8, | |
253 0, 9, 10, 0, 11, 12, 13, 14, 0, 15, 16, 0, 17, 18, 0, 19, 0, 20, | |
254 21, 22, 23, 24, 25, 26, 0, 27, 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
255 0, 0, 0, 0, 0, 29, 30, 31, 0, 0, 0, 32, 33, 34, 35, 36, 37, 38, | |
256 39, 40 | |
257 }; | |
258 | |
259 static const unsigned char ag_key_itt[] = { | |
260 0 | |
261 }; | |
262 | |
263 static const unsigned short ag_key_pt[] = { | |
264 0 | |
265 }; | |
266 | |
267 static const unsigned char ag_key_ch[] = { | |
268 0, 42, 47,255, 47,255, 42,255, 42, 61,255, 42, 47, 61,255, 33, 38, 42, | |
269 43, 45, 47, 60, 61, 62,124,255, 42, 47,255, 33, 38, 42, 47, 60, 61, 62, | |
270 124,255, 33, 38, 42, 60, 61, 62,124,255, 33, 38, 60, 61, 62,124,255, 33, | |
271 38, 61,124,255, 38,124,255,124,255, 42, 61,255, 33, 38, 42, 43, 45, 47, | |
272 60, 61, 62,124,255 | |
273 }; | |
274 | |
275 static const unsigned char ag_key_act[] = { | |
276 0,0,0,4,2,4,3,4,0,0,4,0,0,0,4,3,3,2,3,3,2,3,3,3,3,4,0,0,4,3,3,3,2,3,3, | |
277 3,3,4,3,3,3,3,3,3,3,4,3,3,3,3,3,3,4,3,3,3,3,4,3,3,4,3,4,0,0,4,3,3,2,3, | |
278 3,3,3,3,3,3,4 | |
279 }; | |
280 | |
281 static const unsigned char ag_key_parm[] = { | |
282 0, 46, 51, 0, 0, 0, 50, 0, 93, 77, 0, 46, 51, 78, 0, 84, 82, 0, | |
283 75, 76, 0, 86, 83, 88, 81, 0, 46, 51, 0, 84, 82, 93, 0, 86, 83, 88, | |
284 81, 0, 84, 82, 93, 86, 83, 88, 81, 0, 84, 82, 86, 83, 88, 81, 0, 84, | |
285 82, 83, 81, 0, 82, 81, 0, 81, 0, 93, 77, 0, 84, 82, 0, 75, 76, 78, | |
286 86, 83, 88, 81, 0 | |
287 }; | |
288 | |
289 static const unsigned char ag_key_jmp[] = { | |
290 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 8, | |
291 6, 8, 11, 10, 12, 14, 16, 0, 0, 0, 0, 18, 20, 22, 26, 24, 26, 28, | |
292 30, 0, 32, 34, 36, 38, 40, 42, 44, 0, 46, 48, 50, 52, 54, 56, 0, 58, | |
293 60, 62, 64, 0, 66, 68, 0, 70, 0, 0, 0, 0, 72, 74, 63, 76, 78, 80, | |
294 82, 84, 86, 88, 0 | |
295 }; | |
296 | |
297 static const unsigned char ag_key_index[] = { | |
298 4, 0, 6, 15, 0, 0, 0, 6, 6, 0, 29, 29, 4, 4, 4, 4, 29, 0, | |
299 0, 0, 0, 38, 46, 46, 46, 53, 58, 15, 61, 66, 0, 29, 29, 0, 38, 0, | |
300 4, 0, 4, 0, 4, 0, 0, 0, 4, 0, 4, 0, 4, 0, 4, 0, 4, 0, | |
301 4, 0, 4, 0, 4, 0, 4, 0, 0, 4, 0, 4, 0, 4, 0, 4, 0, 4, | |
302 0, 4, 4, 0, 0, 0, 29, 46, 46, 46, 46, 46, 46, 46, 46, 53, 58, 0, | |
303 0, 0, 29, 29, 4, 0, 0 | |
304 }; | |
305 | |
306 static const unsigned char ag_key_ends[] = { | |
307 47,0, 61,0, 38,0, 61,0, 61,0, 61,0, 61,0, 61,0, 124,0, | |
308 61,0, 38,0, 42,0, 61,0, 61,0, 61,0, 124,0, 61,0, 38,0, 42,0, | |
309 61,0, 61,0, 61,0, 124,0, 61,0, 38,0, 61,0, 61,0, 61,0, 124,0, | |
310 61,0, 38,0, 61,0, 124,0, 38,0, 124,0, 124,0, 61,0, 38,0, | |
311 61,0, 61,0, 61,0, 61,0, 61,0, 61,0, 124,0, | |
312 }; | |
313 | |
314 #define AG_TCV(x) ag_tcv[(x)] | |
315 | |
316 static const unsigned char ag_tcv[] = { | |
317 6, 69, 69, 69, 69, 69, 69, 69, 69, 68, 55, 68, 68, 68, 69, 69, 69, 69, | |
318 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 68, 97, 69, 69, | |
319 69, 69, 69, 69, 96, 95, 91, 89, 98, 90, 61, 92, 64, 64, 64, 64, 64, 64, | |
320 64, 64, 64, 64, 79, 99, 85, 73, 87, 80, 69, 70, 70, 70, 70, 57, 70, 70, | |
321 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, | |
322 70, 69, 69, 69, 69, 70, 69, 70, 70, 70, 70, 57, 70, 70, 70, 70, 70, 70, | |
323 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 69, 69, 69, | |
324 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, | |
325 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, | |
326 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, | |
327 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, | |
328 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, | |
329 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, | |
330 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69, | |
331 69, 69, 69, 69 | |
332 }; | |
333 | |
334 #ifndef SYNTAX_ERROR | |
335 #define SYNTAX_ERROR fprintf(stderr,"%s, line %d, column %d\n", \ | |
336 (PCB).error_message, (PCB).line, (PCB).column) | |
337 #endif | |
338 | |
339 #ifndef FIRST_LINE | |
340 #define FIRST_LINE 1 | |
341 #endif | |
342 | |
343 #ifndef FIRST_COLUMN | |
344 #define FIRST_COLUMN 1 | |
345 #endif | |
346 | |
347 #ifndef PARSER_STACK_OVERFLOW | |
348 #define PARSER_STACK_OVERFLOW {fprintf(stderr, \ | |
349 "\nParser stack overflow, line %d, column %d\n",\ | |
350 (PCB).line, (PCB).column);} | |
351 #endif | |
352 | |
353 #ifndef REDUCTION_TOKEN_ERROR | |
354 #define REDUCTION_TOKEN_ERROR {fprintf(stderr, \ | |
355 "\nReduction token error, line %d, column %d\n", \ | |
356 (PCB).line, (PCB).column);} | |
357 #endif | |
358 | |
359 | |
360 #ifndef INPUT_CODE | |
361 #define INPUT_CODE(T) (T) | |
362 #endif | |
363 | |
364 typedef enum | |
365 {ag_accept_key, ag_set_key, ag_jmp_key, ag_end_key, ag_no_match_key, | |
366 ag_cf_accept_key, ag_cf_set_key, ag_cf_end_key} key_words; | |
367 | |
368 static void ag_get_key_word(int ag_k) { | |
369 int ag_save = (int) ((PCB).la_ptr - (PCB).pointer); | |
370 const unsigned char *ag_p; | |
371 int ag_ch; | |
372 while (1) { | |
373 switch (ag_key_act[ag_k]) { | |
374 case ag_cf_end_key: { | |
375 const unsigned char *sp = ag_key_ends + ag_key_jmp[ag_k]; | |
376 do { | |
377 if ((ag_ch = *sp++) == 0) { | |
378 int ag_k1 = ag_key_parm[ag_k]; | |
379 int ag_k2 = ag_key_pt[ag_k1]; | |
380 if (ag_key_itt[ag_k2 + CONVERT_CASE(*(PCB).la_ptr)]) goto ag_fail; | |
381 (PCB).token_number = (evalKernel_token_type) ag_key_pt[ag_k1 + 1]; | |
382 return; | |
383 } | |
384 } while (CONVERT_CASE(*(PCB).la_ptr++) == ag_ch); | |
385 goto ag_fail; | |
386 } | |
387 case ag_end_key: { | |
388 const unsigned char *sp = ag_key_ends + ag_key_jmp[ag_k]; | |
389 do { | |
390 if ((ag_ch = *sp++) == 0) { | |
391 (PCB).token_number = (evalKernel_token_type) ag_key_parm[ag_k]; | |
392 return; | |
393 } | |
394 } while (CONVERT_CASE(*(PCB).la_ptr++) == ag_ch); | |
395 } | |
396 case ag_no_match_key: | |
397 ag_fail: | |
398 (PCB).la_ptr = (PCB).pointer + ag_save; | |
399 return; | |
400 case ag_cf_set_key: { | |
401 int ag_k1 = ag_key_parm[ag_k]; | |
402 int ag_k2 = ag_key_pt[ag_k1]; | |
403 ag_k = ag_key_jmp[ag_k]; | |
404 if (ag_key_itt[ag_k2 + CONVERT_CASE(*(PCB).la_ptr)]) break; | |
405 ag_save = (int) ((PCB).la_ptr - (PCB).pointer); | |
406 (PCB).token_number = (evalKernel_token_type) ag_key_pt[ag_k1+1]; | |
407 break; | |
408 } | |
409 case ag_set_key: | |
410 ag_save = (int) ((PCB).la_ptr - (PCB).pointer); | |
411 (PCB).token_number = (evalKernel_token_type) ag_key_parm[ag_k]; | |
412 case ag_jmp_key: | |
413 ag_k = ag_key_jmp[ag_k]; | |
414 break; | |
415 case ag_accept_key: | |
416 (PCB).token_number = (evalKernel_token_type) ag_key_parm[ag_k]; | |
417 return; | |
418 case ag_cf_accept_key: { | |
419 int ag_k1 = ag_key_parm[ag_k]; | |
420 int ag_k2 = ag_key_pt[ag_k1]; | |
421 if (ag_key_itt[ag_k2 + CONVERT_CASE(*(PCB).la_ptr)]) | |
422 (PCB).la_ptr = (PCB).pointer + ag_save; | |
423 else (PCB).token_number = (evalKernel_token_type) ag_key_pt[ag_k1+1]; | |
424 return; | |
425 } | |
426 } | |
427 ag_ch = CONVERT_CASE(*(PCB).la_ptr++); | |
428 ag_p = &ag_key_ch[ag_k]; | |
429 if (ag_ch <= 255) while (*ag_p < ag_ch) ag_p++; | |
430 if (ag_ch > 255 || *ag_p != ag_ch) { | |
431 (PCB).la_ptr = (PCB).pointer + ag_save; | |
432 return; | |
433 } | |
434 ag_k = (int) (ag_p - ag_key_ch); | |
435 } | |
436 } | |
437 | |
438 | |
439 #ifndef AG_NEWLINE | |
440 #define AG_NEWLINE 10 | |
441 #endif | |
442 | |
443 #ifndef AG_RETURN | |
444 #define AG_RETURN 13 | |
445 #endif | |
446 | |
447 #ifndef AG_FORMFEED | |
448 #define AG_FORMFEED 12 | |
449 #endif | |
450 | |
451 #ifndef AG_TABCHAR | |
452 #define AG_TABCHAR 9 | |
453 #endif | |
454 | |
455 static void ag_track(void) { | |
456 int ag_k = (int) ((PCB).la_ptr - (PCB).pointer); | |
457 while (ag_k--) { | |
458 switch (*(PCB).pointer++) { | |
459 case AG_NEWLINE: | |
460 (PCB).column = 1, (PCB).line++; | |
461 case AG_RETURN: | |
462 case AG_FORMFEED: | |
463 break; | |
464 case AG_TABCHAR: | |
465 (PCB).column += (TAB_SPACING) - ((PCB).column - 1) % (TAB_SPACING); | |
466 break; | |
467 default: | |
468 (PCB).column++; | |
469 } | |
470 } | |
471 } | |
472 | |
473 | |
474 static void ag_prot(void) { | |
475 int ag_k; | |
476 ag_k = 128 - ++(PCB).btsx; | |
477 if (ag_k <= (PCB).ssx) { | |
478 (PCB).exit_flag = AG_STACK_ERROR_CODE; | |
479 PARSER_STACK_OVERFLOW; | |
480 return; | |
481 } | |
482 (PCB).bts[(PCB).btsx] = (PCB).sn; | |
483 (PCB).bts[ag_k] = (PCB).ssx; | |
484 (PCB).vs[ag_k] = (PCB).vs[(PCB).ssx]; | |
485 (PCB).ss[ag_k] = (PCB).ss[(PCB).ssx]; | |
486 } | |
487 | |
488 static void ag_undo(void) { | |
489 if ((PCB).drt == -1) return; | |
490 while ((PCB).btsx) { | |
491 int ag_k = 128 - (PCB).btsx; | |
492 (PCB).sn = (PCB).bts[(PCB).btsx--]; | |
493 (PCB).ssx = (PCB).bts[ag_k]; | |
494 (PCB).vs[(PCB).ssx] = (PCB).vs[ag_k]; | |
495 (PCB).ss[(PCB).ssx] = (PCB).ss[ag_k]; | |
496 } | |
497 (PCB).token_number = (evalKernel_token_type) (PCB).drt; | |
498 (PCB).ssx = (PCB).dssx; | |
499 (PCB).sn = (PCB).dsn; | |
500 (PCB).drt = -1; | |
501 } | |
502 | |
503 | |
504 static const unsigned char ag_tstt[] = { | |
505 99,98,97,96,90,89,70,68,64,61,57,55,51,46,6,0,1,71,72, | |
506 99,98,97,96,95,92,91,90,89,87,85,80,79,73,70,69,68,64,61,57,55,0,53,54, | |
507 99,98,97,96,95,92,91,90,89,87,85,80,79,73,70,69,68,64,61,57,55,50,0,48,49, | |
508 68,55,51,46,0,1, | |
509 99,98,97,96,90,89,70,64,61,57,6,0,2,3,4,5,7,8,10,16,19,21,23,26,31,32,33,34, | |
510 37,39,42,56,60,74,94, | |
511 99,98,97,96,95,92,91,90,89,87,85,80,79,73,70,69,68,64,61,57,0, | |
512 55,0, | |
513 99,98,97,96,95,92,91,90,89,87,85,80,79,73,70,69,68,64,61,57,55,0, | |
514 50,0, | |
515 64,0,62, | |
516 99,98,95,93,92,91,90,89,88,87,86,85,84,83,82,81,80,79,68,64,61,57,55,51,46, | |
517 6,0,63, | |
518 57,0, | |
519 97,96,90,89,70,68,64,61,57,55,51,46,0,1,71,72, | |
520 97,96,90,89,70,68,64,61,57,55,51,46,0,1,71,72, | |
521 97,96,90,89,70,68,64,61,57,55,51,46,0,1,71,72, | |
522 97,96,95,90,89,70,68,64,61,57,55,51,46,0,1,71,72, | |
523 99,98,95,93,92,91,90,89,88,87,86,85,84,83,82,81,80,79,68,55,51,46,6,0,1,71, | |
524 72, | |
525 97,96,90,89,70,64,61,57,0,2,3,32,33,37,39,42,56,60,74,94, | |
526 97,96,90,89,70,64,61,57,0,2,3,32,33,37,39,42,56,60,74,94, | |
527 97,96,90,89,70,64,61,57,0,2,3,32,33,37,39,42,56,60,74,94, | |
528 97,96,90,89,70,64,61,57,0,2,3,7,10,16,19,21,23,26,31,32,33,34,37,39,42,56, | |
529 60,74,94, | |
530 93,0,38, | |
531 92,91,0,35,36, | |
532 90,89,0,32,33, | |
533 88,87,86,85,0,27,28,29,30, | |
534 84,83,0,24,25, | |
535 82,0,22, | |
536 99,98,96,95,93,92,91,90,89,88,87,86,85,84,83,82,81,80,79,78,77,76,75,73,70, | |
537 68,64,57,55,51,46,6,0,1,71,72, | |
538 81,80,0,17,20, | |
539 96,78,77,76,75,73,0,11,12,13,14,15,39, | |
540 99,98,6,0,44,67, | |
541 64,0,62, | |
542 64,0,62, | |
543 90,89,64,0,58, | |
544 96,0,39, | |
545 95,0,41, | |
546 97,96,90,89,70,68,64,61,57,55,51,46,0,1,71,72, | |
547 97,96,90,89,70,64,61,57,0,2,3,32,33,34,37,39,42,56,60,74,94, | |
548 97,96,90,89,70,68,64,61,57,55,51,46,0,1,71,72, | |
549 97,96,90,89,70,64,61,57,0,2,3,32,33,34,37,39,42,56,60,74,94, | |
550 97,96,90,89,70,68,64,61,57,55,51,46,0,1,71,72, | |
551 97,96,90,89,70,64,61,57,0,2,3,32,33,34,37,39,42,56,60,74,94, | |
552 97,96,90,89,70,64,61,57,0,2,3,31,32,33,34,37,39,42,56,60,74,94, | |
553 97,96,90,89,70,64,61,57,0,2,3,31,32,33,34,37,39,42,56,60,74,94, | |
554 97,96,90,89,70,68,64,61,57,55,51,46,0,1,71,72, | |
555 97,96,90,89,70,64,61,57,0,2,3,26,31,32,33,34,37,39,42,56,60,74,94, | |
556 97,96,90,89,70,68,64,61,57,55,51,46,0,1,71,72, | |
557 97,96,90,89,70,64,61,57,0,2,3,26,31,32,33,34,37,39,42,56,60,74,94, | |
558 97,96,90,89,70,68,64,61,57,55,51,46,0,1,71,72, | |
559 97,96,90,89,70,64,61,57,0,2,3,26,31,32,33,34,37,39,42,56,60,74,94, | |
560 97,96,90,89,70,68,64,61,57,55,51,46,0,1,71,72, | |
561 97,96,90,89,70,64,61,57,0,2,3,26,31,32,33,34,37,39,42,56,60,74,94, | |
562 97,96,90,89,70,68,64,61,57,55,51,46,0,1,71,72, | |
563 97,96,90,89,70,64,61,57,0,2,3,23,26,31,32,33,34,37,39,42,56,60,74,94, | |
564 97,96,90,89,70,68,64,61,57,55,51,46,0,1,71,72, | |
565 97,96,90,89,70,64,61,57,0,2,3,23,26,31,32,33,34,37,39,42,56,60,74,94, | |
566 97,96,90,89,70,68,64,61,57,55,51,46,0,1,71,72, | |
567 97,96,90,89,70,64,61,57,0,2,3,21,23,26,31,32,33,34,37,39,42,56,60,74,94, | |
568 97,96,90,89,70,68,64,61,57,55,51,46,0,1,71,72, | |
569 97,96,90,89,70,64,61,57,0,2,3,19,21,23,26,31,32,33,34,37,39,42,56,60,74,94, | |
570 97,96,90,89,70,68,64,61,57,55,51,46,0,1,71,72, | |
571 97,96,90,89,70,64,61,57,0,2,3,7,10,16,19,21,23,26,31,32,33,34,37,39,42,56, | |
572 60,74,94, | |
573 97,96,95,90,89,70,64,61,57,0,2,3,7,10,16,19,21,23,26,31,32,33,34,37,39,40, | |
574 42,43,56,60,74,94, | |
575 97,96,90,89,70,68,64,61,57,55,51,46,0,1,71,72, | |
576 97,96,90,89,70,64,61,57,0,2,3,7,10,16,19,21,23,26,31,32,33,34,37,39,42,56, | |
577 60,74,94, | |
578 97,96,90,89,70,68,64,61,57,55,51,46,0,1,71,72, | |
579 97,96,90,89,70,64,61,57,0,2,3,7,10,16,19,21,23,26,31,32,33,34,37,39,42,56, | |
580 60,74,94, | |
581 97,96,90,89,70,68,64,61,57,55,51,46,0,1,71,72, | |
582 97,96,90,89,70,64,61,57,0,2,3,7,10,16,19,21,23,26,31,32,33,34,37,39,42,56, | |
583 60,74,94, | |
584 97,96,90,89,70,68,64,61,57,55,51,46,0,1,71,72, | |
585 97,96,90,89,70,64,61,57,0,2,3,7,10,16,19,21,23,26,31,32,33,34,37,39,42,56, | |
586 60,74,94, | |
587 97,96,90,89,70,68,64,61,57,55,51,46,0,1,71,72, | |
588 97,96,90,89,70,64,61,57,0,2,3,7,10,16,19,21,23,26,31,32,33,34,37,39,42,56, | |
589 60,74,94, | |
590 99,98,97,96,90,89,70,68,64,61,57,55,51,46,6,0,1,71,72, | |
591 99,98,97,96,90,89,70,68,64,61,57,55,51,46,6,0,1,71,72, | |
592 99,98,97,96,90,89,70,64,61,57,6,0,2,3,7,8,10,16,19,21,23,26,31,32,33,34,37, | |
593 39,42,56,60,74,94, | |
594 64,0,59, | |
595 64,0,59, | |
596 99,98,95,93,92,91,90,89,88,87,86,85,84,83,82,81,80,79,68,55,51,46,6,0,1,71, | |
597 72, | |
598 92,91,0,35,36, | |
599 92,91,0,35,36, | |
600 90,89,0,32,33, | |
601 90,89,0,32,33, | |
602 90,89,0,32,33, | |
603 90,89,0,32,33, | |
604 88,87,86,85,0,27,28,29,30, | |
605 88,87,86,85,0,27,28,29,30, | |
606 84,83,0,24,25, | |
607 82,0,22, | |
608 79,0,18, | |
609 98,0,44, | |
610 95,0,41, | |
611 64,0, | |
612 64,0, | |
613 97,96,90,89,70,68,64,61,57,55,51,46,0,1,71,72, | |
614 97,96,90,89,70,64,61,57,0,2,3,10,16,19,21,23,26,31,32,33,34,37,39,42,56,60, | |
615 74,94, | |
616 97,96,90,89,70,64,61,57,0,2,3,7,10,16,19,21,23,26,31,32,33,34,37,39,42,56, | |
617 60,74,94, | |
618 | |
619 }; | |
620 | |
621 | |
622 static unsigned const char ag_astt[1499] = { | |
623 8,8,8,8,8,8,8,1,8,8,8,1,1,1,8,7,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, | |
624 1,1,8,7,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,8,7,1,1,9,9,1,1,5,3, | |
625 5,5,1,1,1,1,2,2,1,2,5,7,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,9,9, | |
626 9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,5,3,7,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, | |
627 9,9,9,9,9,5,3,7,1,7,2,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,10,1,5,5,5,5,5, | |
628 7,3,1,5,5,5,5,5,5,1,5,5,5,1,1,1,7,1,1,3,5,5,5,5,5,1,5,5,5,1,1,1,7,1,1,3,5, | |
629 5,5,5,5,1,5,5,5,1,1,1,7,1,1,3,5,5,5,5,5,5,1,5,5,5,1,1,1,7,1,1,3,5,5,5,5,5, | |
630 5,5,5,5,5,5,5,5,5,5,5,5,5,1,1,1,1,5,7,1,1,3,1,1,1,1,2,2,1,2,7,2,1,1,1,2,1, | |
631 1,1,1,1,1,1,1,1,1,2,2,1,2,7,2,1,1,1,2,1,1,1,1,1,1,1,1,1,1,2,2,1,2,7,2,1,1, | |
632 1,2,1,1,1,1,1,1,1,1,1,1,2,2,1,2,7,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, | |
633 1,5,1,1,1,5,1,1,1,1,5,1,1,1,1,1,1,5,1,1,1,1,1,1,5,1,1,1,5,1,5,5,5,5,5,5,5, | |
634 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,10,1,10,10,1,1,1,5,7,1,1,3,1,1,5,1,1,1,1, | |
635 1,1,1,1,4,1,1,1,1,1,1,1,1,3,7,1,1,1,4,2,1,5,2,1,1,8,7,1,1,4,1,1,7,2,5,5,5, | |
636 5,5,1,5,5,5,1,1,1,7,1,1,3,1,1,1,1,2,2,1,2,7,1,1,1,1,2,1,1,1,1,1,1,1,5,5,5, | |
637 5,5,1,5,5,5,1,1,1,7,1,1,3,1,1,1,1,2,2,1,2,7,1,1,1,1,2,1,1,1,1,1,1,1,5,5,5, | |
638 5,5,1,5,5,5,1,1,1,7,1,1,3,1,1,1,1,2,2,1,2,7,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1, | |
639 1,2,2,1,2,7,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,1,2,7,1,1,1,1,1,1,1,1,1, | |
640 1,1,1,1,5,5,5,5,5,1,5,5,5,1,1,1,7,1,1,3,1,1,1,1,2,2,1,2,7,1,1,1,1,1,1,1,1, | |
641 1,1,1,1,1,1,5,5,5,5,5,1,5,5,5,1,1,1,7,1,1,3,1,1,1,1,2,2,1,2,7,1,1,1,1,1,1, | |
642 1,1,1,1,1,1,1,1,5,5,5,5,5,1,5,5,5,1,1,1,7,1,1,3,1,1,1,1,2,2,1,2,7,1,1,1,1, | |
643 1,1,1,1,1,1,1,1,1,1,5,5,5,5,5,1,5,5,5,1,1,1,7,1,1,3,1,1,1,1,2,2,1,2,7,1,1, | |
644 1,1,1,1,1,1,1,1,1,1,1,1,5,5,5,5,5,1,5,5,5,1,1,1,7,1,1,3,1,1,1,1,2,2,1,2,7, | |
645 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,5,5,5,5,5,1,5,5,5,1,1,1,7,1,1,3,1,1,1,1,2,2, | |
646 1,2,7,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,5,5,5,5,5,1,5,5,5,1,1,1,7,1,1,3,1,1,1, | |
647 1,2,2,1,2,7,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,5,5,5,5,5,1,5,5,5,1,1,1,7,1,1, | |
648 3,1,1,1,1,2,2,1,2,7,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,5,5,5,5,5,1,5,5,5,1, | |
649 1,1,7,1,1,3,1,1,1,1,2,2,1,2,7,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, | |
650 4,1,1,2,2,1,2,7,1,1,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,5,5,5,5,5,1,5, | |
651 5,5,1,1,1,7,1,1,3,1,1,1,1,2,2,1,2,7,1,1,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, | |
652 1,5,5,5,5,5,1,5,5,5,1,1,1,7,1,1,3,1,1,1,1,2,2,1,2,7,1,1,2,2,1,1,1,1,1,1,1, | |
653 1,1,1,1,1,1,1,1,1,5,5,5,5,5,1,5,5,5,1,1,1,7,1,1,3,1,1,1,1,2,2,1,2,7,1,1,2, | |
654 2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,5,5,5,5,5,1,5,5,5,1,1,1,7,1,1,3,1,1,1,1, | |
655 2,2,1,2,7,1,1,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,5,5,5,5,5,1,5,5,5,1,1,1, | |
656 7,1,1,3,1,1,1,1,2,2,1,2,7,1,1,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,5,5,5,5, | |
657 5,5,5,1,5,5,5,1,1,1,5,7,1,1,3,5,5,5,5,5,5,5,1,5,5,5,1,1,1,5,7,1,1,3,5,5,1, | |
658 1,1,1,2,2,1,2,5,7,1,1,3,3,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,7,1,2,7,1,5, | |
659 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,1,1,1,1,5,7,1,1,3,1,1,4,1,1,1,1,4,1,1,1, | |
660 1,4,1,1,1,1,4,1,1,1,1,4,1,1,1,1,4,1,1,1,1,1,1,4,1,1,1,1,1,1,1,1,4,1,1,1,1, | |
661 1,1,4,1,1,1,4,1,1,7,1,1,5,1,1,7,2,10,4,10,4,5,5,5,5,5,1,5,5,5,1,1,1,7,1,1, | |
662 3,1,1,1,1,2,2,1,2,7,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,1,2, | |
663 7,1,1,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 | |
664 }; | |
665 | |
666 | |
667 static const unsigned char ag_pstt[] = { | |
668 4,4,4,4,4,4,4,3,4,4,4,3,1,2,4,0,3,3,4, | |
669 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,1,5,6, | |
670 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,8,2,7,8, | |
671 125,125,1,2,127,125, | |
672 2,2,12,15,14,13,72,66,9,72,2,4,21,29,0,30,30,30,30,28,26,25,24,23,22,18,19, | |
673 22,21,20,17,11,10,27,16, | |
674 52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,52,54, | |
675 55,6, | |
676 47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,49, | |
677 50,8, | |
678 31,9,65, | |
679 62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,67,32,62,62,62,62, | |
680 62,10,64, | |
681 33,56, | |
682 126,126,126,126,126,3,126,126,126,3,1,2,12,3,3,152, | |
683 126,126,126,126,126,3,126,126,126,3,1,2,13,3,3,144, | |
684 126,126,126,126,126,3,126,126,126,3,1,2,14,3,3,145, | |
685 126,126,126,126,126,126,3,126,126,126,3,1,2,15,3,3,151, | |
686 126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,3,3, | |
687 1,2,126,16,3,3,149, | |
688 12,15,14,13,72,66,9,72,17,40,34,18,19,40,20,17,11,10,27,16, | |
689 12,15,14,13,72,66,9,72,18,39,34,18,19,39,20,17,11,10,27,16, | |
690 12,15,14,13,72,66,9,72,19,38,34,18,19,38,20,17,11,10,27,16, | |
691 12,15,14,13,72,66,9,72,20,21,29,35,35,28,26,25,24,23,22,18,19,22,21,20,17, | |
692 11,10,27,16, | |
693 36,32,37, | |
694 38,40,26,41,39, | |
695 14,13,21,43,42, | |
696 44,46,48,50,18,51,49,47,45, | |
697 52,54,16,55,53, | |
698 56,14,57, | |
699 126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126, | |
700 126,126,126,126,126,73,3,73,73,3,1,2,126,27,3,3,129, | |
701 58,60,12,61,59, | |
702 15,63,65,67,69,71,35,72,70,68,66,64,62, | |
703 73,74,1,30,75,75, | |
704 31,68,69, | |
705 31,63,61, | |
706 76,77,77,33,77, | |
707 15,35,62, | |
708 78,35,37, | |
709 126,126,126,126,126,3,126,126,126,3,1,2,36,3,3,148, | |
710 12,15,14,13,72,66,9,72,37,21,34,18,19,33,21,20,17,11,10,27,16, | |
711 126,126,126,126,126,3,126,126,126,3,1,2,38,3,3,147, | |
712 12,15,14,13,72,66,9,72,39,21,34,18,19,31,21,20,17,11,10,27,16, | |
713 126,126,126,126,126,3,126,126,126,3,1,2,40,3,3,146, | |
714 12,15,14,13,72,66,9,72,41,21,34,18,19,30,21,20,17,11,10,27,16, | |
715 12,15,14,13,72,66,9,72,42,21,34,79,18,19,79,21,20,17,11,10,27,16, | |
716 12,15,14,13,72,66,9,72,43,21,34,80,18,19,80,21,20,17,11,10,27,16, | |
717 126,126,126,126,126,3,126,126,126,3,1,2,44,3,3,143, | |
718 12,15,14,13,72,66,9,72,45,21,34,81,22,18,19,22,21,20,17,11,10,27,16, | |
719 126,126,126,126,126,3,126,126,126,3,1,2,46,3,3,142, | |
720 12,15,14,13,72,66,9,72,47,21,34,82,22,18,19,22,21,20,17,11,10,27,16, | |
721 126,126,126,126,126,3,126,126,126,3,1,2,48,3,3,141, | |
722 12,15,14,13,72,66,9,72,49,21,34,83,22,18,19,22,21,20,17,11,10,27,16, | |
723 126,126,126,126,126,3,126,126,126,3,1,2,50,3,3,140, | |
724 12,15,14,13,72,66,9,72,51,21,34,84,22,18,19,22,21,20,17,11,10,27,16, | |
725 126,126,126,126,126,3,126,126,126,3,1,2,52,3,3,139, | |
726 12,15,14,13,72,66,9,72,53,21,34,85,23,22,18,19,22,21,20,17,11,10,27,16, | |
727 126,126,126,126,126,3,126,126,126,3,1,2,54,3,3,138, | |
728 12,15,14,13,72,66,9,72,55,21,34,86,23,22,18,19,22,21,20,17,11,10,27,16, | |
729 126,126,126,126,126,3,126,126,126,3,1,2,56,3,3,137, | |
730 12,15,14,13,72,66,9,72,57,21,34,87,24,23,22,18,19,22,21,20,17,11,10,27,16, | |
731 126,126,126,126,126,3,126,126,126,3,1,2,58,3,3,136, | |
732 12,15,14,13,72,66,9,72,59,21,34,88,25,24,23,22,18,19,22,21,20,17,11,10,27, | |
733 16, | |
734 126,126,126,126,126,3,126,126,126,3,1,2,60,3,3,135, | |
735 12,15,14,13,72,66,9,72,61,21,29,89,89,28,26,25,24,23,22,18,19,22,21,20,17, | |
736 11,10,27,16, | |
737 12,15,41,14,13,72,66,9,72,62,21,29,43,43,28,26,25,24,23,22,18,19,22,21,20, | |
738 91,17,90,11,10,27,16, | |
739 126,126,126,126,126,3,126,126,126,3,1,2,63,3,3,133, | |
740 12,15,14,13,72,66,9,72,64,21,29,11,11,28,26,25,24,23,22,18,19,22,21,20,17, | |
741 11,10,27,16, | |
742 126,126,126,126,126,3,126,126,126,3,1,2,65,3,3,132, | |
743 12,15,14,13,72,66,9,72,66,21,29,10,10,28,26,25,24,23,22,18,19,22,21,20,17, | |
744 11,10,27,16, | |
745 126,126,126,126,126,3,126,126,126,3,1,2,67,3,3,131, | |
746 12,15,14,13,72,66,9,72,68,21,29,9,9,28,26,25,24,23,22,18,19,22,21,20,17,11, | |
747 10,27,16, | |
748 126,126,126,126,126,3,126,126,126,3,1,2,69,3,3,130, | |
749 12,15,14,13,72,66,9,72,70,21,29,8,8,28,26,25,24,23,22,18,19,22,21,20,17,11, | |
750 10,27,16, | |
751 126,126,126,126,126,3,126,126,126,3,1,2,71,3,3,128, | |
752 12,15,14,13,72,66,9,72,72,21,29,7,7,28,26,25,24,23,22,18,19,22,21,20,17,11, | |
753 10,27,16, | |
754 126,126,126,126,126,126,126,3,126,126,126,3,1,2,126,73,3,3,154, | |
755 126,126,126,126,126,126,126,3,126,126,126,3,1,2,126,74,3,3,153, | |
756 2,2,12,15,14,13,72,66,9,72,2,75,21,29,5,5,5,28,26,25,24,23,22,18,19,22,21, | |
757 20,17,11,10,27,16, | |
758 70,76,92, | |
759 70,77,93, | |
760 126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,3,3, | |
761 1,2,126,78,3,3,150, | |
762 38,40,28,41,39, | |
763 38,40,27,41,39, | |
764 14,13,25,43,42, | |
765 14,13,24,43,42, | |
766 14,13,23,43,42, | |
767 14,13,22,43,42, | |
768 44,46,48,50,20,51,49,47,45, | |
769 44,46,48,50,19,51,49,47,45, | |
770 52,54,17,55,53, | |
771 56,15,57, | |
772 94,89,95, | |
773 74,42,96, | |
774 78,91,36, | |
775 71,60, | |
776 71,59, | |
777 126,126,126,126,126,3,126,126,126,3,1,2,94,3,3,134, | |
778 12,15,14,13,72,66,9,72,95,21,34,13,28,26,25,24,23,22,18,19,22,21,20,17,11, | |
779 10,27,16, | |
780 12,15,14,13,72,66,9,72,96,21,29,44,44,28,26,25,24,23,22,18,19,22,21,20,17, | |
781 11,10,27,16, | |
782 | |
783 }; | |
784 | |
785 | |
786 static const unsigned short ag_sbt[] = { | |
787 0, 19, 43, 68, 74, 109, 130, 132, 154, 156, 159, 187, 189, 205, | |
788 221, 237, 254, 281, 301, 321, 341, 370, 373, 378, 383, 392, 397, 400, | |
789 436, 441, 454, 460, 463, 466, 471, 474, 477, 493, 514, 530, 551, 567, | |
790 588, 610, 632, 648, 671, 687, 710, 726, 749, 765, 788, 804, 828, 844, | |
791 868, 884, 909, 925, 951, 967, 996,1028,1044,1073,1089,1118,1134,1163, | |
792 1179,1208,1224,1253,1272,1291,1324,1327,1330,1357,1362,1367,1372,1377, | |
793 1382,1387,1396,1405,1410,1413,1416,1419,1422,1424,1426,1442,1470,1499 | |
794 }; | |
795 | |
796 | |
797 static const unsigned short ag_sbe[] = { | |
798 15, 40, 65, 72, 85, 129, 131, 153, 155, 157, 185, 188, 201, 217, | |
799 233, 250, 277, 289, 309, 329, 349, 371, 375, 380, 387, 394, 398, 432, | |
800 438, 447, 457, 461, 464, 469, 472, 475, 489, 501, 526, 538, 563, 575, | |
801 596, 618, 644, 656, 683, 695, 722, 734, 761, 773, 800, 812, 840, 852, | |
802 880, 892, 921, 933, 963, 975,1005,1040,1052,1085,1097,1130,1142,1175, | |
803 1187,1220,1232,1268,1287,1302,1325,1328,1353,1359,1364,1369,1374,1379, | |
804 1384,1391,1400,1407,1411,1414,1417,1420,1423,1425,1438,1450,1478,1499 | |
805 }; | |
806 | |
807 | |
808 static const unsigned char ag_fl[] = { | |
809 2,2,0,1,1,3,1,3,3,3,3,3,1,5,1,3,1,3,1,3,3,1,3,3,3,3,1,3,3,1,3,3,1,3,1, | |
810 1,4,3,2,2,2,0,1,1,3,1,1,2,0,1,3,1,2,0,1,3,1,0,1,4,4,3,0,1,2,2,1,2,1,2, | |
811 1,2,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, | |
812 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,0,1,2,2,2,2,2,2,2,2,2,2,2,2, | |
813 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2 | |
814 }; | |
815 | |
816 static const unsigned char ag_ptt[] = { | |
817 0, 4, 8, 8, 5, 5, 7, 7, 7, 7, 7, 7, 10, 10, 16, 16, 19, 19, | |
818 21, 21, 21, 23, 23, 23, 23, 23, 26, 26, 26, 31, 31, 31, 34, 34, 37, 37, | |
819 37, 37, 37, 37, 37, 40, 40, 43, 43, 1, 48, 48, 49, 49, 1, 53, 53, 54, | |
820 54, 1, 94, 58, 58, 94, 94, 56, 63, 63, 56, 56, 60, 60, 62, 62, 59, 59, | |
821 74, 74, 9, 9, 45, 45, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, | |
822 47, 47, 47, 47, 47, 47, 47, 47, 47, 52, 52, 52, 52, 52, 52, 52, 52, 52, | |
823 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 65, 65, 66, 66, 66, 71, 71, | |
824 72, 72, 11, 3, 12, 13, 14, 15, 18, 17, 20, 22, 24, 25, 27, 28, 29, 30, | |
825 32, 33, 35, 36, 38, 2, 41, 39, 42, 44, 67 | |
826 }; | |
827 | |
828 | |
829 static void ag_ra(void) | |
830 { | |
831 switch(ag_rpx[(PCB).ag_ap]) { | |
832 case 1: V(0,(double *)) = ag_rp_1(V(0,(int *)), V(2,(double *))); break; | |
833 case 2: V(0,(double *)) = ag_rp_2(V(0,(int *)), V(2,(double *))); break; | |
834 case 3: V(0,(double *)) = ag_rp_3(V(0,(int *)), V(2,(double *))); break; | |
835 case 4: V(0,(double *)) = ag_rp_4(V(0,(int *)), V(2,(double *))); break; | |
836 case 5: V(0,(double *)) = ag_rp_5(V(0,(int *)), V(2,(double *))); break; | |
837 case 6: V(0,(double *)) = ag_rp_6(V(0,(double *)), V(2,(double *)), V(4,(double *))); break; | |
838 case 7: V(0,(double *)) = ag_rp_7(V(0,(double *)), V(2,(double *))); break; | |
839 case 8: V(0,(double *)) = ag_rp_8(V(0,(double *)), V(2,(double *))); break; | |
840 case 9: V(0,(double *)) = ag_rp_9(V(0,(double *)), V(2,(double *))); break; | |
841 case 10: V(0,(double *)) = ag_rp_10(V(0,(double *)), V(2,(double *))); break; | |
842 case 11: V(0,(double *)) = ag_rp_11(V(0,(double *)), V(2,(double *))); break; | |
843 case 12: V(0,(double *)) = ag_rp_12(V(0,(double *)), V(2,(double *))); break; | |
844 case 13: V(0,(double *)) = ag_rp_13(V(0,(double *)), V(2,(double *))); break; | |
845 case 14: V(0,(double *)) = ag_rp_14(V(0,(double *)), V(2,(double *))); break; | |
846 case 15: V(0,(double *)) = ag_rp_15(V(0,(double *)), V(2,(double *))); break; | |
847 case 16: V(0,(double *)) = ag_rp_16(V(0,(double *)), V(2,(double *))); break; | |
848 case 17: V(0,(double *)) = ag_rp_17(V(0,(double *)), V(2,(double *))); break; | |
849 case 18: V(0,(double *)) = ag_rp_18(V(0,(double *)), V(2,(double *))); break; | |
850 case 19: V(0,(double *)) = ag_rp_19(V(0,(double *)), V(2,(double *))); break; | |
851 case 20: V(0,(double *)) = ag_rp_20(V(0,(int *))); break; | |
852 case 21: V(0,(double *)) = ag_rp_21(V(0,(int *)), V(2,(int *))); break; | |
853 case 22: V(0,(double *)) = ag_rp_22(V(1,(double *))); break; | |
854 case 23: V(0,(double *)) = ag_rp_23(V(1,(double *))); break; | |
855 case 24: V(0,(double *)) = ag_rp_24(V(1,(double *))); break; | |
856 case 25: V(0,(double *)) = ag_rp_25(V(1,(double *))); break; | |
857 case 26: V(0,(int *)) = ag_rp_26(); break; | |
858 case 27: V(0,(int *)) = ag_rp_27(V(0,(double *))); break; | |
859 case 28: V(0,(int *)) = ag_rp_28(V(0,(int *)), V(2,(double *))); break; | |
860 case 29: V(0,(double *)) = ag_rp_29(V(0,(double *)), V(3,(int *))); break; | |
861 case 30: V(0,(double *)) = ag_rp_30(V(0,(double *)), V(3,(int *))); break; | |
862 case 31: V(0,(double *)) = ag_rp_31(V(0,(double *)), V(2,(double *))); break; | |
863 case 32: V(0,(double *)) = ag_rp_32(V(1,(double *))); break; | |
864 case 33: V(0,(double *)) = ag_rp_33(V(0,(int *))); break; | |
865 case 34: V(0,(double *)) = ag_rp_34(V(0,(double *)), V(1,(int *))); break; | |
866 case 35: V(0,(double *)) = ag_rp_35(V(0,(int *))); break; | |
867 case 36: V(0,(double *)) = ag_rp_36(V(0,(int *)), V(1,(double *))); break; | |
868 case 37: V(0,(int *)) = ag_rp_37(V(0,(int *))); break; | |
869 case 38: V(0,(int *)) = ag_rp_38(V(0,(int *)), V(1,(int *))); break; | |
870 case 39: V(0,(int *)) = ag_rp_39(V(0,(int *))); break; | |
871 case 40: V(0,(int *)) = ag_rp_40(V(0,(int *)), V(1,(int *))); break; | |
872 } | |
873 (PCB).la_ptr = (PCB).pointer; | |
874 } | |
875 | |
876 #define TOKEN_NAMES evalKernel_token_names | |
877 const char *const evalKernel_token_names[100] = { | |
878 "input string", | |
879 "white space", | |
880 "real", | |
881 "name", | |
882 "input string", | |
883 "expressions", | |
884 "eof", | |
885 "expression", | |
886 "", | |
887 "", | |
888 "conditional expression", | |
889 "'='", | |
890 "\"+=\"", | |
891 "\"-=\"", | |
892 "\"*=\"", | |
893 "\"/=\"", | |
894 "logical or expression", | |
895 "'\\?'", | |
896 "':'", | |
897 "logical and expression", | |
898 "\"||\"", | |
899 "equality expression", | |
900 "\"&&\"", | |
901 "relational expression", | |
902 "\"==\"", | |
903 "\"!=\"", | |
904 "additive expression", | |
905 "'<'", | |
906 "\"<=\"", | |
907 "'>'", | |
908 "\">=\"", | |
909 "multiplicative expression", | |
910 "'+'", | |
911 "'-'", | |
912 "factor", | |
913 "'*'", | |
914 "'/'", | |
915 "primary", | |
916 "\"**\"", | |
917 "'('", | |
918 "arguments", | |
919 "')'", | |
920 "'!'", | |
921 "argument list", | |
922 "','", | |
923 "", | |
924 "\"/*\"", | |
925 "", | |
926 "", | |
927 "", | |
928 "\"*/\"", | |
929 "\"//\"", | |
930 "", | |
931 "", | |
932 "", | |
933 "'\\n'", | |
934 "simple real", | |
935 "", | |
936 "", | |
937 "exponent", | |
938 "integer part", | |
939 "'.'", | |
940 "fraction part", | |
941 "", | |
942 "digit", | |
943 "letter", | |
944 "", | |
945 "", | |
946 "", | |
947 "", | |
948 "", | |
949 "", | |
950 "", | |
951 "'='", | |
952 "name", | |
953 "\"+=\"", | |
954 "\"-=\"", | |
955 "\"*=\"", | |
956 "\"/=\"", | |
957 "':'", | |
958 "'\\?'", | |
959 "\"||\"", | |
960 "\"&&\"", | |
961 "\"==\"", | |
962 "\"!=\"", | |
963 "'<'", | |
964 "\"<=\"", | |
965 "'>'", | |
966 "\">=\"", | |
967 "'+'", | |
968 "'-'", | |
969 "'*'", | |
970 "'/'", | |
971 "\"**\"", | |
972 "real", | |
973 "')'", | |
974 "'('", | |
975 "'!'", | |
976 "','", | |
977 "", | |
978 | |
979 }; | |
980 | |
981 | |
982 static const unsigned char ag_ctn[] = { | |
983 0,0, 1,1, 1,1, 0,0, 0,0, 0,0, 1,2, 0,0, 1,2, 56,1, 56,1, 94,1, | |
984 37,1, 0,0, 0,0, 0,0, 37,1, 37,1, 37,1, 37,1, 37,1, 34,1, 31,1, 26,1, | |
985 23,1, 21,1, 19,1, 37,1, 10,1, 7,1, 0,0, 62,1, 56,2, 94,2, 37,1, 37,2, | |
986 0,0, 34,2, 0,0, 31,2, 0,0, 31,2, 26,2, 26,2, 0,0, 23,2, 0,0, 23,2, | |
987 0,0, 23,2, 0,0, 23,2, 0,0, 21,2, 0,0, 21,2, 0,0, 19,2, 0,0, 16,2, | |
988 0,0, 10,2, 37,2, 0,0, 7,2, 0,0, 7,2, 0,0, 7,2, 0,0, 7,2, 0,0, | |
989 7,2, 9,1, 0,0, 5,2, 94,3, 94,3, 0,0, 31,1, 31,1, 26,1, 26,1, 26,1, | |
990 26,1, 23,1, 23,1, 21,1, 19,1, 10,3, 43,1, 37,3, 59,1, 59,1, 0,0, 10,4, | |
991 43,2 | |
992 }; | |
993 | |
994 #ifndef MISSING_FORMAT | |
995 #define MISSING_FORMAT "Missing %s" | |
996 #endif | |
997 #ifndef UNEXPECTED_FORMAT | |
998 #define UNEXPECTED_FORMAT "Unexpected %s" | |
999 #endif | |
1000 #ifndef UNNAMED_TOKEN | |
1001 #define UNNAMED_TOKEN "input" | |
1002 #endif | |
1003 | |
1004 | |
1005 static void ag_diagnose(void) { | |
1006 int ag_snd = (PCB).sn; | |
1007 int ag_k = ag_sbt[ag_snd]; | |
1008 | |
1009 if (*TOKEN_NAMES[ag_tstt[ag_k]] && ag_astt[ag_k + 1] == ag_action_8) { | |
1010 sprintf((PCB).ag_msg, MISSING_FORMAT, TOKEN_NAMES[ag_tstt[ag_k]]); | |
1011 } | |
1012 else if (ag_astt[ag_sbe[(PCB).sn]] == ag_action_8 | |
1013 && (ag_k = (int) ag_sbe[(PCB).sn] + 1) == (int) ag_sbt[(PCB).sn+1] - 1 | |
1014 && *TOKEN_NAMES[ag_tstt[ag_k]]) { | |
1015 sprintf((PCB).ag_msg, MISSING_FORMAT, TOKEN_NAMES[ag_tstt[ag_k]]); | |
1016 } | |
1017 else if ((PCB).token_number && *TOKEN_NAMES[(PCB).token_number]) { | |
1018 sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, TOKEN_NAMES[(PCB).token_number]); | |
1019 } | |
1020 else if (isprint(INPUT_CODE((*(PCB).pointer))) && INPUT_CODE((*(PCB).pointer)) != '\\') { | |
1021 char buf[20]; | |
1022 sprintf(buf, "\'%c\'", (char) INPUT_CODE((*(PCB).pointer))); | |
1023 sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, buf); | |
1024 } | |
1025 else sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, UNNAMED_TOKEN); | |
1026 (PCB).error_message = (PCB).ag_msg; | |
1027 | |
1028 | |
1029 { | |
1030 int ag_sx, ag_t; | |
1031 | |
1032 ag_sx = (PCB).ssx; | |
1033 (PCB).ss[ag_sx] = (PCB).sn; | |
1034 do { | |
1035 while (ag_sx && ag_ctn[2*(ag_snd = (PCB).ss[ag_sx])] == 0) ag_sx--; | |
1036 if (ag_sx) { | |
1037 ag_t = ag_ctn[2*ag_snd]; | |
1038 ag_sx -= ag_ctn[2*ag_snd +1]; | |
1039 ag_snd = (PCB).ss[ag_sx]; | |
1040 } | |
1041 else { | |
1042 ag_snd = 0; | |
1043 ag_t = ag_ptt[0]; | |
1044 } | |
1045 } while (ag_sx && *TOKEN_NAMES[ag_t]==0); | |
1046 if (*TOKEN_NAMES[ag_t] == 0) ag_t = 0; | |
1047 (PCB).error_frame_ssx = ag_sx; | |
1048 (PCB).error_frame_token = (evalKernel_token_type) ag_t; | |
1049 } | |
1050 | |
1051 | |
1052 } | |
1053 static int ag_action_1_r_proc(void); | |
1054 static int ag_action_2_r_proc(void); | |
1055 static int ag_action_3_r_proc(void); | |
1056 static int ag_action_4_r_proc(void); | |
1057 static int ag_action_1_s_proc(void); | |
1058 static int ag_action_3_s_proc(void); | |
1059 static int ag_action_1_proc(void); | |
1060 static int ag_action_2_proc(void); | |
1061 static int ag_action_3_proc(void); | |
1062 static int ag_action_4_proc(void); | |
1063 static int ag_action_5_proc(void); | |
1064 static int ag_action_6_proc(void); | |
1065 static int ag_action_7_proc(void); | |
1066 static int ag_action_8_proc(void); | |
1067 static int ag_action_9_proc(void); | |
1068 static int ag_action_10_proc(void); | |
1069 static int ag_action_11_proc(void); | |
1070 static int ag_action_8_proc(void); | |
1071 | |
1072 | |
1073 static int (*const ag_r_procs_scan[])(void) = { | |
1074 ag_action_1_r_proc, | |
1075 ag_action_2_r_proc, | |
1076 ag_action_3_r_proc, | |
1077 ag_action_4_r_proc | |
1078 }; | |
1079 | |
1080 static int (*const ag_s_procs_scan[])(void) = { | |
1081 ag_action_1_s_proc, | |
1082 ag_action_2_r_proc, | |
1083 ag_action_3_s_proc, | |
1084 ag_action_4_r_proc | |
1085 }; | |
1086 | |
1087 static int (*const ag_gt_procs_scan[])(void) = { | |
1088 ag_action_1_proc, | |
1089 ag_action_2_proc, | |
1090 ag_action_3_proc, | |
1091 ag_action_4_proc, | |
1092 ag_action_5_proc, | |
1093 ag_action_6_proc, | |
1094 ag_action_7_proc, | |
1095 ag_action_8_proc, | |
1096 ag_action_9_proc, | |
1097 ag_action_10_proc, | |
1098 ag_action_11_proc, | |
1099 ag_action_8_proc | |
1100 }; | |
1101 | |
1102 | |
1103 static int ag_rns(int ag_t, int *ag_sx, int ag_snd) { | |
1104 while (1) { | |
1105 int ag_act, ag_k = ag_sbt[ag_snd], ag_lim = ag_sbt[ag_snd+1]; | |
1106 int ag_p; | |
1107 | |
1108 while (ag_k < ag_lim && ag_tstt[ag_k] != ag_t) ag_k++; | |
1109 if (ag_k == ag_lim) break; | |
1110 ag_act = ag_astt[ag_k]; | |
1111 ag_p = ag_pstt[ag_k]; | |
1112 if (ag_act == ag_action_2) return ag_p; | |
1113 if (ag_act == ag_action_10 || ag_act == ag_action_11) { | |
1114 (*ag_sx)--; | |
1115 return ag_snd; | |
1116 } | |
1117 if (ag_act != ag_action_3 && | |
1118 ag_act != ag_action_4) break; | |
1119 *ag_sx -= (ag_fl[ag_p] - 1); | |
1120 ag_snd = (PCB).ss[*ag_sx]; | |
1121 ag_t = ag_ptt[ag_p]; | |
1122 } | |
1123 return 0; | |
1124 } | |
1125 | |
1126 static int ag_jns(int ag_t) { | |
1127 int ag_k; | |
1128 | |
1129 ag_k = ag_sbt[(PCB).sn]; | |
1130 while (ag_tstt[ag_k] != ag_t && ag_tstt[ag_k]) ag_k++; | |
1131 while (1) { | |
1132 int ag_p = ag_pstt[ag_k]; | |
1133 int ag_sd; | |
1134 | |
1135 switch (ag_astt[ag_k]) { | |
1136 case ag_action_2: | |
1137 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
1138 return ag_p; | |
1139 case ag_action_10: | |
1140 case ag_action_11: | |
1141 return (PCB).ss[(PCB).ssx--]; | |
1142 case ag_action_9: | |
1143 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
1144 (PCB).ssx++; | |
1145 (PCB).sn = ag_p; | |
1146 ag_k = ag_sbt[(PCB).sn]; | |
1147 while (ag_tstt[ag_k] != ag_t && ag_tstt[ag_k]) ag_k++; | |
1148 continue; | |
1149 case ag_action_3: | |
1150 case ag_action_4: | |
1151 ag_sd = ag_fl[ag_p] - 1; | |
1152 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
1153 else (PCB).ss[(PCB).ssx] = (PCB).sn; | |
1154 ag_t = ag_ptt[ag_p]; | |
1155 ag_k = ag_sbt[(PCB).sn+1]; | |
1156 while (ag_tstt[--ag_k] != ag_t); | |
1157 continue; | |
1158 case ag_action_5: | |
1159 case ag_action_6: | |
1160 if (ag_fl[ag_p]) break; | |
1161 (PCB).sn = ag_rns(ag_ptt[ag_p],&(PCB).ssx, (PCB).sn); | |
1162 (PCB).ss[++(PCB).ssx] = (PCB).sn; | |
1163 ag_k = ag_sbt[(PCB).sn]; | |
1164 while (ag_tstt[ag_k] != ag_t && ag_tstt[ag_k]) ag_k++; | |
1165 continue; | |
1166 } | |
1167 break; | |
1168 } | |
1169 return 0; | |
1170 } | |
1171 | |
1172 | |
1173 static int ag_atx(int ag_t, int *ag_sx, int ag_snd) { | |
1174 int ag_k, ag_f; | |
1175 int ag_save_btsx = (PCB).btsx; | |
1176 int ag_flag = 1; | |
1177 | |
1178 while (1) { | |
1179 int ag_a; | |
1180 | |
1181 (PCB).bts[128 - ++(PCB).btsx] = *ag_sx; | |
1182 (PCB).ss[128 - (PCB).btsx] = (PCB).ss[*ag_sx]; | |
1183 (PCB).ss[*ag_sx] = ag_snd; | |
1184 ag_k = ag_sbt[ag_snd]; | |
1185 while (ag_tstt[ag_k] != ag_t && ag_tstt[ag_k]) ag_k++; | |
1186 ag_a = ag_astt[ag_k]; | |
1187 if (ag_a == ag_action_2 || | |
1188 ag_a == ag_action_3 || | |
1189 ag_a == ag_action_10 || | |
1190 ag_a == ag_action_11 || | |
1191 ag_a == ag_action_1 || | |
1192 ag_a == ag_action_4) break; | |
1193 if ((ag_a == ag_action_5 || | |
1194 ag_a == ag_action_6) && | |
1195 (ag_k = ag_fl[ag_f = ag_pstt[ag_k]]) == 0) { | |
1196 ag_snd = ag_rns(ag_ptt[ag_f],ag_sx, (PCB).ss[*ag_sx]); | |
1197 (*ag_sx)++; | |
1198 continue; | |
1199 } | |
1200 if (ag_a == ag_action_9) { | |
1201 ag_snd = ag_pstt[ag_k]; | |
1202 (*ag_sx)++; | |
1203 continue; | |
1204 } | |
1205 ag_flag = 0; | |
1206 break; | |
1207 } | |
1208 while ((PCB).btsx > ag_save_btsx) { | |
1209 *ag_sx = (PCB).bts[128 - (PCB).btsx]; | |
1210 (PCB).ss[*ag_sx] = (PCB).ss[128 - (PCB).btsx--]; | |
1211 } | |
1212 return ag_flag; | |
1213 } | |
1214 | |
1215 | |
1216 static int ag_tst_tkn(void) { | |
1217 int ag_rk, ag_sx, ag_snd = (PCB).sn; | |
1218 | |
1219 (PCB).token_number = (evalKernel_token_type) AG_TCV(INPUT_CODE(*(PCB).la_ptr)); | |
1220 (PCB).la_ptr++; | |
1221 if (ag_key_index[(PCB).sn]) { | |
1222 unsigned ag_k = ag_key_index[(PCB).sn]; | |
1223 int ag_ch = CONVERT_CASE(INPUT_CODE(*(PCB).pointer)); | |
1224 if (ag_ch <= 255) { | |
1225 while (ag_key_ch[ag_k] < ag_ch) ag_k++; | |
1226 if (ag_key_ch[ag_k] == ag_ch) ag_get_key_word(ag_k); | |
1227 } | |
1228 } | |
1229 for (ag_rk = 0; ag_rk < (PCB).ag_lrss; ag_rk += 2) { | |
1230 ag_sx = (PCB).ag_rss[ag_rk]; | |
1231 if (ag_sx > (PCB).ssx || ag_sx > (PCB).ag_min_depth) continue; | |
1232 (PCB).sn = (PCB).ag_rss[ag_rk + 1]; | |
1233 if (ag_atx((PCB).token_number, &ag_sx, (PCB).sn)) break; | |
1234 } | |
1235 (PCB).sn = ag_snd; | |
1236 return ag_rk; | |
1237 } | |
1238 | |
1239 static void ag_set_error_procs(void); | |
1240 | |
1241 static void ag_auto_resynch(void) { | |
1242 int ag_sx, ag_rk; | |
1243 int ag_rk1, ag_rk2, ag_tk1; | |
1244 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
1245 if ((PCB).ag_error_depth && (PCB).ag_min_depth >= (PCB).ag_error_depth) { | |
1246 (PCB).ssx = (PCB).ag_error_depth; | |
1247 (PCB).sn = (PCB).ss[(PCB).ssx]; | |
1248 } | |
1249 else { | |
1250 ag_diagnose(); | |
1251 SYNTAX_ERROR; | |
1252 if ((PCB).exit_flag != AG_RUNNING_CODE) return; | |
1253 (PCB).ag_error_depth = (PCB).ag_min_depth = 0; | |
1254 (PCB).ag_lrss = 0; | |
1255 (PCB).ss[ag_sx = (PCB).ssx] = (PCB).sn; | |
1256 (PCB).ag_min_depth = (PCB).ag_rss[(PCB).ag_lrss++] = ag_sx; | |
1257 (PCB).ag_rss[(PCB).ag_lrss++] = (PCB).sn; | |
1258 while (ag_sx && (PCB).ag_lrss < 2*128) { | |
1259 int ag_t = 0, ag_x, ag_s, ag_sxs = ag_sx; | |
1260 | |
1261 while (ag_sx && (ag_t = ag_ctn[2*(PCB).sn]) == 0) (PCB).sn = (PCB).ss[--ag_sx]; | |
1262 if (ag_t) (PCB).sn = (PCB).ss[ag_sx -= ag_ctn[2*(PCB).sn +1]]; | |
1263 else { | |
1264 if (ag_sx == 0) (PCB).sn = 0; | |
1265 ag_t = ag_ptt[0]; | |
1266 } | |
1267 if ((ag_s = ag_rns(ag_t, &ag_sx, (PCB).sn)) == 0) break; | |
1268 for (ag_x = 0; ag_x < (PCB).ag_lrss; ag_x += 2) | |
1269 if ((PCB).ag_rss[ag_x] == ag_sx + 1 && (PCB).ag_rss[ag_x+1] == ag_s) break; | |
1270 if (ag_x == (PCB).ag_lrss) { | |
1271 (PCB).ag_rss[(PCB).ag_lrss++] = ++ag_sx; | |
1272 (PCB).ag_rss[(PCB).ag_lrss++] = (PCB).sn = ag_s; | |
1273 } | |
1274 else if (ag_sx >= ag_sxs) ag_sx--; | |
1275 } | |
1276 ag_set_error_procs(); | |
1277 } | |
1278 (PCB).la_ptr = (PCB).pointer; | |
1279 if ((PCB).ssx > (PCB).ag_min_depth) (PCB).ag_min_depth = (PCB).ssx; | |
1280 while (1) { | |
1281 ag_rk1 = ag_tst_tkn(); | |
1282 if ((PCB).token_number == 6) | |
1283 {(PCB).exit_flag = AG_SYNTAX_ERROR_CODE; return;} | |
1284 if (ag_rk1 < (PCB).ag_lrss) break; | |
1285 {(PCB).la_ptr = (PCB).pointer + 1; ag_track();} | |
1286 } | |
1287 ag_tk1 = (PCB).token_number; | |
1288 ag_track(); | |
1289 ag_rk2 = ag_tst_tkn(); | |
1290 if (ag_rk2 < ag_rk1) {ag_rk = ag_rk2; ag_track();} | |
1291 else {ag_rk = ag_rk1; (PCB).token_number = (evalKernel_token_type) ag_tk1; (PCB).la_ptr = (PCB).pointer;} | |
1292 (PCB).ag_min_depth = (PCB).ssx = (PCB).ag_rss[ag_rk++]; | |
1293 (PCB).sn = (PCB).ss[(PCB).ssx] = (PCB).ag_rss[ag_rk]; | |
1294 (PCB).sn = ag_jns((PCB).token_number); | |
1295 if ((PCB).ag_error_depth == 0 || (PCB).ag_error_depth > (PCB).ssx) | |
1296 (PCB).ag_error_depth = (PCB).ssx; | |
1297 if (++(PCB).ssx >= 128) { | |
1298 (PCB).exit_flag = AG_STACK_ERROR_CODE; | |
1299 PARSER_STACK_OVERFLOW; | |
1300 return; | |
1301 } | |
1302 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
1303 (PCB).ag_tmp_depth = (PCB).ag_min_depth; | |
1304 (PCB).la_ptr = (PCB).pointer; | |
1305 return; | |
1306 } | |
1307 | |
1308 | |
1309 static int ag_action_10_proc(void) { | |
1310 int ag_t = (PCB).token_number; | |
1311 (PCB).btsx = 0, (PCB).drt = -1; | |
1312 do { | |
1313 ag_track(); | |
1314 (PCB).token_number = (evalKernel_token_type) AG_TCV(INPUT_CODE(*(PCB).la_ptr)); | |
1315 (PCB).la_ptr++; | |
1316 if (ag_key_index[(PCB).sn]) { | |
1317 unsigned ag_k = ag_key_index[(PCB).sn]; | |
1318 int ag_ch = CONVERT_CASE(INPUT_CODE(*(PCB).pointer)); | |
1319 if (ag_ch <= 255) { | |
1320 while (ag_key_ch[ag_k] < ag_ch) ag_k++; | |
1321 if (ag_key_ch[ag_k] == ag_ch) ag_get_key_word(ag_k); | |
1322 } | |
1323 } | |
1324 } while ((PCB).token_number == (evalKernel_token_type) ag_t); | |
1325 (PCB).la_ptr = (PCB).pointer; | |
1326 return 1; | |
1327 } | |
1328 | |
1329 static int ag_action_11_proc(void) { | |
1330 int ag_t = (PCB).token_number; | |
1331 | |
1332 (PCB).btsx = 0, (PCB).drt = -1; | |
1333 do { | |
1334 (*(int *) &(PCB).vs[(PCB).ssx]) = *(PCB).pointer; | |
1335 (PCB).ssx--; | |
1336 ag_track(); | |
1337 ag_ra(); | |
1338 if ((PCB).exit_flag != AG_RUNNING_CODE) return 0; | |
1339 (PCB).ssx++; | |
1340 (PCB).token_number = (evalKernel_token_type) AG_TCV(INPUT_CODE(*(PCB).la_ptr)); | |
1341 (PCB).la_ptr++; | |
1342 if (ag_key_index[(PCB).sn]) { | |
1343 unsigned ag_k = ag_key_index[(PCB).sn]; | |
1344 int ag_ch = CONVERT_CASE(INPUT_CODE(*(PCB).pointer)); | |
1345 if (ag_ch <= 255) { | |
1346 while (ag_key_ch[ag_k] < ag_ch) ag_k++; | |
1347 if (ag_key_ch[ag_k] == ag_ch) ag_get_key_word(ag_k); | |
1348 } | |
1349 } | |
1350 } | |
1351 while ((PCB).token_number == (evalKernel_token_type) ag_t); | |
1352 (PCB).la_ptr = (PCB).pointer; | |
1353 return 1; | |
1354 } | |
1355 | |
1356 static int ag_action_3_r_proc(void) { | |
1357 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
1358 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
1359 (PCB).btsx = 0, (PCB).drt = -1; | |
1360 (PCB).reduction_token = (evalKernel_token_type) ag_ptt[(PCB).ag_ap]; | |
1361 ag_ra(); | |
1362 return (PCB).exit_flag == AG_RUNNING_CODE; | |
1363 } | |
1364 | |
1365 static int ag_action_3_s_proc(void) { | |
1366 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
1367 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
1368 (PCB).btsx = 0, (PCB).drt = -1; | |
1369 (PCB).reduction_token = (evalKernel_token_type) ag_ptt[(PCB).ag_ap]; | |
1370 ag_ra(); | |
1371 return (PCB).exit_flag == AG_RUNNING_CODE; | |
1372 } | |
1373 | |
1374 static int ag_action_4_r_proc(void) { | |
1375 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
1376 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
1377 (PCB).reduction_token = (evalKernel_token_type) ag_ptt[(PCB).ag_ap]; | |
1378 return 1; | |
1379 } | |
1380 | |
1381 static int ag_action_2_proc(void) { | |
1382 (PCB).btsx = 0, (PCB).drt = -1; | |
1383 if ((PCB).ssx >= 128) { | |
1384 (PCB).exit_flag = AG_STACK_ERROR_CODE; | |
1385 PARSER_STACK_OVERFLOW; | |
1386 } | |
1387 (*(int *) &(PCB).vs[(PCB).ssx]) = *(PCB).pointer; | |
1388 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
1389 (PCB).ssx++; | |
1390 (PCB).sn = (PCB).ag_ap; | |
1391 ag_track(); | |
1392 return 0; | |
1393 } | |
1394 | |
1395 static int ag_action_9_proc(void) { | |
1396 if ((PCB).drt == -1) { | |
1397 (PCB).drt=(PCB).token_number; | |
1398 (PCB).dssx=(PCB).ssx; | |
1399 (PCB).dsn=(PCB).sn; | |
1400 } | |
1401 ag_prot(); | |
1402 (PCB).vs[(PCB).ssx] = ag_null_value; | |
1403 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
1404 (PCB).ssx++; | |
1405 (PCB).sn = (PCB).ag_ap; | |
1406 (PCB).la_ptr = (PCB).pointer; | |
1407 return (PCB).exit_flag == AG_RUNNING_CODE; | |
1408 } | |
1409 | |
1410 static int ag_action_2_r_proc(void) { | |
1411 (PCB).ssx++; | |
1412 (PCB).sn = (PCB).ag_ap; | |
1413 return 0; | |
1414 } | |
1415 | |
1416 static int ag_action_7_proc(void) { | |
1417 --(PCB).ssx; | |
1418 (PCB).la_ptr = (PCB).pointer; | |
1419 (PCB).exit_flag = AG_SUCCESS_CODE; | |
1420 return 0; | |
1421 } | |
1422 | |
1423 static int ag_action_1_proc(void) { | |
1424 ag_track(); | |
1425 (PCB).exit_flag = AG_SUCCESS_CODE; | |
1426 return 0; | |
1427 } | |
1428 | |
1429 static int ag_action_1_r_proc(void) { | |
1430 (PCB).exit_flag = AG_SUCCESS_CODE; | |
1431 return 0; | |
1432 } | |
1433 | |
1434 static int ag_action_1_s_proc(void) { | |
1435 (PCB).exit_flag = AG_SUCCESS_CODE; | |
1436 return 0; | |
1437 } | |
1438 | |
1439 static int ag_action_4_proc(void) { | |
1440 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
1441 (PCB).reduction_token = (evalKernel_token_type) ag_ptt[(PCB).ag_ap]; | |
1442 (PCB).btsx = 0, (PCB).drt = -1; | |
1443 (*(int *) &(PCB).vs[(PCB).ssx]) = *(PCB).pointer; | |
1444 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
1445 else (PCB).ss[(PCB).ssx] = (PCB).sn; | |
1446 ag_track(); | |
1447 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
1448 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
1449 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
1450 do { | |
1451 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
1452 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
1453 else ag_t2 = ag_tx; | |
1454 } while (ag_t1 < ag_t2); | |
1455 (PCB).ag_ap = ag_pstt[ag_t1]; | |
1456 if ((*(PCB).s_procs[ag_astt[ag_t1]])() == 0) break; | |
1457 } | |
1458 return 0; | |
1459 } | |
1460 | |
1461 static int ag_action_3_proc(void) { | |
1462 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
1463 (PCB).btsx = 0, (PCB).drt = -1; | |
1464 (*(int *) &(PCB).vs[(PCB).ssx]) = *(PCB).pointer; | |
1465 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
1466 else (PCB).ss[(PCB).ssx] = (PCB).sn; | |
1467 ag_track(); | |
1468 (PCB).reduction_token = (evalKernel_token_type) ag_ptt[(PCB).ag_ap]; | |
1469 ag_ra(); | |
1470 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
1471 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
1472 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
1473 do { | |
1474 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
1475 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
1476 else ag_t2 = ag_tx; | |
1477 } while (ag_t1 < ag_t2); | |
1478 (PCB).ag_ap = ag_pstt[ag_t1]; | |
1479 if ((*(PCB).s_procs[ag_astt[ag_t1]])() == 0) break; | |
1480 } | |
1481 return 0; | |
1482 } | |
1483 | |
1484 static int ag_action_8_proc(void) { | |
1485 ag_undo(); | |
1486 (PCB).la_ptr = (PCB).pointer; | |
1487 ag_auto_resynch(); | |
1488 return (PCB).exit_flag == AG_RUNNING_CODE; | |
1489 } | |
1490 | |
1491 static int ag_action_5_proc(void) { | |
1492 int ag_sd = ag_fl[(PCB).ag_ap]; | |
1493 (PCB).btsx = 0, (PCB).drt = -1; | |
1494 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
1495 else { | |
1496 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
1497 } | |
1498 (PCB).la_ptr = (PCB).pointer; | |
1499 (PCB).reduction_token = (evalKernel_token_type) ag_ptt[(PCB).ag_ap]; | |
1500 ag_ra(); | |
1501 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
1502 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
1503 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
1504 do { | |
1505 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
1506 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
1507 else ag_t2 = ag_tx; | |
1508 } while (ag_t1 < ag_t2); | |
1509 (PCB).ag_ap = ag_pstt[ag_t1]; | |
1510 if ((*(PCB).r_procs[ag_astt[ag_t1]])() == 0) break; | |
1511 } | |
1512 return (PCB).exit_flag == AG_RUNNING_CODE; | |
1513 } | |
1514 | |
1515 static int ag_action_6_proc(void) { | |
1516 int ag_sd = ag_fl[(PCB).ag_ap]; | |
1517 (PCB).reduction_token = (evalKernel_token_type) ag_ptt[(PCB).ag_ap]; | |
1518 if ((PCB).drt == -1) { | |
1519 (PCB).drt=(PCB).token_number; | |
1520 (PCB).dssx=(PCB).ssx; | |
1521 (PCB).dsn=(PCB).sn; | |
1522 } | |
1523 if (ag_sd) { | |
1524 (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
1525 } | |
1526 else { | |
1527 ag_prot(); | |
1528 (PCB).vs[(PCB).ssx] = ag_null_value; | |
1529 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
1530 } | |
1531 (PCB).la_ptr = (PCB).pointer; | |
1532 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
1533 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
1534 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
1535 do { | |
1536 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
1537 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
1538 else ag_t2 = ag_tx; | |
1539 } while (ag_t1 < ag_t2); | |
1540 (PCB).ag_ap = ag_pstt[ag_t1]; | |
1541 if ((*(PCB).r_procs[ag_astt[ag_t1]])() == 0) break; | |
1542 } | |
1543 return (PCB).exit_flag == AG_RUNNING_CODE; | |
1544 } | |
1545 | |
1546 | |
1547 static void ag_check_depth(int ag_fl) { | |
1548 int ag_sx = (PCB).ssx - ag_fl; | |
1549 if ((PCB).ag_error_depth && ag_sx < (PCB).ag_tmp_depth) (PCB).ag_tmp_depth = ag_sx; | |
1550 } | |
1551 | |
1552 static int ag_action_3_er_proc(void) { | |
1553 ag_check_depth(ag_fl[(PCB).ag_ap] - 1); | |
1554 return ag_action_4_r_proc(); | |
1555 } | |
1556 | |
1557 static int ag_action_2_e_proc(void) { | |
1558 ag_action_2_proc(); | |
1559 (PCB).ag_min_depth = (PCB).ag_tmp_depth; | |
1560 return 0; | |
1561 } | |
1562 | |
1563 static int ag_action_4_e_proc(void) { | |
1564 ag_check_depth(ag_fl[(PCB).ag_ap] - 1); | |
1565 (PCB).ag_min_depth = (PCB).ag_tmp_depth; | |
1566 return ag_action_4_proc(); | |
1567 } | |
1568 | |
1569 static int ag_action_6_e_proc(void) { | |
1570 ag_check_depth(ag_fl[(PCB).ag_ap]); | |
1571 return ag_action_6_proc(); | |
1572 } | |
1573 | |
1574 static int ag_action_11_e_proc(void) { | |
1575 return ag_action_10_proc(); | |
1576 } | |
1577 | |
1578 static int (*ag_r_procs_error[])(void) = { | |
1579 ag_action_1_r_proc, | |
1580 ag_action_2_r_proc, | |
1581 ag_action_3_er_proc, | |
1582 ag_action_3_er_proc | |
1583 }; | |
1584 | |
1585 static int (*ag_s_procs_error[])(void) = { | |
1586 ag_action_1_s_proc, | |
1587 ag_action_2_r_proc, | |
1588 ag_action_3_er_proc, | |
1589 ag_action_3_er_proc | |
1590 }; | |
1591 | |
1592 static int (*ag_gt_procs_error[])(void) = { | |
1593 ag_action_1_proc, | |
1594 ag_action_2_e_proc, | |
1595 ag_action_4_e_proc, | |
1596 ag_action_4_e_proc, | |
1597 ag_action_6_e_proc, | |
1598 ag_action_6_e_proc, | |
1599 ag_action_7_proc, | |
1600 ag_action_8_proc, | |
1601 ag_action_9_proc, | |
1602 ag_action_10_proc, | |
1603 ag_action_11_e_proc, | |
1604 ag_action_8_proc | |
1605 }; | |
1606 | |
1607 static void ag_set_error_procs(void) { | |
1608 (PCB).gt_procs = ag_gt_procs_error; | |
1609 (PCB).r_procs = ag_r_procs_error; | |
1610 (PCB).s_procs = ag_s_procs_error; | |
1611 } | |
1612 | |
1613 | |
1614 void init_evalKernel(void) { | |
1615 (PCB).la_ptr = (PCB).pointer; | |
1616 (PCB).gt_procs = ag_gt_procs_scan; | |
1617 (PCB).r_procs = ag_r_procs_scan; | |
1618 (PCB).s_procs = ag_s_procs_scan; | |
1619 (PCB).ag_error_depth = (PCB).ag_min_depth = (PCB).ag_tmp_depth = 0; | |
1620 (PCB).ag_resynch_active = 0; | |
1621 (PCB).ss[0] = (PCB).sn = (PCB).ssx = 0; | |
1622 (PCB).exit_flag = AG_RUNNING_CODE; | |
1623 (PCB).line = FIRST_LINE; | |
1624 (PCB).column = FIRST_COLUMN; | |
1625 (PCB).btsx = 0, (PCB).drt = -1; | |
1626 } | |
1627 | |
1628 void evalKernel(void) { | |
1629 init_evalKernel(); | |
1630 (PCB).exit_flag = AG_RUNNING_CODE; | |
1631 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
1632 unsigned ag_t1 = ag_sbt[(PCB).sn]; | |
1633 if (ag_tstt[ag_t1]) { | |
1634 unsigned ag_t2 = ag_sbe[(PCB).sn] - 1; | |
1635 (PCB).token_number = (evalKernel_token_type) AG_TCV(INPUT_CODE(*(PCB).la_ptr)); | |
1636 (PCB).la_ptr++; | |
1637 if (ag_key_index[(PCB).sn]) { | |
1638 unsigned ag_k = ag_key_index[(PCB).sn]; | |
1639 int ag_ch = CONVERT_CASE(INPUT_CODE(*(PCB).pointer)); | |
1640 if (ag_ch <= 255) { | |
1641 while (ag_key_ch[ag_k] < ag_ch) ag_k++; | |
1642 if (ag_key_ch[ag_k] == ag_ch) ag_get_key_word(ag_k); | |
1643 } | |
1644 } | |
1645 do { | |
1646 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
1647 if (ag_tstt[ag_tx] > (unsigned char)(PCB).token_number) | |
1648 ag_t1 = ag_tx + 1; | |
1649 else ag_t2 = ag_tx; | |
1650 } while (ag_t1 < ag_t2); | |
1651 if (ag_tstt[ag_t1] != (unsigned char)(PCB).token_number) | |
1652 ag_t1 = ag_sbe[(PCB).sn]; | |
1653 } | |
1654 (PCB).ag_ap = ag_pstt[ag_t1]; | |
1655 (*(PCB).gt_procs[ag_astt[ag_t1]])(); | |
1656 } | |
1657 } | |
1658 | |
1659 |