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