Mercurial > ~dholland > hg > ag > index.cgi
comparison tests/agcl/ffcalc/good/ffcm-b.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 /* FOUR FUNCTION CALCULATOR: FFCALC.SYN */ | |
2 /* | |
3 * AnaGram, A System for Syntax Directed Programming | |
4 * File generated by: ... | |
5 * | |
6 * AnaGram Parsing Engine | |
7 * Copyright 1993-2002 Parsifal Software. All Rights Reserved. | |
8 * | |
9 * This software is provided 'as-is', without any express or implied | |
10 * warranty. In no event will the authors be held liable for any damages | |
11 * arising from the use of this software. | |
12 * | |
13 * Permission is granted to anyone to use this software for any purpose, | |
14 * including commercial applications, and to alter it and redistribute it | |
15 * freely, subject to the following restrictions: | |
16 * | |
17 * 1. The origin of this software must not be misrepresented; you must not | |
18 * claim that you wrote the original software. If you use this software | |
19 * in a product, an acknowledgment in the product documentation would be | |
20 * appreciated but is not required. | |
21 * 2. Altered source versions must be plainly marked as such, and must not be | |
22 * misrepresented as being the original software. | |
23 * 3. This notice may not be removed or altered from any source distribution. | |
24 */ | |
25 | |
26 #ifndef FFCM-B_H | |
27 #include "ffcm-b.h" | |
28 #endif | |
29 | |
30 #ifndef FFCM-B_H | |
31 #error Mismatched header file | |
32 #endif | |
33 | |
34 #include <ctype.h> | |
35 #include <stdio.h> | |
36 | |
37 #define RULE_CONTEXT (&((PCB).cs[(PCB).ssx])) | |
38 #define ERROR_CONTEXT ((PCB).cs[(PCB).error_frame_ssx]) | |
39 #define CONTEXT ((PCB).cs[(PCB).ssx]) | |
40 | |
41 | |
42 | |
43 ffcm-b_pcb_type ffcm-b_pcb; | |
44 #define PCB ffcm-b_pcb | |
45 | |
46 /* Line -, ffcm-b.syn */ | |
47 /* -- EMBEDDED C ---------------------------------- */ | |
48 double value[64]; /* registers */ | |
49 void main(void) { | |
50 ffcalc(); | |
51 } | |
52 | |
53 #ifndef CONVERT_CASE | |
54 | |
55 static const char agCaseTable[31] = { | |
56 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, | |
57 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, | |
58 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0, | |
59 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 | |
60 }; | |
61 | |
62 static int agConvertCase(int c) { | |
63 if (c >= 'a' && c <= 'z') return c ^= 0x20; | |
64 if (c >= 0xe0 && c < 0xff) c ^= agCaseTable[c-0xe0]; | |
65 return c; | |
66 } | |
67 | |
68 #define CONVERT_CASE(c) agConvertCase(c) | |
69 | |
70 #endif | |
71 | |
72 | |
73 #ifndef TAB_SPACING | |
74 #define TAB_SPACING 8 | |
75 #endif | |
76 | |
77 #define ag_rp_1(x) (printf("%g\n",x)) | |
78 | |
79 static void ag_rp_2(double n, double x) { | |
80 /* Line -, ffcm-b.syn */ | |
81 printf("%c = %g\n",n+'A',value[n]=x); | |
82 } | |
83 | |
84 #define ag_rp_3(x, t) (x+t) | |
85 | |
86 #define ag_rp_4(x, t) (x-t) | |
87 | |
88 #define ag_rp_5(t, f) (t*f) | |
89 | |
90 #define ag_rp_6(t, f) (t/f) | |
91 | |
92 #define ag_rp_7(n) (value[n]) | |
93 | |
94 #define ag_rp_8(x) (x) | |
95 | |
96 #define ag_rp_9(f) (-f) | |
97 | |
98 #define ag_rp_10(i, f) (i+f) | |
99 | |
100 #define ag_rp_11(f) (f) | |
101 | |
102 #define ag_rp_12(d) (d-'0') | |
103 | |
104 #define ag_rp_13(x, d) (10*x + d-'0') | |
105 | |
106 #define ag_rp_14(d) ((d-'0')/10.) | |
107 | |
108 #define ag_rp_15(d, f) ((d-'0' + f)/10.) | |
109 | |
110 #define ag_rp_16(c) (n_chars = 0, name[n_chars++]=c) | |
111 | |
112 #define ag_rp_17(c) (name[n_chars++]=c) | |
113 | |
114 | |
115 #define READ_COUNTS | |
116 #define WRITE_COUNTS | |
117 #undef V | |
118 #define V(i,t) (*t (&(PCB).vs[(PCB).ssx + i])) | |
119 #undef VS | |
120 #define VS(i) (PCB).vs[(PCB).ssx + i] | |
121 | |
122 #ifndef GET_CONTEXT | |
123 #define GET_CONTEXT CONTEXT = (PCB).input_context | |
124 #endif | |
125 | |
126 typedef enum { | |
127 ag_action_1, | |
128 ag_action_2, | |
129 ag_action_3, | |
130 ag_action_4, | |
131 ag_action_5, | |
132 ag_action_6, | |
133 ag_action_7, | |
134 ag_action_8, | |
135 ag_action_9, | |
136 ag_action_10, | |
137 ag_action_11, | |
138 ag_action_12 | |
139 } ag_parser_action; | |
140 | |
141 | |
142 #ifndef NULL_VALUE_INITIALIZER | |
143 #define NULL_VALUE_INITIALIZER = { 0 } | |
144 #endif | |
145 | |
146 static ffcm-b_vs_type const ag_null_value NULL_VALUE_INITIALIZER; | |
147 | |
148 static const unsigned char ag_rpx[] = { | |
149 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 0, 0, 3, 4, 0, 5, | |
150 6, 7, 0, 8, 9, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 11, 12, 13, | |
151 14, 15, 16, 17 | |
152 }; | |
153 | |
154 static const unsigned char ag_key_itt[] = { | |
155 0 | |
156 }; | |
157 | |
158 static const unsigned short ag_key_pt[] = { | |
159 0 | |
160 }; | |
161 | |
162 static const unsigned char ag_key_ch[] = { | |
163 0, 47, 65,255, 42,255, 47, 65, 84,255, 65,255, 47, 84,255, 47,255, 84, | |
164 255 | |
165 }; | |
166 | |
167 static const unsigned char ag_key_act[] = { | |
168 0,3,3,4,3,4,3,3,3,4,3,4,3,3,4,3,4,3,4 | |
169 }; | |
170 | |
171 static const unsigned char ag_key_parm[] = { | |
172 0, 26, 45, 0, 30, 0, 26, 45, 44, 0, 45, 0, 26, 44, 0, 26, 0, 44, | |
173 0 | |
174 }; | |
175 | |
176 static const unsigned char ag_key_jmp[] = { | |
177 0, 0, 2, 0, 5, 0, 7, 9, 12, 0, 14, 0, 17, 19, 0, 21, 0, 23, | |
178 0 | |
179 }; | |
180 | |
181 static const unsigned char ag_key_index[] = { | |
182 1, 4, 6, 10, 4, 4, 0, 12, 15, 15, 12, 0, 0, 15, 15, 17, 0, 0, | |
183 0, 0, 10, 0, 12, 12, 0, 15, 0, 15, 0, 17, 15, 0, 0, 15, 0, 1, | |
184 12, 15, 0, 0, 17, 17 | |
185 }; | |
186 | |
187 static const unsigned char ag_key_ends[] = { | |
188 42,0, 68,68,0, 47,0, 42,0, 68,68,0, 79,0, 68,68,0, 42,0, | |
189 79,0, 42,0, 79,0, | |
190 }; | |
191 #define AG_TCV(x) (((int)(x) >= -1 && (int)(x) <= 255) ? ag_tcv[(x) + 1] : 0) | |
192 | |
193 static const unsigned char ag_tcv[] = { | |
194 11, 38, 38, 38, 38, 38, 38, 38, 38, 38, 25, 41, 25, 25, 25, 38, 38, 38, | |
195 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 25, 38, 38, | |
196 38, 38, 38, 38, 38, 52, 51, 48, 46, 38, 47, 32, 49, 35, 35, 35, 35, 35, | |
197 35, 35, 35, 35, 35, 38, 38, 38, 42, 38, 38, 38, 36, 36, 36, 36, 36, 36, | |
198 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, | |
199 36, 36, 38, 38, 38, 38, 38, 38, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, | |
200 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 36, 38, 38, | |
201 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, | |
202 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, | |
203 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, | |
204 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, | |
205 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, | |
206 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, | |
207 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, | |
208 38, 38, 38, 38, 38 | |
209 }; | |
210 | |
211 #ifndef SYNTAX_ERROR | |
212 #define SYNTAX_ERROR fprintf(stderr,"%s, line %d, column %d\n", \ | |
213 (PCB).error_message, (PCB).line, (PCB).column) | |
214 #endif | |
215 | |
216 #ifndef FIRST_LINE | |
217 #define FIRST_LINE 1 | |
218 #endif | |
219 | |
220 #ifndef FIRST_COLUMN | |
221 #define FIRST_COLUMN 1 | |
222 #endif | |
223 | |
224 #ifndef PARSER_STACK_OVERFLOW | |
225 #define PARSER_STACK_OVERFLOW {fprintf(stderr, \ | |
226 "\nParser stack overflow, line %d, column %d\n",\ | |
227 (PCB).line, (PCB).column);} | |
228 #endif | |
229 | |
230 #ifndef REDUCTION_TOKEN_ERROR | |
231 #define REDUCTION_TOKEN_ERROR {fprintf(stderr, \ | |
232 "\nReduction token error, line %d, column %d\n", \ | |
233 (PCB).line, (PCB).column);} | |
234 #endif | |
235 | |
236 | |
237 typedef enum | |
238 {ag_accept_key, ag_set_key, ag_jmp_key, ag_end_key, ag_no_match_key, | |
239 ag_cf_accept_key, ag_cf_set_key, ag_cf_end_key} key_words; | |
240 | |
241 #ifndef GET_INPUT | |
242 #define GET_INPUT ((PCB).input_code = getchar()) | |
243 #endif | |
244 | |
245 | |
246 static int ag_look_ahead(void) { | |
247 if ((PCB).rx < (PCB).fx) { | |
248 return CONVERT_CASE((PCB).lab[(PCB).rx++]); | |
249 } | |
250 GET_INPUT; | |
251 (PCB).fx++; | |
252 return CONVERT_CASE((PCB).lab[(PCB).rx++] = (PCB).input_code); | |
253 } | |
254 | |
255 static void ag_get_key_word(int ag_k) { | |
256 int save_index = (PCB).rx; | |
257 const unsigned char *sp; | |
258 int ag_ch; | |
259 while (1) { | |
260 switch (ag_key_act[ag_k]) { | |
261 case ag_cf_end_key: | |
262 sp = ag_key_ends + ag_key_jmp[ag_k]; | |
263 do { | |
264 if ((ag_ch = *sp++) == 0) { | |
265 int ag_k1 = ag_key_parm[ag_k]; | |
266 int ag_k2 = ag_key_pt[ag_k1]; | |
267 if (ag_key_itt[ag_k2 + ag_look_ahead()]) goto ag_fail; | |
268 (PCB).rx--; | |
269 (PCB).token_number = (ffcm-b_token_type) ag_key_pt[ag_k1 + 1]; | |
270 return; | |
271 } | |
272 } while (ag_look_ahead() == ag_ch); | |
273 goto ag_fail; | |
274 case ag_end_key: | |
275 sp = ag_key_ends + ag_key_jmp[ag_k]; | |
276 do { | |
277 if ((ag_ch = *sp++) == 0) { | |
278 (PCB).token_number = (ffcm-b_token_type) ag_key_parm[ag_k]; | |
279 return; | |
280 } | |
281 } while (ag_look_ahead() == ag_ch); | |
282 case ag_no_match_key: | |
283 ag_fail: | |
284 (PCB).rx = save_index; | |
285 return; | |
286 case ag_cf_set_key: { | |
287 int ag_k1 = ag_key_parm[ag_k]; | |
288 int ag_k2 = ag_key_pt[ag_k1]; | |
289 ag_k = ag_key_jmp[ag_k]; | |
290 if (ag_key_itt[ag_k2 + (ag_ch = ag_look_ahead())]) break; | |
291 save_index = --(PCB).rx; | |
292 (PCB).token_number = (ffcm-b_token_type) ag_key_pt[ag_k1+1]; | |
293 break; | |
294 } | |
295 case ag_set_key: | |
296 save_index = (PCB).rx; | |
297 (PCB).token_number = (ffcm-b_token_type) ag_key_parm[ag_k]; | |
298 case ag_jmp_key: | |
299 ag_k = ag_key_jmp[ag_k]; | |
300 ag_ch = ag_look_ahead(); | |
301 break; | |
302 case ag_accept_key: | |
303 (PCB).token_number = (ffcm-b_token_type) ag_key_parm[ag_k]; | |
304 return; | |
305 case ag_cf_accept_key: { | |
306 int ag_k1 = ag_key_parm[ag_k]; | |
307 int ag_k2 = ag_key_pt[ag_k1]; | |
308 if (ag_key_itt[ag_k2 + ag_look_ahead()]) (PCB).rx = save_index; | |
309 else { | |
310 (PCB).rx--; | |
311 (PCB).token_number = (ffcm-b_token_type) ag_key_pt[ag_k1+1]; | |
312 } | |
313 return; | |
314 } | |
315 default: | |
316 /* not reachable; here to suppress compiler warnings */ | |
317 goto ag_fail; | |
318 } | |
319 if (ag_ch <= 255) while (ag_key_ch[ag_k] < ag_ch) ag_k++; | |
320 if (ag_ch > 255 || ag_key_ch[ag_k] != ag_ch) { | |
321 (PCB).rx = save_index; | |
322 return; | |
323 } | |
324 } | |
325 } | |
326 | |
327 | |
328 #ifndef AG_NEWLINE | |
329 #define AG_NEWLINE 10 | |
330 #endif | |
331 | |
332 #ifndef AG_RETURN | |
333 #define AG_RETURN 13 | |
334 #endif | |
335 | |
336 #ifndef AG_FORMFEED | |
337 #define AG_FORMFEED 12 | |
338 #endif | |
339 | |
340 #ifndef AG_TABCHAR | |
341 #define AG_TABCHAR 9 | |
342 #endif | |
343 | |
344 static void ag_track(void) { | |
345 int ag_k = 0; | |
346 while (ag_k < (PCB).rx) { | |
347 int ag_ch = (PCB).lab[ag_k++]; | |
348 switch (ag_ch) { | |
349 case AG_NEWLINE: | |
350 (PCB).column = 1, (PCB).line++; | |
351 case AG_RETURN: | |
352 case AG_FORMFEED: | |
353 break; | |
354 case AG_TABCHAR: | |
355 (PCB).column += (TAB_SPACING) - ((PCB).column - 1) % (TAB_SPACING); | |
356 break; | |
357 default: | |
358 (PCB).column++; | |
359 } | |
360 } | |
361 ag_k = 0; | |
362 while ((PCB).rx < (PCB).fx) (PCB).lab[ag_k++] = (PCB).lab[(PCB).rx++]; | |
363 (PCB).fx = ag_k; | |
364 (PCB).rx = 0; | |
365 } | |
366 | |
367 | |
368 static void ag_prot(void) { | |
369 int ag_k; | |
370 ag_k = 128 - ++(PCB).btsx; | |
371 if (ag_k <= (PCB).ssx) { | |
372 (PCB).exit_flag = AG_STACK_ERROR_CODE; | |
373 PARSER_STACK_OVERFLOW; | |
374 return; | |
375 } | |
376 (PCB).bts[(PCB).btsx] = (PCB).sn; | |
377 (PCB).bts[ag_k] = (PCB).ssx; | |
378 (PCB).vs[ag_k] = (PCB).vs[(PCB).ssx]; | |
379 (PCB).ss[ag_k] = (PCB).ss[(PCB).ssx]; | |
380 } | |
381 | |
382 static void ag_undo(void) { | |
383 if ((PCB).drt == -1) return; | |
384 while ((PCB).btsx) { | |
385 int ag_k = 128 - (PCB).btsx; | |
386 (PCB).sn = (PCB).bts[(PCB).btsx--]; | |
387 (PCB).ssx = (PCB).bts[ag_k]; | |
388 (PCB).vs[(PCB).ssx] = (PCB).vs[ag_k]; | |
389 (PCB).ss[(PCB).ssx] = (PCB).ss[ag_k]; | |
390 } | |
391 (PCB).token_number = (ffcm-b_token_type) (PCB).drt; | |
392 (PCB).ssx = (PCB).dssx; | |
393 (PCB).sn = (PCB).dsn; | |
394 (PCB).drt = -1; | |
395 } | |
396 | |
397 | |
398 static const unsigned char ag_tstt[] = { | |
399 52,47,45,41,36,35,32,26,25,11,0,1,39,40, | |
400 52,51,49,48,47,46,42,41,38,36,35,32,30,25,0,28,29, | |
401 26,25,0,1, | |
402 52,47,45,41,36,35,32,16,11,0,2,3,4,5,6,8,9,10,12,14,17,19,20,23,31,43,50, | |
403 52,51,49,48,47,46,42,41,38,36,35,32,25,0, | |
404 30,0, | |
405 35,0,33, | |
406 51,49,48,47,46,44,41,35,32,26,25,0,34, | |
407 52,47,36,35,32,26,25,0,1,39,40, | |
408 52,47,36,35,32,26,25,0,1,39,40, | |
409 51,49,48,47,46,44,41,26,25,0,1,39,40, | |
410 52,47,36,35,32,0,2,3,19,20,23,31,43,50, | |
411 52,47,36,35,32,0,2,3,12,17,19,20,23,31,43,50, | |
412 52,47,36,35,32,26,25,0,1,39,40, | |
413 51,49,48,47,46,42,41,36,35,26,25,0,1,39,40, | |
414 49,48,0,21,22, | |
415 52,47,36,35,32,0,2,3,12,17,19,20,23,31,43,50, | |
416 49,48,47,46,42,41,0,13, | |
417 47,46,41,0,18,19, | |
418 41,0,7, | |
419 52,47,45,41,36,35,32,16,11,0,2,3,5,6,8,12,14,17,19,20,23,31,43,50, | |
420 11,0, | |
421 51,49,48,47,46,44,41,35,26,25,0,33, | |
422 35,0,33, | |
423 51,47,46,0,18,19,24, | |
424 52,47,36,35,32,26,25,0,1,39,40, | |
425 52,47,36,35,32,0,2,3,19,20,23,31,43,50, | |
426 52,47,36,35,32,26,25,0,1,39,40, | |
427 52,47,36,35,32,0,2,3,19,20,23,31,43,50, | |
428 47,46,44,0,15,18,19, | |
429 52,47,36,35,32,26,25,0,1,39,40, | |
430 52,47,36,35,32,0,2,3,12,17,19,20,23,31,43,50, | |
431 52,47,36,35,32,0,2,3,17,19,20,23,31,43,50, | |
432 52,47,36,35,32,26,25,0,1,39,40, | |
433 52,47,36,35,32,0,2,3,17,19,20,23,31,43,50, | |
434 52,47,45,41,36,35,32,26,25,11,0,1,39,40, | |
435 51,49,48,47,46,44,41,26,25,0,1,39,40, | |
436 36,26,25,0,1,39,40, | |
437 36,0,3,43, | |
438 47,46,41,0,18,19, | |
439 51,49,48,47,46,44,41,0,21,22, | |
440 51,49,48,47,46,44,41,0,21,22, | |
441 | |
442 }; | |
443 | |
444 | |
445 static unsigned const char ag_astt[460] = { | |
446 8,8,8,8,8,8,8,1,1,8,7,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,8,1,7,1,1,1,9,5,3,1,1, | |
447 1,8,2,2,1,1,8,7,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,9,9,9,9,9,9,9,9,9,9,9,9, | |
448 9,5,3,7,1,7,2,5,5,5,5,5,5,5,10,1,5,5,7,3,5,5,5,5,5,1,1,7,1,1,3,5,5,5,5,5,1, | |
449 1,7,1,1,3,5,5,5,5,5,5,5,1,1,7,1,1,3,1,1,2,2,1,7,2,2,1,2,1,1,1,1,1,1,2,2,1, | |
450 7,1,2,1,1,1,1,1,1,1,1,5,5,5,5,5,1,1,7,1,1,3,5,5,5,5,5,5,5,10,10,1,1,7,1,1, | |
451 3,1,1,5,1,1,1,1,2,2,1,7,1,2,1,1,1,1,1,1,1,1,4,4,4,4,1,4,7,1,1,1,4,7,1,1,1, | |
452 7,3,1,1,1,8,2,2,1,1,5,7,1,1,1,1,3,1,1,1,1,1,1,1,1,1,3,7,4,4,4,4,4,4,4,1,4, | |
453 4,7,2,1,5,2,1,1,1,7,1,1,2,5,5,5,5,5,1,1,7,1,1,3,1,1,2,2,1,7,2,2,1,2,1,1,1, | |
454 1,5,5,5,5,5,1,1,7,1,1,3,1,1,2,2,1,7,2,2,1,2,1,1,1,1,1,1,1,7,1,1,1,5,5,5,5, | |
455 5,1,1,7,1,1,3,1,1,2,2,1,7,1,2,1,1,1,1,1,1,1,1,1,1,2,2,1,7,1,2,1,1,1,1,1,1, | |
456 1,5,5,5,5,5,1,1,7,1,1,3,1,1,2,2,1,7,1,2,1,1,1,1,1,1,1,5,5,5,5,5,5,5,1,1,5, | |
457 7,1,1,3,5,5,5,5,5,5,5,1,1,7,1,1,3,5,1,1,7,1,1,3,2,7,3,1,1,1,4,7,1,1,4,1,1, | |
458 4,4,4,4,7,1,1,4,1,1,4,4,4,4,7,1,1 | |
459 }; | |
460 | |
461 | |
462 static const unsigned char ag_pstt[] = { | |
463 3,3,3,3,3,3,3,1,2,3,0,2,2,3, | |
464 4,4,4,4,4,4,4,4,4,4,4,4,5,4,1,4,5, | |
465 1,56,58,56, | |
466 9,8,13,19,38,34,6,19,21,3,15,17,0,19,19,20,20,21,18,16,15,11,15,12,7,14,10, | |
467 25,25,25,25,25,25,25,25,25,25,25,25,25,27, | |
468 28,5, | |
469 22,6,33, | |
470 30,30,30,30,30,30,30,35,23,30,30,7,32, | |
471 57,57,57,57,57,1,2,8,2,2,65, | |
472 57,57,57,57,57,1,2,9,2,2,70, | |
473 57,57,57,57,57,57,57,1,2,10,2,2,68, | |
474 9,8,38,34,6,11,22,19,11,22,12,7,14,10, | |
475 9,8,38,34,6,12,15,19,24,15,11,15,12,7,14,10, | |
476 57,57,57,57,57,1,2,13,2,2,63, | |
477 57,57,57,57,57,57,57,39,39,1,2,14,2,2,61, | |
478 25,27,13,28,26, | |
479 9,8,38,34,6,16,15,19,29,15,11,15,12,7,14,10, | |
480 19,19,19,19,30,19,17,31, | |
481 8,33,9,18,34,32, | |
482 35,19,3, | |
483 9,8,13,19,38,34,6,19,7,20,15,17,19,19,5,18,16,15,11,15,12,7,14,10, | |
484 8,21, | |
485 36,36,36,36,36,36,36,22,36,36,22,37, | |
486 22,31,29, | |
487 36,8,33,24,34,32,21, | |
488 57,57,57,57,57,1,2,25,2,2,67, | |
489 9,8,38,34,6,26,18,19,11,18,12,7,14,10, | |
490 57,57,57,57,57,1,2,27,2,2,66, | |
491 9,8,38,34,6,28,17,19,11,17,12,7,14,10, | |
492 8,33,37,29,38,34,32, | |
493 57,57,57,57,57,1,2,30,2,2,60, | |
494 9,8,38,34,6,31,15,19,39,15,11,15,12,7,14,10, | |
495 9,8,38,34,6,32,40,19,40,11,40,12,7,14,10, | |
496 57,57,57,57,57,1,2,33,2,2,64, | |
497 9,8,38,34,6,34,41,19,41,11,41,12,7,14,10, | |
498 57,57,57,57,57,57,57,1,2,57,35,2,2,59, | |
499 57,57,57,57,57,57,57,1,2,36,2,2,69, | |
500 57,1,2,37,2,2,62, | |
501 38,38,11,14, | |
502 8,33,10,39,34,32, | |
503 15,25,27,15,15,15,15,40,28,26, | |
504 14,25,27,14,14,14,14,41,28,26, | |
505 | |
506 }; | |
507 | |
508 | |
509 static const unsigned short ag_sbt[] = { | |
510 0, 14, 31, 35, 62, 76, 78, 81, 94, 105, 116, 129, 143, 159, | |
511 170, 185, 190, 206, 214, 220, 223, 247, 249, 261, 264, 271, 282, 296, | |
512 307, 321, 328, 339, 355, 370, 381, 396, 410, 423, 430, 434, 440, 450, | |
513 460 | |
514 }; | |
515 | |
516 | |
517 static const unsigned short ag_sbe[] = { | |
518 10, 28, 33, 44, 75, 77, 79, 92, 101, 112, 125, 134, 148, 166, | |
519 181, 187, 195, 212, 217, 221, 232, 248, 259, 262, 267, 278, 287, 303, | |
520 312, 324, 335, 344, 360, 377, 386, 406, 419, 426, 431, 437, 447, 457, 460 | |
521 }; | |
522 | |
523 | |
524 static const unsigned char ag_fl[] = { | |
525 2,0,1,2,1,2,0,1,2,1,3,4,1,1,3,3,1,3,3,1,1,3,2,1,1,2,0,1,3,3,0,1,2,2,1, | |
526 2,1,2,1,2,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, | |
527 2 | |
528 }; | |
529 | |
530 static const unsigned char ag_ptt[] = { | |
531 0, 6, 6, 8, 9, 9, 10, 10, 4, 5, 5, 5, 5, 12, 12, 12, 17, 17, | |
532 17, 20, 20, 20, 20, 1, 28, 28, 29, 29, 1, 50, 34, 34, 50, 50, 31, 31, | |
533 33, 33, 43, 43, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 37, | |
534 37, 39, 39, 40, 40, 7, 13, 3, 15, 14, 18, 19, 21, 22, 2, 24, 23 | |
535 }; | |
536 | |
537 | |
538 static void ag_ra(void) | |
539 { | |
540 switch(ag_rpx[(PCB).ag_ap]) { | |
541 case 1: ag_rp_1(V(0,(double *))); break; | |
542 case 2: ag_rp_2(V(0,(double *)), V(2,(double *))); break; | |
543 case 3: V(0,(double *)) = ag_rp_3(V(0,(double *)), V(2,(double *))); break; | |
544 case 4: V(0,(double *)) = ag_rp_4(V(0,(double *)), V(2,(double *))); break; | |
545 case 5: V(0,(double *)) = ag_rp_5(V(0,(double *)), V(2,(double *))); break; | |
546 case 6: V(0,(double *)) = ag_rp_6(V(0,(double *)), V(2,(double *))); break; | |
547 case 7: V(0,(double *)) = ag_rp_7(V(0,(double *))); break; | |
548 case 8: V(0,(double *)) = ag_rp_8(V(1,(double *))); break; | |
549 case 9: V(0,(double *)) = ag_rp_9(V(1,(double *))); break; | |
550 case 10: V(0,(double *)) = ag_rp_10(V(0,(double *)), V(2,(double *))); break; | |
551 case 11: V(0,(double *)) = ag_rp_11(V(1,(double *))); break; | |
552 case 12: V(0,(double *)) = ag_rp_12(V(0,(int *))); break; | |
553 case 13: V(0,(double *)) = ag_rp_13(V(0,(double *)), V(1,(int *))); break; | |
554 case 14: V(0,(double *)) = ag_rp_14(V(0,(int *))); break; | |
555 case 15: V(0,(double *)) = ag_rp_15(V(0,(int *)), V(1,(double *))); break; | |
556 case 16: V(0,(double *)) = ag_rp_16(V(0,(int *))); break; | |
557 case 17: V(0,(double *)) = ag_rp_17(V(1,(int *))); break; | |
558 } | |
559 } | |
560 | |
561 #define TOKEN_NAMES ffcm-b_token_names | |
562 const char *const ffcm-b_token_names[53] = { | |
563 "calculator", | |
564 "white space", | |
565 "real", | |
566 "name", | |
567 "calculator", | |
568 "calculation", | |
569 "", | |
570 "'\\n'", | |
571 "", | |
572 "", | |
573 "", | |
574 "eof", | |
575 "expression", | |
576 "'='", | |
577 "\"ADD\"", | |
578 "\"TO\"", | |
579 "error", | |
580 "term", | |
581 "'+'", | |
582 "'-'", | |
583 "factor", | |
584 "'*'", | |
585 "'/'", | |
586 "'('", | |
587 "')'", | |
588 "", | |
589 "\"/*\"", | |
590 "", | |
591 "", | |
592 "", | |
593 "\"*/\"", | |
594 "integer part", | |
595 "'.'", | |
596 "fraction part", | |
597 "", | |
598 "digit", | |
599 "letter", | |
600 "", | |
601 "", | |
602 "", | |
603 "", | |
604 "'\\n'", | |
605 "'='", | |
606 "name", | |
607 "\"TO\"", | |
608 "\"ADD\"", | |
609 "'+'", | |
610 "'-'", | |
611 "'*'", | |
612 "'/'", | |
613 "real", | |
614 "')'", | |
615 "'('", | |
616 | |
617 }; | |
618 | |
619 #ifndef MISSING_FORMAT | |
620 #define MISSING_FORMAT "Missing %s" | |
621 #endif | |
622 #ifndef UNEXPECTED_FORMAT | |
623 #define UNEXPECTED_FORMAT "Unexpected %s" | |
624 #endif | |
625 #ifndef UNNAMED_TOKEN | |
626 #define UNNAMED_TOKEN "input" | |
627 #endif | |
628 | |
629 | |
630 static void ag_diagnose(void) { | |
631 int ag_snd = (PCB).sn; | |
632 int ag_k = ag_sbt[ag_snd]; | |
633 | |
634 if (*TOKEN_NAMES[ag_tstt[ag_k]] && ag_astt[ag_k + 1] == ag_action_8) { | |
635 sprintf((PCB).ag_msg, MISSING_FORMAT, TOKEN_NAMES[ag_tstt[ag_k]]); | |
636 } | |
637 else if (ag_astt[ag_sbe[(PCB).sn]] == ag_action_8 | |
638 && (ag_k = (int) ag_sbe[(PCB).sn] + 1) == (int) ag_sbt[(PCB).sn+1] - 1 | |
639 && *TOKEN_NAMES[ag_tstt[ag_k]]) { | |
640 sprintf((PCB).ag_msg, MISSING_FORMAT, TOKEN_NAMES[ag_tstt[ag_k]]); | |
641 } | |
642 else if ((PCB).token_number && *TOKEN_NAMES[(PCB).token_number]) { | |
643 sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, TOKEN_NAMES[(PCB).token_number]); | |
644 } | |
645 else if (isprint((*(PCB).lab)) && (*(PCB).lab) != '\\') { | |
646 char buf[20]; | |
647 sprintf(buf, "\'%c\'", (char) (*(PCB).lab)); | |
648 sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, buf); | |
649 } | |
650 else sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, UNNAMED_TOKEN); | |
651 (PCB).error_message = (PCB).ag_msg; | |
652 | |
653 | |
654 } | |
655 static int ag_action_1_r_proc(void); | |
656 static int ag_action_2_r_proc(void); | |
657 static int ag_action_3_r_proc(void); | |
658 static int ag_action_4_r_proc(void); | |
659 static int ag_action_1_s_proc(void); | |
660 static int ag_action_3_s_proc(void); | |
661 static int ag_action_1_proc(void); | |
662 static int ag_action_2_proc(void); | |
663 static int ag_action_3_proc(void); | |
664 static int ag_action_4_proc(void); | |
665 static int ag_action_5_proc(void); | |
666 static int ag_action_6_proc(void); | |
667 static int ag_action_7_proc(void); | |
668 static int ag_action_8_proc(void); | |
669 static int ag_action_9_proc(void); | |
670 static int ag_action_10_proc(void); | |
671 static int ag_action_11_proc(void); | |
672 static int ag_action_8_proc(void); | |
673 | |
674 | |
675 static int (*const ag_r_procs_scan[])(void) = { | |
676 ag_action_1_r_proc, | |
677 ag_action_2_r_proc, | |
678 ag_action_3_r_proc, | |
679 ag_action_4_r_proc | |
680 }; | |
681 | |
682 static int (*const ag_s_procs_scan[])(void) = { | |
683 ag_action_1_s_proc, | |
684 ag_action_2_r_proc, | |
685 ag_action_3_s_proc, | |
686 ag_action_4_r_proc | |
687 }; | |
688 | |
689 static int (*const ag_gt_procs_scan[])(void) = { | |
690 ag_action_1_proc, | |
691 ag_action_2_proc, | |
692 ag_action_3_proc, | |
693 ag_action_4_proc, | |
694 ag_action_5_proc, | |
695 ag_action_6_proc, | |
696 ag_action_7_proc, | |
697 ag_action_8_proc, | |
698 ag_action_9_proc, | |
699 ag_action_10_proc, | |
700 ag_action_11_proc, | |
701 ag_action_8_proc | |
702 }; | |
703 | |
704 | |
705 static int ag_action_1_er_proc(void); | |
706 static int ag_action_2_er_proc(void); | |
707 static int ag_action_3_er_proc(void); | |
708 static int ag_action_4_er_proc(void); | |
709 | |
710 static int (*const ag_er_procs_scan[])(void) = { | |
711 ag_action_1_er_proc, | |
712 ag_action_2_er_proc, | |
713 ag_action_3_er_proc, | |
714 ag_action_4_er_proc | |
715 }; | |
716 | |
717 | |
718 static void ag_error_resynch(void) { | |
719 int ag_k; | |
720 int ag_ssx = (PCB).ssx; | |
721 | |
722 ag_diagnose(); | |
723 SYNTAX_ERROR; | |
724 if ((PCB).exit_flag != AG_RUNNING_CODE) return; | |
725 while (1) { | |
726 ag_k = ag_sbt[(PCB).sn]; | |
727 while (ag_tstt[ag_k] != 16 && ag_tstt[ag_k]) ag_k++; | |
728 if (ag_tstt[ag_k] || (PCB).ssx == 0) break; | |
729 (PCB).sn = (PCB).ss[--(PCB).ssx]; | |
730 } | |
731 if (ag_tstt[ag_k] == 0) { | |
732 (PCB).sn = PCB.ss[(PCB).ssx = ag_ssx]; | |
733 (PCB).exit_flag = AG_SYNTAX_ERROR_CODE; | |
734 return; | |
735 } | |
736 ag_k = ag_sbt[(PCB).sn]; | |
737 while (ag_tstt[ag_k] != 16 && ag_tstt[ag_k]) ag_k++; | |
738 (PCB).ag_ap = ag_pstt[ag_k]; | |
739 (ag_er_procs_scan[ag_astt[ag_k]])(); | |
740 while (1) { | |
741 ag_k = ag_sbt[(PCB).sn]; | |
742 while (ag_tstt[ag_k] != (unsigned char) (PCB).token_number && ag_tstt[ag_k]) | |
743 ag_k++; | |
744 if (ag_tstt[ag_k] && ag_astt[ag_k] != ag_action_10) break; | |
745 if ((PCB).token_number == 11) | |
746 {(PCB).exit_flag = AG_SYNTAX_ERROR_CODE; return;} | |
747 {(PCB).rx = 1; ag_track();} | |
748 if ((PCB).rx < (PCB).fx) { | |
749 (PCB).input_code = (PCB).lab[(PCB).rx++]; | |
750 (PCB).token_number = (ffcm-b_token_type) AG_TCV((PCB).input_code);} | |
751 else { | |
752 GET_INPUT; | |
753 (PCB).lab[(PCB).fx++] = (PCB).input_code; | |
754 (PCB).token_number = (ffcm-b_token_type) AG_TCV((PCB).input_code); | |
755 (PCB).rx++; | |
756 } | |
757 if (ag_key_index[(PCB).sn]) { | |
758 unsigned ag_k = ag_key_index[(PCB).sn]; | |
759 int ag_ch = CONVERT_CASE((PCB).input_code); | |
760 if (ag_ch < 255) { | |
761 while (ag_key_ch[ag_k] < ag_ch) ag_k++; | |
762 if (ag_key_ch[ag_k] == ag_ch) ag_get_key_word(ag_k); | |
763 } | |
764 } | |
765 } | |
766 (PCB).rx = 0; | |
767 } | |
768 | |
769 | |
770 static int ag_action_10_proc(void) { | |
771 int ag_t = (PCB).token_number; | |
772 (PCB).btsx = 0, (PCB).drt = -1; | |
773 do { | |
774 ag_track(); | |
775 if ((PCB).rx < (PCB).fx) { | |
776 (PCB).input_code = (PCB).lab[(PCB).rx++]; | |
777 (PCB).token_number = (ffcm-b_token_type) AG_TCV((PCB).input_code);} | |
778 else { | |
779 GET_INPUT; | |
780 (PCB).lab[(PCB).fx++] = (PCB).input_code; | |
781 (PCB).token_number = (ffcm-b_token_type) AG_TCV((PCB).input_code); | |
782 (PCB).rx++; | |
783 } | |
784 if (ag_key_index[(PCB).sn]) { | |
785 unsigned ag_k = ag_key_index[(PCB).sn]; | |
786 int ag_ch = CONVERT_CASE((PCB).input_code); | |
787 if (ag_ch < 255) { | |
788 while (ag_key_ch[ag_k] < ag_ch) ag_k++; | |
789 if (ag_key_ch[ag_k] == ag_ch) ag_get_key_word(ag_k); | |
790 } | |
791 } | |
792 } while ((PCB).token_number == (ffcm-b_token_type) ag_t); | |
793 (PCB).rx = 0; | |
794 return 1; | |
795 } | |
796 | |
797 static int ag_action_11_proc(void) { | |
798 int ag_t = (PCB).token_number; | |
799 | |
800 (PCB).btsx = 0, (PCB).drt = -1; | |
801 do { | |
802 (*(int *) &(PCB).vs[(PCB).ssx]) = *(PCB).lab; | |
803 (PCB).ssx--; | |
804 ag_track(); | |
805 ag_ra(); | |
806 if ((PCB).exit_flag != AG_RUNNING_CODE) return 0; | |
807 (PCB).ssx++; | |
808 if ((PCB).rx < (PCB).fx) { | |
809 (PCB).input_code = (PCB).lab[(PCB).rx++]; | |
810 (PCB).token_number = (ffcm-b_token_type) AG_TCV((PCB).input_code);} | |
811 else { | |
812 GET_INPUT; | |
813 (PCB).lab[(PCB).fx++] = (PCB).input_code; | |
814 (PCB).token_number = (ffcm-b_token_type) AG_TCV((PCB).input_code); | |
815 (PCB).rx++; | |
816 } | |
817 if (ag_key_index[(PCB).sn]) { | |
818 unsigned ag_k = ag_key_index[(PCB).sn]; | |
819 int ag_ch = CONVERT_CASE((PCB).input_code); | |
820 if (ag_ch < 255) { | |
821 while (ag_key_ch[ag_k] < ag_ch) ag_k++; | |
822 if (ag_key_ch[ag_k] == ag_ch) ag_get_key_word(ag_k); | |
823 } | |
824 } | |
825 } | |
826 while ((PCB).token_number == (ffcm-b_token_type) ag_t); | |
827 (PCB).rx = 0; | |
828 return 1; | |
829 } | |
830 | |
831 static int ag_action_3_r_proc(void) { | |
832 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
833 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
834 (PCB).btsx = 0, (PCB).drt = -1; | |
835 (PCB).reduction_token = (ffcm-b_token_type) ag_ptt[(PCB).ag_ap]; | |
836 ag_ra(); | |
837 return (PCB).exit_flag == AG_RUNNING_CODE; | |
838 } | |
839 | |
840 static int ag_action_3_s_proc(void) { | |
841 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
842 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
843 (PCB).btsx = 0, (PCB).drt = -1; | |
844 (PCB).reduction_token = (ffcm-b_token_type) ag_ptt[(PCB).ag_ap]; | |
845 ag_ra(); | |
846 return (PCB).exit_flag == AG_RUNNING_CODE; | |
847 } | |
848 | |
849 static int ag_action_4_r_proc(void) { | |
850 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
851 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
852 (PCB).reduction_token = (ffcm-b_token_type) ag_ptt[(PCB).ag_ap]; | |
853 return 1; | |
854 } | |
855 | |
856 static int ag_action_2_proc(void) { | |
857 (PCB).btsx = 0, (PCB).drt = -1; | |
858 if ((PCB).ssx >= 128) { | |
859 (PCB).exit_flag = AG_STACK_ERROR_CODE; | |
860 PARSER_STACK_OVERFLOW; | |
861 } | |
862 (*(int *) &(PCB).vs[(PCB).ssx]) = *(PCB).lab; | |
863 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
864 (PCB).ssx++; | |
865 (PCB).sn = (PCB).ag_ap; | |
866 ag_track(); | |
867 return 0; | |
868 } | |
869 | |
870 static int ag_action_9_proc(void) { | |
871 if ((PCB).drt == -1) { | |
872 (PCB).drt=(PCB).token_number; | |
873 (PCB).dssx=(PCB).ssx; | |
874 (PCB).dsn=(PCB).sn; | |
875 } | |
876 ag_prot(); | |
877 (PCB).vs[(PCB).ssx] = ag_null_value; | |
878 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
879 (PCB).ssx++; | |
880 (PCB).sn = (PCB).ag_ap; | |
881 (PCB).rx = 0; | |
882 return (PCB).exit_flag == AG_RUNNING_CODE; | |
883 } | |
884 | |
885 static int ag_action_2_r_proc(void) { | |
886 (PCB).ssx++; | |
887 (PCB).sn = (PCB).ag_ap; | |
888 return 0; | |
889 } | |
890 | |
891 static int ag_action_7_proc(void) { | |
892 --(PCB).ssx; | |
893 (PCB).rx = 0; | |
894 (PCB).exit_flag = AG_SUCCESS_CODE; | |
895 return 0; | |
896 } | |
897 | |
898 static int ag_action_1_proc(void) { | |
899 ag_track(); | |
900 (PCB).exit_flag = AG_SUCCESS_CODE; | |
901 return 0; | |
902 } | |
903 | |
904 static int ag_action_1_r_proc(void) { | |
905 (PCB).exit_flag = AG_SUCCESS_CODE; | |
906 return 0; | |
907 } | |
908 | |
909 static int ag_action_1_s_proc(void) { | |
910 (PCB).exit_flag = AG_SUCCESS_CODE; | |
911 return 0; | |
912 } | |
913 | |
914 static int ag_action_4_proc(void) { | |
915 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
916 (PCB).reduction_token = (ffcm-b_token_type) ag_ptt[(PCB).ag_ap]; | |
917 (PCB).btsx = 0, (PCB).drt = -1; | |
918 (*(int *) &(PCB).vs[(PCB).ssx]) = *(PCB).lab; | |
919 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
920 else (PCB).ss[(PCB).ssx] = (PCB).sn; | |
921 ag_track(); | |
922 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
923 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
924 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
925 do { | |
926 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
927 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
928 else ag_t2 = ag_tx; | |
929 } while (ag_t1 < ag_t2); | |
930 (PCB).ag_ap = ag_pstt[ag_t1]; | |
931 if ((ag_s_procs_scan[ag_astt[ag_t1]])() == 0) break; | |
932 } | |
933 return 0; | |
934 } | |
935 | |
936 static int ag_action_3_proc(void) { | |
937 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
938 (PCB).btsx = 0, (PCB).drt = -1; | |
939 (*(int *) &(PCB).vs[(PCB).ssx]) = *(PCB).lab; | |
940 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
941 else (PCB).ss[(PCB).ssx] = (PCB).sn; | |
942 ag_track(); | |
943 (PCB).reduction_token = (ffcm-b_token_type) ag_ptt[(PCB).ag_ap]; | |
944 ag_ra(); | |
945 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
946 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
947 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
948 do { | |
949 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
950 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
951 else ag_t2 = ag_tx; | |
952 } while (ag_t1 < ag_t2); | |
953 (PCB).ag_ap = ag_pstt[ag_t1]; | |
954 if ((ag_s_procs_scan[ag_astt[ag_t1]])() == 0) break; | |
955 } | |
956 return 0; | |
957 } | |
958 | |
959 static int ag_action_8_proc(void) { | |
960 int ag_k = ag_sbt[(PCB).sn]; | |
961 while (ag_tstt[ag_k] != 16 && ag_tstt[ag_k]) ag_k++; | |
962 if (ag_tstt[ag_k] == 0) ag_undo(); | |
963 (PCB).rx = 0; | |
964 ag_error_resynch(); | |
965 return (PCB).exit_flag == AG_RUNNING_CODE; | |
966 } | |
967 | |
968 static int ag_action_5_proc(void) { | |
969 int ag_sd = ag_fl[(PCB).ag_ap]; | |
970 (PCB).btsx = 0, (PCB).drt = -1; | |
971 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
972 else { | |
973 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
974 } | |
975 (PCB).rx = 0; | |
976 (PCB).reduction_token = (ffcm-b_token_type) ag_ptt[(PCB).ag_ap]; | |
977 ag_ra(); | |
978 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
979 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
980 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
981 do { | |
982 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
983 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
984 else ag_t2 = ag_tx; | |
985 } while (ag_t1 < ag_t2); | |
986 (PCB).ag_ap = ag_pstt[ag_t1]; | |
987 if ((ag_r_procs_scan[ag_astt[ag_t1]])() == 0) break; | |
988 } | |
989 return (PCB).exit_flag == AG_RUNNING_CODE; | |
990 } | |
991 | |
992 static int ag_action_6_proc(void) { | |
993 int ag_sd = ag_fl[(PCB).ag_ap]; | |
994 (PCB).reduction_token = (ffcm-b_token_type) ag_ptt[(PCB).ag_ap]; | |
995 if ((PCB).drt == -1) { | |
996 (PCB).drt=(PCB).token_number; | |
997 (PCB).dssx=(PCB).ssx; | |
998 (PCB).dsn=(PCB).sn; | |
999 } | |
1000 if (ag_sd) { | |
1001 (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
1002 } | |
1003 else { | |
1004 ag_prot(); | |
1005 (PCB).vs[(PCB).ssx] = ag_null_value; | |
1006 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
1007 } | |
1008 (PCB).rx = 0; | |
1009 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
1010 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
1011 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
1012 do { | |
1013 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
1014 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
1015 else ag_t2 = ag_tx; | |
1016 } while (ag_t1 < ag_t2); | |
1017 (PCB).ag_ap = ag_pstt[ag_t1]; | |
1018 if ((ag_r_procs_scan[ag_astt[ag_t1]])() == 0) break; | |
1019 } | |
1020 return (PCB).exit_flag == AG_RUNNING_CODE; | |
1021 } | |
1022 | |
1023 | |
1024 static int ag_action_2_er_proc(void) { | |
1025 (PCB).btsx = 0, (PCB).drt = -1; | |
1026 (*(int *) &(PCB).vs[(PCB).ssx]) = *(PCB).lab; | |
1027 (PCB).ssx++; | |
1028 (PCB).sn = (PCB).ag_ap; | |
1029 return 0; | |
1030 } | |
1031 | |
1032 static int ag_action_1_er_proc(void) { | |
1033 (PCB).btsx = 0, (PCB).drt = -1; | |
1034 (PCB).exit_flag = AG_SUCCESS_CODE; | |
1035 return 0; | |
1036 } | |
1037 | |
1038 static int ag_action_4_er_proc(void) { | |
1039 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
1040 (PCB).btsx = 0, (PCB).drt = -1; | |
1041 (PCB).reduction_token = (ffcm-b_token_type) ag_ptt[(PCB).ag_ap]; | |
1042 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
1043 else (PCB).ss[(PCB).ssx] = (PCB).sn; | |
1044 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
1045 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
1046 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
1047 do { | |
1048 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
1049 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
1050 else ag_t2 = ag_tx; | |
1051 } while (ag_t1 < ag_t2); | |
1052 (PCB).ag_ap = ag_pstt[ag_t1]; | |
1053 if ((ag_s_procs_scan[ag_astt[ag_t1]])() == 0) break; | |
1054 } | |
1055 return 0; | |
1056 } | |
1057 | |
1058 static int ag_action_3_er_proc(void) { | |
1059 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
1060 (PCB).btsx = 0, (PCB).drt = -1; | |
1061 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
1062 else (PCB).ss[(PCB).ssx] = (PCB).sn; | |
1063 (PCB).reduction_token = (ffcm-b_token_type) ag_ptt[(PCB).ag_ap]; | |
1064 ag_ra(); | |
1065 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
1066 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
1067 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
1068 do { | |
1069 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
1070 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
1071 else ag_t2 = ag_tx; | |
1072 } while (ag_t1 < ag_t2); | |
1073 (PCB).ag_ap = ag_pstt[ag_t1]; | |
1074 if ((ag_s_procs_scan[ag_astt[ag_t1]])() == 0) break; | |
1075 } | |
1076 return 0; | |
1077 } | |
1078 | |
1079 | |
1080 void init_ffcm-b(void) { | |
1081 (PCB).rx = (PCB).fx = 0; | |
1082 (PCB).ss[0] = (PCB).sn = (PCB).ssx = 0; | |
1083 (PCB).exit_flag = AG_RUNNING_CODE; | |
1084 (PCB).line = FIRST_LINE; | |
1085 (PCB).column = FIRST_COLUMN; | |
1086 (PCB).btsx = 0, (PCB).drt = -1; | |
1087 } | |
1088 | |
1089 void ffcm-b(void) { | |
1090 init_ffcm-b(); | |
1091 (PCB).exit_flag = AG_RUNNING_CODE; | |
1092 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
1093 unsigned ag_t1 = ag_sbt[(PCB).sn]; | |
1094 if (ag_tstt[ag_t1]) { | |
1095 unsigned ag_t2 = ag_sbe[(PCB).sn] - 1; | |
1096 if ((PCB).rx < (PCB).fx) { | |
1097 (PCB).input_code = (PCB).lab[(PCB).rx++]; | |
1098 (PCB).token_number = (ffcm-b_token_type) AG_TCV((PCB).input_code);} | |
1099 else { | |
1100 GET_INPUT; | |
1101 (PCB).lab[(PCB).fx++] = (PCB).input_code; | |
1102 (PCB).token_number = (ffcm-b_token_type) AG_TCV((PCB).input_code); | |
1103 (PCB).rx++; | |
1104 } | |
1105 if (ag_key_index[(PCB).sn]) { | |
1106 unsigned ag_k = ag_key_index[(PCB).sn]; | |
1107 int ag_ch = CONVERT_CASE((PCB).input_code); | |
1108 if (ag_ch < 255) { | |
1109 while (ag_key_ch[ag_k] < ag_ch) ag_k++; | |
1110 if (ag_key_ch[ag_k] == ag_ch) ag_get_key_word(ag_k); | |
1111 } | |
1112 } | |
1113 do { | |
1114 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
1115 if (ag_tstt[ag_tx] > (unsigned char)(PCB).token_number) | |
1116 ag_t1 = ag_tx + 1; | |
1117 else ag_t2 = ag_tx; | |
1118 } while (ag_t1 < ag_t2); | |
1119 if (ag_tstt[ag_t1] != (unsigned char)(PCB).token_number) | |
1120 ag_t1 = ag_sbe[(PCB).sn]; | |
1121 } | |
1122 (PCB).ag_ap = ag_pstt[ag_t1]; | |
1123 (ag_gt_procs_scan[ag_astt[ag_t1]])(); | |
1124 } | |
1125 } | |
1126 | |
1127 |