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