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