Mercurial > ~dholland > hg > ag > index.cgi
comparison tests/agcl/examples/good/fc4.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 FC4_H | |
27 #include "fc4.h" | |
28 #endif | |
29 | |
30 #ifndef FC4_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 fc4_pcb_type fc4_pcb; | |
44 #define PCB fc4_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 -, fc4.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 -, fc4.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 -, fc4.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 fc4_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, 3, 0, 4, 0, 0, 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, 10, 0, 10, 10, 0, | |
159 0, 8, 0, 0, 8, 8, 8, 8, 0, 6, 4, 0, 10, 10, 10, 10, 10, 0, | |
160 0, 0, 0, 4, 8, 4, 8, 4, 8, 0, 0, 4, 8, 8, 10, 10, 8, 8, | |
161 8, 0, 0, 0, 4, 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, 45, 36, 44, 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, 42, 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 42, 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 = (fc4_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 = (fc4_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 = (fc4_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 = (fc4_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 = (fc4_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 = (fc4_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 = (fc4_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,44,35,30,25,24,23,20,10,0,1,37,38, | |
376 45,44,42,41,40,36,35,29,24,23,20,0,27,28, | |
377 45,44,42,41,40,35,30,25,24,23,20,10,0, | |
378 45,44,42,41,40,35,30,25,24,23,20,10,0, | |
379 45,44,42,41,40,35,30,25,24,23,20,10,0,1, | |
380 45,44,35,30,23,20,15,10,0,2,4,5,6,7,8,9,11,16,17,18,19,43, | |
381 45,44,42,41,40,36,35,29,24,23,20,0, | |
382 45,44,42,41,40,36,35,29,24,23,20,0, | |
383 29,0, | |
384 45,44,42,41,40,35,30,25,24,23,20,10,0, | |
385 42,41,40,25,24,23,20,0, | |
386 25,24,23,20,0,1,37,38, | |
387 23,0,22, | |
388 42,41,40,25,24,23,20,0,21, | |
389 23,20,0, | |
390 25,24,23,20,0,1,37,38, | |
391 42,41,40,25,24,0,1,37,38, | |
392 23,20,0,2,19,43, | |
393 23,20,0,2,19,43, | |
394 35,30,0, | |
395 42,0,14, | |
396 41,40,0,12,13, | |
397 35,30,0, | |
398 35,30,0,3,34,39, | |
399 45,44,35,30,23,20,10,0, | |
400 45,44,35,30,23,20,15,10,0,2,5,6,7,11,16,17,18,19,43, | |
401 10,0, | |
402 45,44,42,41,40,36,35,29,24,23,20,0, | |
403 45,44,42,41,40,35,30,25,24,23,20,10,0, | |
404 23,20,0, | |
405 42,41,40,25,24,23,0,22, | |
406 42,41,40,25,24,0, | |
407 42,41,40,25,24,23,20,0, | |
408 42,41,40,25,24,23,0,22, | |
409 42,41,40,25,24,0, | |
410 23,20,0, | |
411 42,41,40,0, | |
412 41,40,0, | |
413 41,40,0, | |
414 35,30,25,24,0,1,37,38, | |
415 35,30,0, | |
416 35,30,25,24,0,1,37,38, | |
417 35,30,0, | |
418 35,30,25,24,0,1,37,38, | |
419 35,30,0, | |
420 45,44,42,41,40,36,35,24,23,20,0,32,33, | |
421 35,0, | |
422 45,44,35,30,25,24,23,20,10,0,1,37,38, | |
423 45,44,35,30,23,20,10,0, | |
424 45,44,35,30,23,20,10,0, | |
425 42,41,40,25,24,0, | |
426 42,41,40,25,24,0, | |
427 35,30,0, | |
428 35,30,0, | |
429 35,30,0, | |
430 45,44,42,41,40,36,35,24,23,20,0, | |
431 45,44,42,41,40,36,35,24,23,20,0, | |
432 35,0, | |
433 45,44,35,30,25,24,23,20,10,0, | |
434 45,44,35,30,23,20,10,0, | |
435 45,44,42,41,40,36,35,24,23,20,0, | |
436 | |
437 }; | |
438 | |
439 | |
440 static unsigned const char ag_astt[465] = { | |
441 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, | |
442 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, | |
443 5,7,1,0,1,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, | |
444 1,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,1,5,5,7,1,1,1,1,7,1,5, | |
445 5,5,5,5,1,1,7,1,5,5,7,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, | |
446 1,1,1,5,5,7,1,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, | |
447 1,5,7,1,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, | |
448 5,5,7,5,5,7,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, | |
449 5,5,5,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, | |
450 4,4,7,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, | |
451 5,7,1,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, | |
452 5,7,5,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, | |
453 5,7,5,5,5,5,5,5,5,7,5,5,5,5,5,5,5,5,5,5,7 | |
454 }; | |
455 | |
456 | |
457 static const unsigned char ag_pstt[] = { | |
458 60,60,60,60,1,2,60,60,60,0,3,4,5, | |
459 6,6,6,6,6,6,6,29,6,6,6,1,7,8, | |
460 26,26,26,26,26,26,26,26,26,26,26,26,2, | |
461 58,58,58,58,58,58,58,58,58,58,58,58,3, | |
462 61,61,61,61,61,61,61,1,2,61,61,61,4,9, | |
463 11,15,1,1,10,12,19,6,5,20,0,22,23,24,25,26,21,18,14,17,13,16, | |
464 27,27,27,27,27,27,27,27,27,27,27,6, | |
465 27,27,27,27,27,27,27,30,27,27,27,7, | |
466 28,8, | |
467 59,59,59,59,59,59,59,59,59,59,59,59,9, | |
468 22,22,22,22,22,22,22,10, | |
469 1,2,60,60,11,3,4,29, | |
470 30,12,31, | |
471 17,17,17,17,17,32,33,13,34, | |
472 15,15,14, | |
473 1,2,60,60,15,3,4,35, | |
474 60,60,60,1,2,16,3,4,36, | |
475 10,12,17,37,13,16, | |
476 10,12,18,38,13,16, | |
477 12,12,19, | |
478 39,20,40, | |
479 41,43,21,44,42, | |
480 2,2,22, | |
481 36,45,23,48,46,47, | |
482 4,4,4,4,4,4,4,24, | |
483 11,15,1,1,10,12,19,7,25,20,22,23,49,21,18,14,17,13,16, | |
484 8,26, | |
485 28,28,28,28,28,28,28,28,28,28,28,27, | |
486 31,31,31,31,31,31,31,31,31,31,31,31,28, | |
487 68,68,29, | |
488 24,24,24,24,24,30,30,50, | |
489 21,21,21,21,21,31, | |
490 23,23,23,23,23,23,23,32, | |
491 18,18,18,18,18,30,33,51, | |
492 19,19,19,19,19,34, | |
493 67,67,35, | |
494 66,66,66,36, | |
495 16,16,37, | |
496 13,13,38, | |
497 60,60,1,2,39,3,4,52, | |
498 11,11,40, | |
499 60,60,1,2,41,3,4,53, | |
500 10,10,42, | |
501 60,60,1,2,43,3,4,54, | |
502 9,9,44, | |
503 55,55,55,55,55,55,34,55,55,55,45,56,57, | |
504 58,46, | |
505 60,60,60,60,1,2,60,60,60,47,3,4,59, | |
506 3,3,3,3,3,3,3,48, | |
507 5,5,5,5,5,5,5,49, | |
508 25,25,25,25,25,50, | |
509 20,20,20,20,20,51, | |
510 65,65,52, | |
511 64,64,53, | |
512 63,63,54, | |
513 32,32,32,32,32,32,32,32,32,32,55, | |
514 60,60,60,60,60,60,35,60,60,60,56, | |
515 37,57, | |
516 38,38,38,38,38,38,38,38,38,58, | |
517 62,62,62,62,62,62,62,59, | |
518 33,33,33,33,33,33,33,33,33,33,60, | |
519 | |
520 }; | |
521 | |
522 | |
523 static const unsigned short ag_sbt[] = { | |
524 0, 13, 27, 40, 53, 67, 89, 101, 113, 115, 128, 136, 144, 147, | |
525 156, 159, 167, 176, 182, 188, 191, 194, 199, 202, 208, 216, 235, 237, | |
526 249, 262, 265, 273, 279, 287, 295, 301, 304, 308, 311, 314, 322, 325, | |
527 333, 336, 344, 347, 360, 362, 375, 383, 391, 397, 403, 406, 409, 412, | |
528 423, 434, 436, 446, 454, 465 | |
529 }; | |
530 | |
531 | |
532 static const unsigned short ag_sbe[] = { | |
533 9, 24, 39, 52, 65, 75, 100, 112, 114, 127, 135, 140, 145, 154, | |
534 158, 163, 172, 178, 184, 190, 192, 196, 201, 204, 215, 224, 236, 248, | |
535 261, 264, 271, 278, 286, 293, 300, 303, 307, 310, 313, 318, 324, 329, | |
536 335, 340, 346, 357, 361, 371, 382, 390, 396, 402, 405, 408, 411, 422, | |
537 433, 435, 445, 453, 464, 465 | |
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,0,1,2,0,1,2,3,2,1,2,1,2,1,1,2,0,1,3,1,2,0, | |
543 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 | |
544 }; | |
545 | |
546 static const unsigned char ag_ptt[] = { | |
547 0, 6, 6, 7, 8, 8, 9, 9, 4, 5, 5, 5, 5, 11, 18, 18, 11, 21, | |
548 21, 43, 43, 43, 19, 19, 22, 22, 1, 27, 27, 28, 28, 1, 32, 32, 33, 33, | |
549 34, 34, 39, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 31, 31, 31, 31, 31, | |
550 31, 31, 31, 31, 37, 37, 38, 38, 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 *)), V(2,(double *))); break; | |
563 case 7: V(0,(double *)) = ag_rp_7(V(1,(double *))); break; | |
564 case 8: V(0,(double *)) = ag_rp_8(V(0,(int *))); break; | |
565 case 9: V(0,(double *)) = ag_rp_9(V(0,(double *)), V(1,(int *))); break; | |
566 case 10: V(0,(double *)) = ag_rp_10(V(0,(int *))); break; | |
567 case 11: V(0,(double *)) = ag_rp_11(V(0,(int *)), V(1,(double *))); break; | |
568 } | |
569 } | |
570 | |
571 #define TOKEN_NAMES fc4_token_names | |
572 const char *const fc4_token_names[46] = { | |
573 "grammar", | |
574 "white space", | |
575 "unsigned number", | |
576 "end of line", | |
577 "grammar", | |
578 "temperature", | |
579 "", | |
580 "", | |
581 "", | |
582 "", | |
583 "eof", | |
584 "number", | |
585 "", | |
586 "", | |
587 "", | |
588 "error", | |
589 "'-'", | |
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 = (fc4_token_type) AG_TCV((PCB).input_code);} | |
754 else { | |
755 GET_INPUT; | |
756 (PCB).lab[(PCB).fx++] = (PCB).input_code; | |
757 (PCB).token_number = (fc4_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 = (fc4_token_type) AG_TCV((PCB).input_code);} | |
781 else { | |
782 GET_INPUT; | |
783 (PCB).lab[(PCB).fx++] = (PCB).input_code; | |
784 (PCB).token_number = (fc4_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 == (fc4_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 = (fc4_token_type) AG_TCV((PCB).input_code);} | |
814 else { | |
815 GET_INPUT; | |
816 (PCB).lab[(PCB).fx++] = (PCB).input_code; | |
817 (PCB).token_number = (fc4_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 == (fc4_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 = (fc4_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 = (fc4_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 = (fc4_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 = (fc4_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 = (fc4_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 = (fc4_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 = (fc4_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 = (fc4_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 = (fc4_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_fc4(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 fc4(void) { | |
1093 init_fc4(); | |
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 = (fc4_token_type) AG_TCV((PCB).input_code);} | |
1102 else { | |
1103 GET_INPUT; | |
1104 (PCB).lab[(PCB).fx++] = (PCB).input_code; | |
1105 (PCB).token_number = (fc4_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 fc4(); | |
1134 return 0; | |
1135 } |