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