Mercurial > ~dholland > hg > ag > index.cgi
comparison helpgen/readhelp.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 | ec2b657edf13 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:13d2b8934445 |
---|---|
1 /* | |
2 * AnaGram, a System for Syntax Directed Programming | |
3 * Copyright 1993 Parsifal Software. All Rights Reserved. | |
4 * Copyright 2006 David A. Holland. All Rights Reserved. | |
5 * See the file COPYING for license and usage terms. | |
6 * | |
7 * readhelp.syn - Toplevel syntax for help source file. | |
8 */ | |
9 #include <sys/types.h> | |
10 #include <sys/stat.h> | |
11 #include <assert.h> | |
12 #include <errno.h> | |
13 #include <fcntl.h> | |
14 #include <stdio.h> | |
15 #include <stdlib.h> | |
16 #include <string.h> | |
17 #include <unistd.h> | |
18 | |
19 #include "utils.h" | |
20 #include "topic.h" | |
21 #include "helpgen.h" | |
22 | |
23 /* | |
24 * AnaGram, A System for Syntax Directed Programming | |
25 * File generated by: Version 2.40-current, built Jun 13 2007 | |
26 * | |
27 * AnaGram Parsing Engine | |
28 * Copyright 1993-2002 Parsifal Software. All Rights Reserved. | |
29 * | |
30 * This software is provided 'as-is', without any express or implied | |
31 * warranty. In no event will the authors be held liable for any damages | |
32 * arising from the use of this software. | |
33 * | |
34 * Permission is granted to anyone to use this software for any purpose, | |
35 * including commercial applications, and to alter it and redistribute it | |
36 * freely, subject to the following restrictions: | |
37 * | |
38 * 1. The origin of this software must not be misrepresented; you must not | |
39 * claim that you wrote the original software. If you use this software | |
40 * in a product, an acknowledgment in the product documentation would be | |
41 * appreciated but is not required. | |
42 * 2. Altered source versions must be plainly marked as such, and must not be | |
43 * misrepresented as being the original software. | |
44 * 3. This notice may not be removed or altered from any source distribution. | |
45 */ | |
46 | |
47 #ifndef READHELP_H_1181769468 | |
48 #include "readhelp.h" | |
49 #endif | |
50 | |
51 #ifndef READHELP_H_1181769468 | |
52 #error Mismatched header file | |
53 #endif | |
54 | |
55 #include <ctype.h> | |
56 #include <stdio.h> | |
57 | |
58 #define RULE_CONTEXT (&((PCB).cs[(PCB).ssx])) | |
59 #define ERROR_CONTEXT ((PCB).cs[(PCB).error_frame_ssx]) | |
60 #define CONTEXT ((PCB).cs[(PCB).ssx]) | |
61 | |
62 | |
63 | |
64 readhelp_pcb_type readhelp_pcb; | |
65 #define PCB readhelp_pcb | |
66 | |
67 #line 124 "/disk/disk0/home/dholland/projects/ag/src/helpgen/readhelp.syn" | |
68 static char string_space[4096]; | |
69 static size_t string_pos; | |
70 | |
71 static void startstr(void) { | |
72 string_pos = 0; | |
73 } | |
74 | |
75 static void addstr(int ch) { | |
76 if (string_pos >= sizeof(string_space)-1) { | |
77 fprintf(stderr, "String buffer overflow - make string_space larger\n"); | |
78 exit(1); | |
79 } | |
80 string_space[string_pos++] = ch; | |
81 } | |
82 | |
83 static const char *getstr(void) { | |
84 string_space[string_pos] = 0; | |
85 return string_space; | |
86 } | |
87 #line 88 "readhelp.c" | |
88 #line 149 "/disk/disk0/home/dholland/projects/ag/src/helpgen/readhelp.syn" | |
89 static struct topic *curtopic; | |
90 | |
91 static void startblock(void) { | |
92 assert(curtopic == NULL); | |
93 curtopic = topic_create(); | |
94 } | |
95 | |
96 static void endblock(void) { | |
97 help_addtopic(curtopic); | |
98 curtopic = NULL; | |
99 } | |
100 | |
101 static void see_xref(const char *ref) { | |
102 topic_addref(curtopic, ref); | |
103 } | |
104 | |
105 #line 106 "readhelp.c" | |
106 #line 172 "/disk/disk0/home/dholland/projects/ag/src/helpgen/readhelp.syn" | |
107 #define GET_CONTEXT CONTEXT = PCB.pointer | |
108 | |
109 static unsigned char *inputdata; | |
110 | |
111 static void block(long head, long tail) { | |
112 long length = tail - head; | |
113 assert(length >= 0); | |
114 if (length > 0) { | |
115 topic_setbody(curtopic, (const char *)(inputdata+head), length); | |
116 } | |
117 } | |
118 | |
119 static off_t getlength(int fd) { | |
120 struct stat st; | |
121 if (fstat(fd, &st) < 0) { | |
122 fprintf(stderr, "fstat failed: %s", strerror(errno)); | |
123 exit(1); | |
124 } | |
125 return st.st_size; | |
126 } | |
127 | |
128 void load(const char *path) { | |
129 char *buf; | |
130 off_t len; | |
131 int fd, r; | |
132 | |
133 fd = open(path, O_RDONLY); | |
134 if (fd < 0) { | |
135 fprintf(stderr, "%s: %s\n", path, strerror(errno)); | |
136 exit(1); | |
137 } | |
138 | |
139 len = getlength(fd); | |
140 buf = domalloc(len+1); | |
141 r = read(fd, buf, len); | |
142 if (r < 0) { | |
143 fprintf(stderr, "%s: read: %s\n", path, strerror(errno)); | |
144 exit(1); | |
145 } | |
146 if (r < len) { | |
147 fprintf(stderr, "%s: read: short count %d of %ld\n", path, r, (long) len); | |
148 exit(1); | |
149 } | |
150 buf[r] = 0; | |
151 close(fd); | |
152 | |
153 inputdata = (unsigned char *) buf; | |
154 PCB.pointer = inputdata; | |
155 readhelp(); | |
156 inputdata = NULL; | |
157 free(buf); | |
158 } | |
159 | |
160 #line 161 "readhelp.c" | |
161 | |
162 #ifndef CONVERT_CASE | |
163 #define CONVERT_CASE(c) (c) | |
164 #endif | |
165 #ifndef TAB_SPACING | |
166 #define TAB_SPACING 8 | |
167 #endif | |
168 | |
169 #define ag_rp_1(c) (c) | |
170 | |
171 #define ag_rp_2(c) (startstr(), addstr(c)) | |
172 | |
173 #define ag_rp_3(c) (addstr(c)) | |
174 | |
175 #define ag_rp_4(c) (addstr(' '), addstr(c)) | |
176 | |
177 #define ag_rp_5() (getstr()) | |
178 | |
179 #define ag_rp_6(t) (topic_addtitle(curtopic, t)) | |
180 | |
181 #define ag_rp_7(t) (topic_addtitle(curtopic, t)) | |
182 | |
183 #define ag_rp_8() (CONTEXT - inputdata) | |
184 | |
185 #define ag_rp_9() (see_xref(getstr())) | |
186 | |
187 #define ag_rp_10() (startstr()) | |
188 | |
189 #define ag_rp_11(c) (addstr(c)) | |
190 | |
191 #define ag_rp_12(c) (addstr(' '), addstr(c)) | |
192 | |
193 #define ag_rp_13() (addstr(' ')) | |
194 | |
195 #define ag_rp_14() (CONTEXT - inputdata) | |
196 | |
197 #define ag_rp_15() (CONTEXT - inputdata) | |
198 | |
199 static void ag_rp_16(void) { | |
200 #line 105 "/disk/disk0/home/dholland/projects/ag/src/helpgen/readhelp.syn" | |
201 startblock(); | |
202 #line 203 "readhelp.c" | |
203 } | |
204 | |
205 #define ag_rp_17() (endblock()) | |
206 | |
207 #define ag_rp_18(bb, be) (block(bb,be)) | |
208 | |
209 #define ag_rp_19() (block(0,0)) | |
210 | |
211 | |
212 #define READ_COUNTS | |
213 #define WRITE_COUNTS | |
214 #undef V | |
215 #define V(i,t) (*t (&(PCB).vs[(PCB).ssx + i])) | |
216 #undef VS | |
217 #define VS(i) (PCB).vs[(PCB).ssx + i] | |
218 | |
219 #ifndef GET_CONTEXT | |
220 #define GET_CONTEXT CONTEXT = (PCB).input_context | |
221 #endif | |
222 | |
223 typedef enum { | |
224 ag_action_1, | |
225 ag_action_2, | |
226 ag_action_3, | |
227 ag_action_4, | |
228 ag_action_5, | |
229 ag_action_6, | |
230 ag_action_7, | |
231 ag_action_8, | |
232 ag_action_9, | |
233 ag_action_10, | |
234 ag_action_11, | |
235 ag_action_12 | |
236 } ag_parser_action; | |
237 | |
238 | |
239 #ifndef NULL_VALUE_INITIALIZER | |
240 #define NULL_VALUE_INITIALIZER = { 0 } | |
241 #endif | |
242 | |
243 static readhelp_vs_type const ag_null_value NULL_VALUE_INITIALIZER; | |
244 | |
245 static const unsigned char ag_rpx[] = { | |
246 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, | |
247 3, 4, 5, 6, 7, 0, 0, 8, 0, 0, 0, 9, 10, 11, 12, 13, 0, 0, | |
248 14, 0, 0, 15, 16, 17, 0, 0, 18, 19 | |
249 }; | |
250 | |
251 static const unsigned char ag_key_itt[] = { | |
252 0 | |
253 }; | |
254 | |
255 static const unsigned short ag_key_pt[] = { | |
256 0 | |
257 }; | |
258 | |
259 static const unsigned char ag_key_ch[] = { | |
260 0, 47,255, 35,255 | |
261 }; | |
262 | |
263 static const unsigned char ag_key_act[] = { | |
264 0,3,4,3,4 | |
265 }; | |
266 | |
267 static const unsigned char ag_key_parm[] = { | |
268 0, 6, 0, 32, 0 | |
269 }; | |
270 | |
271 static const unsigned char ag_key_jmp[] = { | |
272 0, 0, 0, 2, 0 | |
273 }; | |
274 | |
275 static const unsigned char ag_key_index[] = { | |
276 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 3, 1, 0, 0, 0, 3, 0, 1, | |
277 0, 0, 0, 3, 3, 0, 0, 0, 0, 3, 0, 3 | |
278 }; | |
279 | |
280 static const unsigned char ag_key_ends[] = { | |
281 47,0, 35,0, | |
282 }; | |
283 | |
284 #define AG_TCV(x) ag_tcv[(x)] | |
285 | |
286 static const unsigned char ag_tcv[] = { | |
287 39, 2, 2, 2, 2, 2, 2, 2, 2, 4, 12, 2, 2, 10, 2, 2, 2, 2, | |
288 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 2, 2, 2, | |
289 2, 2, 2, 2, 2, 2, 2, 2, 20, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
290 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
291 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
292 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
293 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
294 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
295 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
296 2, 2, 2, 2, 2, 2, 2, 28, 27, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
297 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
298 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
299 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
300 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
301 2, 2, 2, 2 | |
302 }; | |
303 | |
304 #ifndef SYNTAX_ERROR | |
305 #define SYNTAX_ERROR fprintf(stderr,"%s, line %d, column %d\n", \ | |
306 (PCB).error_message, (PCB).line, (PCB).column) | |
307 #endif | |
308 | |
309 #ifndef FIRST_LINE | |
310 #define FIRST_LINE 1 | |
311 #endif | |
312 | |
313 #ifndef FIRST_COLUMN | |
314 #define FIRST_COLUMN 1 | |
315 #endif | |
316 | |
317 #ifndef PARSER_STACK_OVERFLOW | |
318 #define PARSER_STACK_OVERFLOW {fprintf(stderr, \ | |
319 "\nParser stack overflow, line %d, column %d\n",\ | |
320 (PCB).line, (PCB).column);} | |
321 #endif | |
322 | |
323 #ifndef REDUCTION_TOKEN_ERROR | |
324 #define REDUCTION_TOKEN_ERROR {fprintf(stderr, \ | |
325 "\nReduction token error, line %d, column %d\n", \ | |
326 (PCB).line, (PCB).column);} | |
327 #endif | |
328 | |
329 | |
330 #ifndef INPUT_CODE | |
331 #define INPUT_CODE(T) (T) | |
332 #endif | |
333 | |
334 typedef enum | |
335 {ag_accept_key, ag_set_key, ag_jmp_key, ag_end_key, ag_no_match_key, | |
336 ag_cf_accept_key, ag_cf_set_key, ag_cf_end_key} key_words; | |
337 | |
338 static void ag_get_key_word(int ag_k) { | |
339 int ag_save = (int) ((PCB).la_ptr - (PCB).pointer); | |
340 const unsigned char *ag_p; | |
341 int ag_ch; | |
342 while (1) { | |
343 switch (ag_key_act[ag_k]) { | |
344 case ag_cf_end_key: { | |
345 const unsigned char *sp = ag_key_ends + ag_key_jmp[ag_k]; | |
346 do { | |
347 if ((ag_ch = *sp++) == 0) { | |
348 int ag_k1 = ag_key_parm[ag_k]; | |
349 int ag_k2 = ag_key_pt[ag_k1]; | |
350 if (ag_key_itt[ag_k2 + CONVERT_CASE(*(PCB).la_ptr)]) goto ag_fail; | |
351 (PCB).token_number = (readhelp_token_type) ag_key_pt[ag_k1 + 1]; | |
352 return; | |
353 } | |
354 } while (CONVERT_CASE(*(PCB).la_ptr++) == ag_ch); | |
355 goto ag_fail; | |
356 } | |
357 case ag_end_key: { | |
358 const unsigned char *sp = ag_key_ends + ag_key_jmp[ag_k]; | |
359 do { | |
360 if ((ag_ch = *sp++) == 0) { | |
361 (PCB).token_number = (readhelp_token_type) ag_key_parm[ag_k]; | |
362 return; | |
363 } | |
364 } while (CONVERT_CASE(*(PCB).la_ptr++) == ag_ch); | |
365 } | |
366 case ag_no_match_key: | |
367 ag_fail: | |
368 (PCB).la_ptr = (PCB).pointer + ag_save; | |
369 return; | |
370 case ag_cf_set_key: { | |
371 int ag_k1 = ag_key_parm[ag_k]; | |
372 int ag_k2 = ag_key_pt[ag_k1]; | |
373 ag_k = ag_key_jmp[ag_k]; | |
374 if (ag_key_itt[ag_k2 + CONVERT_CASE(*(PCB).la_ptr)]) break; | |
375 ag_save = (int) ((PCB).la_ptr - (PCB).pointer); | |
376 (PCB).token_number = (readhelp_token_type) ag_key_pt[ag_k1+1]; | |
377 break; | |
378 } | |
379 case ag_set_key: | |
380 ag_save = (int) ((PCB).la_ptr - (PCB).pointer); | |
381 (PCB).token_number = (readhelp_token_type) ag_key_parm[ag_k]; | |
382 case ag_jmp_key: | |
383 ag_k = ag_key_jmp[ag_k]; | |
384 break; | |
385 case ag_accept_key: | |
386 (PCB).token_number = (readhelp_token_type) ag_key_parm[ag_k]; | |
387 return; | |
388 case ag_cf_accept_key: { | |
389 int ag_k1 = ag_key_parm[ag_k]; | |
390 int ag_k2 = ag_key_pt[ag_k1]; | |
391 if (ag_key_itt[ag_k2 + CONVERT_CASE(*(PCB).la_ptr)]) | |
392 (PCB).la_ptr = (PCB).pointer + ag_save; | |
393 else (PCB).token_number = (readhelp_token_type) ag_key_pt[ag_k1+1]; | |
394 return; | |
395 } | |
396 } | |
397 ag_ch = CONVERT_CASE(*(PCB).la_ptr++); | |
398 ag_p = &ag_key_ch[ag_k]; | |
399 if (ag_ch <= 255) while (*ag_p < ag_ch) ag_p++; | |
400 if (ag_ch > 255 || *ag_p != ag_ch) { | |
401 (PCB).la_ptr = (PCB).pointer + ag_save; | |
402 return; | |
403 } | |
404 ag_k = (int) (ag_p - ag_key_ch); | |
405 } | |
406 } | |
407 | |
408 | |
409 #ifndef AG_NEWLINE | |
410 #define AG_NEWLINE 10 | |
411 #endif | |
412 | |
413 #ifndef AG_RETURN | |
414 #define AG_RETURN 13 | |
415 #endif | |
416 | |
417 #ifndef AG_FORMFEED | |
418 #define AG_FORMFEED 12 | |
419 #endif | |
420 | |
421 #ifndef AG_TABCHAR | |
422 #define AG_TABCHAR 9 | |
423 #endif | |
424 | |
425 static void ag_track(void) { | |
426 int ag_k = (int) ((PCB).la_ptr - (PCB).pointer); | |
427 while (ag_k--) { | |
428 switch (*(PCB).pointer++) { | |
429 case AG_NEWLINE: | |
430 (PCB).column = 1, (PCB).line++; | |
431 case AG_RETURN: | |
432 case AG_FORMFEED: | |
433 break; | |
434 case AG_TABCHAR: | |
435 (PCB).column += (TAB_SPACING) - ((PCB).column - 1) % (TAB_SPACING); | |
436 break; | |
437 default: | |
438 (PCB).column++; | |
439 } | |
440 } | |
441 } | |
442 | |
443 | |
444 static void ag_prot(void) { | |
445 int ag_k; | |
446 ag_k = 128 - ++(PCB).btsx; | |
447 if (ag_k <= (PCB).ssx) { | |
448 (PCB).exit_flag = AG_STACK_ERROR_CODE; | |
449 PARSER_STACK_OVERFLOW; | |
450 return; | |
451 } | |
452 (PCB).bts[(PCB).btsx] = (PCB).sn; | |
453 (PCB).bts[ag_k] = (PCB).ssx; | |
454 (PCB).vs[ag_k] = (PCB).vs[(PCB).ssx]; | |
455 (PCB).ss[ag_k] = (PCB).ss[(PCB).ssx]; | |
456 (PCB).cs[ag_k] = (PCB).cs[(PCB).ssx]; | |
457 } | |
458 | |
459 static void ag_undo(void) { | |
460 if ((PCB).drt == -1) return; | |
461 while ((PCB).btsx) { | |
462 int ag_k = 128 - (PCB).btsx; | |
463 (PCB).sn = (PCB).bts[(PCB).btsx--]; | |
464 (PCB).ssx = (PCB).bts[ag_k]; | |
465 (PCB).vs[(PCB).ssx] = (PCB).vs[ag_k]; | |
466 (PCB).ss[(PCB).ssx] = (PCB).ss[ag_k]; | |
467 (PCB).cs[(PCB).ssx] = (PCB).cs[ag_k]; | |
468 } | |
469 (PCB).token_number = (readhelp_token_type) (PCB).drt; | |
470 (PCB).ssx = (PCB).dssx; | |
471 (PCB).sn = (PCB).dsn; | |
472 (PCB).drt = -1; | |
473 } | |
474 | |
475 | |
476 static const unsigned char ag_tstt[] = { | |
477 39,12,10,6,4,2,0,37,38, | |
478 39,12,10,6,4,2,0,3,15,33,34, | |
479 2,0,1,17,18,19, | |
480 4,0, | |
481 12,10,6,0,5,9, | |
482 20,12,10,6,4,2,0,1,3,15, | |
483 20,12,10,6,0,5,9, | |
484 28,27,20,4,2,0,8, | |
485 12,10,0,11, | |
486 4,2,0,1, | |
487 32,28,20,12,10,4,2,0,11,13,30,31,35,36, | |
488 12,10,6,4,2,0,3,14,15, | |
489 28,27,20,4,2,0, | |
490 12,0, | |
491 12,0, | |
492 32,28,20,12,10,4,2,0,11,13, | |
493 28,20,4,2,0,21,22,23,25,26,29, | |
494 12,10,6,2,0,5,9,16, | |
495 2,0,1,17,18, | |
496 27,12,10,4,2,0,1,3,15, | |
497 28,20,12,10,4,2,0,11,13,22,25,26, | |
498 28,20,4,2,0,22,23,25,26, | |
499 32,12,10,0,11,13,30,31, | |
500 4,2,0,3,15, | |
501 4,2,0,1, | |
502 27,12,10,0,11, | |
503 28,20,12,10,4,2,0,11,13,22,25,26, | |
504 32,28,20,12,10,4,2,0,11,13,21,22,23,25,26, | |
505 12,0, | |
506 28,20,4,2,0,22,23,25,26, | |
507 | |
508 }; | |
509 | |
510 | |
511 static unsigned const char ag_astt[223] = { | |
512 8,5,5,5,8,8,7,0,1,3,8,8,8,1,4,7,1,1,3,1,2,7,2,1,2,1,9,5,5,8,1,7,3,1,5,5,5, | |
513 5,1,2,7,2,1,2,1,5,8,1,7,1,1,1,1,1,1,1,7,1,8,1,7,1,9,2,5,2,2,8,8,8,1,8,8,7, | |
514 1,2,1,2,2,1,8,8,8,1,5,7,1,1,1,9,9,9,9,9,5,3,7,3,7,3,5,5,8,1,5,5,7,1,3,2,1, | |
515 1,1,7,1,1,1,1,1,1,5,8,1,5,7,1,1,3,2,7,2,1,2,8,5,8,1,2,7,2,1,1,2,9,8,1,9,9, | |
516 7,1,2,3,3,1,2,1,1,1,5,1,1,1,1,2,8,1,7,1,2,1,2,1,5,7,1,3,9,2,5,2,2,8,1,7,1, | |
517 2,9,8,1,9,9,7,1,3,3,3,1,3,2,1,8,1,1,1,7,1,3,1,1,1,1,1,2,7,2,1,1,1,5,1,1,1, | |
518 1 | |
519 }; | |
520 | |
521 | |
522 static const unsigned char ag_pstt[] = { | |
523 1,47,47,47,1,1,0,0,1, | |
524 46,4,4,4,3,40,1,3,4,49,2, | |
525 1,2,17,5,21,6, | |
526 3,13, | |
527 6,8,7,4,48,8, | |
528 12,12,12,12,9,1,5,18,9,20, | |
529 11,6,8,7,6,10,8, | |
530 12,12,12,12,12,7,12, | |
531 13,13,8,13, | |
532 3,1,13,19, | |
533 39,16,16,14,14,16,16,10,14,36,15,45,41,16, | |
534 17,17,17,3,12,11,3,18,17, | |
535 5,5,5,5,5,7, | |
536 10,13, | |
537 11,14, | |
538 38,43,43,14,14,43,43,15,14,37, | |
539 30,20,20,20,16,21,20,20,20,19,22, | |
540 6,8,7,14,17,23,8,16, | |
541 1,18,17,5,22, | |
542 25,12,25,24,1,19,31,24,25, | |
543 30,24,14,14,24,24,20,14,25,24,24,19, | |
544 30,26,26,26,34,26,26,26,19, | |
545 39,14,14,22,14,36,27,44, | |
546 3,12,23,3,15, | |
547 3,1,13,32, | |
548 29,28,28,25,28, | |
549 30,24,14,14,24,24,26,14,26,24,24,19, | |
550 38,30,20,14,14,20,20,27,14,37,29,20,20,20,19, | |
551 33,28, | |
552 30,26,26,26,35,26,26,26,19, | |
553 | |
554 }; | |
555 | |
556 | |
557 static const unsigned char ag_sbt[] = { | |
558 0, 9, 20, 26, 28, 34, 44, 51, 58, 62, 66, 80, 89, 95, | |
559 97, 99, 109, 120, 128, 133, 142, 154, 163, 171, 176, 180, 185, 197, | |
560 212, 214, 223 | |
561 }; | |
562 | |
563 | |
564 static const unsigned char ag_sbe[] = { | |
565 6, 15, 21, 27, 31, 40, 48, 56, 60, 64, 73, 85, 94, 96, | |
566 98, 106, 113, 124, 129, 138, 148, 158, 166, 173, 178, 183, 191, 204, | |
567 213, 218, 223 | |
568 }; | |
569 | |
570 | |
571 static const unsigned char ag_fl[] = { | |
572 1,1,1,2,1,2,0,2,0,1,3,2,0,1,0,2,2,1,2,3,2,1,4,1,2,2,3,1,1,3,1,2,3,4,1, | |
573 3,1,2,2,1,0,4,0,1,3,1,2,0,3,2 | |
574 }; | |
575 | |
576 static const unsigned char ag_ptt[] = { | |
577 0, 1, 3, 3, 8, 8, 9, 9, 11, 11, 5, 13, 15, 15, 16, 16, 14, 17, | |
578 17, 17, 18, 19, 19, 23, 23, 21, 21, 22, 22, 25, 26, 26, 26, 26, 29, 29, | |
579 30, 30, 31, 31, 34, 33, 36, 36, 35, 35, 37, 38, 38, 38 | |
580 }; | |
581 | |
582 | |
583 static void ag_ra(void) | |
584 { | |
585 switch(ag_rpx[(PCB).ag_ap]) { | |
586 case 1: V(0,(int *)) = ag_rp_1(V(0,(int *))); break; | |
587 case 2: ag_rp_2(V(0,(int *))); break; | |
588 case 3: ag_rp_3(V(1,(int *))); break; | |
589 case 4: ag_rp_4(V(2,(int *))); break; | |
590 case 5: V(0,(const char * *)) = ag_rp_5(); break; | |
591 case 6: ag_rp_6(V(0,(const char * *))); break; | |
592 case 7: ag_rp_7(V(3,(const char * *))); break; | |
593 case 8: V(0,(long *)) = ag_rp_8(); break; | |
594 case 9: ag_rp_9(); break; | |
595 case 10: ag_rp_10(); break; | |
596 case 11: ag_rp_11(V(1,(int *))); break; | |
597 case 12: ag_rp_12(V(2,(int *))); break; | |
598 case 13: ag_rp_13(); break; | |
599 case 14: V(0,(long *)) = ag_rp_14(); break; | |
600 case 15: V(0,(long *)) = ag_rp_15(); break; | |
601 case 16: ag_rp_16(); break; | |
602 case 17: ag_rp_17(); break; | |
603 case 18: ag_rp_18(V(1,(long *)), V(2,(long *))); break; | |
604 case 19: ag_rp_19(); break; | |
605 } | |
606 (PCB).la_ptr = (PCB).pointer; | |
607 } | |
608 | |
609 #define TOKEN_NAMES readhelp_token_names | |
610 const char *const readhelp_token_names[40] = { | |
611 "file", | |
612 "letter", | |
613 "", | |
614 "blanks", | |
615 "blank", | |
616 "eol", | |
617 "\"//\"", | |
618 "text", | |
619 "", | |
620 "", | |
621 "cr", | |
622 "", | |
623 "nl", | |
624 "new line", | |
625 "continue", | |
626 "", | |
627 "", | |
628 "name", | |
629 "title", | |
630 "titles", | |
631 "','", | |
632 "text lines", | |
633 "text unit", | |
634 "", | |
635 "", | |
636 "cross reference", | |
637 "cross reference text", | |
638 "right", | |
639 "left", | |
640 "block body", | |
641 "blank lines", | |
642 "end block", | |
643 "\"##\"", | |
644 "block", | |
645 "", | |
646 "real block body", | |
647 "", | |
648 "file", | |
649 "blocks", | |
650 "eof", | |
651 | |
652 }; | |
653 | |
654 #ifndef MISSING_FORMAT | |
655 #define MISSING_FORMAT "Missing %s" | |
656 #endif | |
657 #ifndef UNEXPECTED_FORMAT | |
658 #define UNEXPECTED_FORMAT "Unexpected %s" | |
659 #endif | |
660 #ifndef UNNAMED_TOKEN | |
661 #define UNNAMED_TOKEN "input" | |
662 #endif | |
663 | |
664 | |
665 static void ag_diagnose(void) { | |
666 int ag_snd = (PCB).sn; | |
667 int ag_k = ag_sbt[ag_snd]; | |
668 | |
669 if (*TOKEN_NAMES[ag_tstt[ag_k]] && ag_astt[ag_k + 1] == ag_action_8) { | |
670 sprintf((PCB).ag_msg, MISSING_FORMAT, TOKEN_NAMES[ag_tstt[ag_k]]); | |
671 } | |
672 else if (ag_astt[ag_sbe[(PCB).sn]] == ag_action_8 | |
673 && (ag_k = (int) ag_sbe[(PCB).sn] + 1) == (int) ag_sbt[(PCB).sn+1] - 1 | |
674 && *TOKEN_NAMES[ag_tstt[ag_k]]) { | |
675 sprintf((PCB).ag_msg, MISSING_FORMAT, TOKEN_NAMES[ag_tstt[ag_k]]); | |
676 } | |
677 else if ((PCB).token_number && *TOKEN_NAMES[(PCB).token_number]) { | |
678 sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, TOKEN_NAMES[(PCB).token_number]); | |
679 } | |
680 else if (isprint(INPUT_CODE((*(PCB).pointer))) && INPUT_CODE((*(PCB).pointer)) != '\\') { | |
681 char buf[20]; | |
682 sprintf(buf, "\'%c\'", (char) INPUT_CODE((*(PCB).pointer))); | |
683 sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, buf); | |
684 } | |
685 else sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, UNNAMED_TOKEN); | |
686 (PCB).error_message = (PCB).ag_msg; | |
687 | |
688 | |
689 } | |
690 static int ag_action_1_r_proc(void); | |
691 static int ag_action_2_r_proc(void); | |
692 static int ag_action_3_r_proc(void); | |
693 static int ag_action_4_r_proc(void); | |
694 static int ag_action_1_s_proc(void); | |
695 static int ag_action_3_s_proc(void); | |
696 static int ag_action_1_proc(void); | |
697 static int ag_action_2_proc(void); | |
698 static int ag_action_3_proc(void); | |
699 static int ag_action_4_proc(void); | |
700 static int ag_action_5_proc(void); | |
701 static int ag_action_6_proc(void); | |
702 static int ag_action_7_proc(void); | |
703 static int ag_action_8_proc(void); | |
704 static int ag_action_9_proc(void); | |
705 static int ag_action_10_proc(void); | |
706 static int ag_action_11_proc(void); | |
707 static int ag_action_8_proc(void); | |
708 | |
709 | |
710 static int (*const ag_r_procs_scan[])(void) = { | |
711 ag_action_1_r_proc, | |
712 ag_action_2_r_proc, | |
713 ag_action_3_r_proc, | |
714 ag_action_4_r_proc | |
715 }; | |
716 | |
717 static int (*const ag_s_procs_scan[])(void) = { | |
718 ag_action_1_s_proc, | |
719 ag_action_2_r_proc, | |
720 ag_action_3_s_proc, | |
721 ag_action_4_r_proc | |
722 }; | |
723 | |
724 static int (*const ag_gt_procs_scan[])(void) = { | |
725 ag_action_1_proc, | |
726 ag_action_2_proc, | |
727 ag_action_3_proc, | |
728 ag_action_4_proc, | |
729 ag_action_5_proc, | |
730 ag_action_6_proc, | |
731 ag_action_7_proc, | |
732 ag_action_8_proc, | |
733 ag_action_9_proc, | |
734 ag_action_10_proc, | |
735 ag_action_11_proc, | |
736 ag_action_8_proc | |
737 }; | |
738 | |
739 | |
740 static int ag_action_10_proc(void) { | |
741 int ag_t = (PCB).token_number; | |
742 (PCB).btsx = 0, (PCB).drt = -1; | |
743 do { | |
744 ag_track(); | |
745 (PCB).token_number = (readhelp_token_type) AG_TCV(INPUT_CODE(*(PCB).la_ptr)); | |
746 (PCB).la_ptr++; | |
747 if (ag_key_index[(PCB).sn]) { | |
748 unsigned ag_k = ag_key_index[(PCB).sn]; | |
749 int ag_ch = CONVERT_CASE(INPUT_CODE(*(PCB).pointer)); | |
750 if (ag_ch <= 255) { | |
751 while (ag_key_ch[ag_k] < ag_ch) ag_k++; | |
752 if (ag_key_ch[ag_k] == ag_ch) ag_get_key_word(ag_k); | |
753 } | |
754 } | |
755 } while ((PCB).token_number == (readhelp_token_type) ag_t); | |
756 (PCB).la_ptr = (PCB).pointer; | |
757 return 1; | |
758 } | |
759 | |
760 static int ag_action_11_proc(void) { | |
761 int ag_t = (PCB).token_number; | |
762 | |
763 (PCB).btsx = 0, (PCB).drt = -1; | |
764 do { | |
765 (*(int *) &(PCB).vs[(PCB).ssx]) = *(PCB).pointer; | |
766 (PCB).ssx--; | |
767 ag_track(); | |
768 ag_ra(); | |
769 if ((PCB).exit_flag != AG_RUNNING_CODE) return 0; | |
770 (PCB).ssx++; | |
771 (PCB).token_number = (readhelp_token_type) AG_TCV(INPUT_CODE(*(PCB).la_ptr)); | |
772 (PCB).la_ptr++; | |
773 if (ag_key_index[(PCB).sn]) { | |
774 unsigned ag_k = ag_key_index[(PCB).sn]; | |
775 int ag_ch = CONVERT_CASE(INPUT_CODE(*(PCB).pointer)); | |
776 if (ag_ch <= 255) { | |
777 while (ag_key_ch[ag_k] < ag_ch) ag_k++; | |
778 if (ag_key_ch[ag_k] == ag_ch) ag_get_key_word(ag_k); | |
779 } | |
780 } | |
781 } | |
782 while ((PCB).token_number == (readhelp_token_type) ag_t); | |
783 (PCB).la_ptr = (PCB).pointer; | |
784 return 1; | |
785 } | |
786 | |
787 static int ag_action_3_r_proc(void) { | |
788 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
789 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
790 (PCB).btsx = 0, (PCB).drt = -1; | |
791 (PCB).reduction_token = (readhelp_token_type) ag_ptt[(PCB).ag_ap]; | |
792 ag_ra(); | |
793 return (PCB).exit_flag == AG_RUNNING_CODE; | |
794 } | |
795 | |
796 static int ag_action_3_s_proc(void) { | |
797 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
798 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
799 (PCB).btsx = 0, (PCB).drt = -1; | |
800 (PCB).reduction_token = (readhelp_token_type) ag_ptt[(PCB).ag_ap]; | |
801 ag_ra(); | |
802 return (PCB).exit_flag == AG_RUNNING_CODE; | |
803 } | |
804 | |
805 static int ag_action_4_r_proc(void) { | |
806 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
807 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
808 (PCB).reduction_token = (readhelp_token_type) ag_ptt[(PCB).ag_ap]; | |
809 return 1; | |
810 } | |
811 | |
812 static int ag_action_2_proc(void) { | |
813 (PCB).btsx = 0, (PCB).drt = -1; | |
814 if ((PCB).ssx >= 128) { | |
815 (PCB).exit_flag = AG_STACK_ERROR_CODE; | |
816 PARSER_STACK_OVERFLOW; | |
817 } | |
818 (*(int *) &(PCB).vs[(PCB).ssx]) = *(PCB).pointer; | |
819 GET_CONTEXT; | |
820 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
821 (PCB).ssx++; | |
822 (PCB).sn = (PCB).ag_ap; | |
823 ag_track(); | |
824 return 0; | |
825 } | |
826 | |
827 static int ag_action_9_proc(void) { | |
828 if ((PCB).drt == -1) { | |
829 (PCB).drt=(PCB).token_number; | |
830 (PCB).dssx=(PCB).ssx; | |
831 (PCB).dsn=(PCB).sn; | |
832 } | |
833 ag_prot(); | |
834 (PCB).vs[(PCB).ssx] = ag_null_value; | |
835 GET_CONTEXT; | |
836 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
837 (PCB).ssx++; | |
838 (PCB).sn = (PCB).ag_ap; | |
839 (PCB).la_ptr = (PCB).pointer; | |
840 return (PCB).exit_flag == AG_RUNNING_CODE; | |
841 } | |
842 | |
843 static int ag_action_2_r_proc(void) { | |
844 (PCB).ssx++; | |
845 (PCB).sn = (PCB).ag_ap; | |
846 return 0; | |
847 } | |
848 | |
849 static int ag_action_7_proc(void) { | |
850 --(PCB).ssx; | |
851 (PCB).la_ptr = (PCB).pointer; | |
852 (PCB).exit_flag = AG_SUCCESS_CODE; | |
853 return 0; | |
854 } | |
855 | |
856 static int ag_action_1_proc(void) { | |
857 ag_track(); | |
858 (PCB).exit_flag = AG_SUCCESS_CODE; | |
859 return 0; | |
860 } | |
861 | |
862 static int ag_action_1_r_proc(void) { | |
863 (PCB).exit_flag = AG_SUCCESS_CODE; | |
864 return 0; | |
865 } | |
866 | |
867 static int ag_action_1_s_proc(void) { | |
868 (PCB).exit_flag = AG_SUCCESS_CODE; | |
869 return 0; | |
870 } | |
871 | |
872 static int ag_action_4_proc(void) { | |
873 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
874 (PCB).reduction_token = (readhelp_token_type) ag_ptt[(PCB).ag_ap]; | |
875 (PCB).btsx = 0, (PCB).drt = -1; | |
876 (*(int *) &(PCB).vs[(PCB).ssx]) = *(PCB).pointer; | |
877 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
878 else GET_CONTEXT; | |
879 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
880 ag_track(); | |
881 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
882 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
883 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
884 do { | |
885 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
886 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
887 else ag_t2 = ag_tx; | |
888 } while (ag_t1 < ag_t2); | |
889 (PCB).ag_ap = ag_pstt[ag_t1]; | |
890 if ((ag_s_procs_scan[ag_astt[ag_t1]])() == 0) break; | |
891 } | |
892 return 0; | |
893 } | |
894 | |
895 static int ag_action_3_proc(void) { | |
896 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
897 (PCB).btsx = 0, (PCB).drt = -1; | |
898 (*(int *) &(PCB).vs[(PCB).ssx]) = *(PCB).pointer; | |
899 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
900 else GET_CONTEXT; | |
901 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
902 ag_track(); | |
903 (PCB).reduction_token = (readhelp_token_type) ag_ptt[(PCB).ag_ap]; | |
904 ag_ra(); | |
905 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
906 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
907 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
908 do { | |
909 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
910 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
911 else ag_t2 = ag_tx; | |
912 } while (ag_t1 < ag_t2); | |
913 (PCB).ag_ap = ag_pstt[ag_t1]; | |
914 if ((ag_s_procs_scan[ag_astt[ag_t1]])() == 0) break; | |
915 } | |
916 return 0; | |
917 } | |
918 | |
919 static int ag_action_8_proc(void) { | |
920 ag_undo(); | |
921 (PCB).la_ptr = (PCB).pointer; | |
922 (PCB).exit_flag = AG_SYNTAX_ERROR_CODE; | |
923 ag_diagnose(); | |
924 SYNTAX_ERROR; | |
925 {(PCB).la_ptr = (PCB).pointer + 1; ag_track();} | |
926 return (PCB).exit_flag == AG_RUNNING_CODE; | |
927 } | |
928 | |
929 static int ag_action_5_proc(void) { | |
930 int ag_sd = ag_fl[(PCB).ag_ap]; | |
931 (PCB).btsx = 0, (PCB).drt = -1; | |
932 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
933 else { | |
934 GET_CONTEXT; | |
935 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
936 } | |
937 (PCB).la_ptr = (PCB).pointer; | |
938 (PCB).reduction_token = (readhelp_token_type) ag_ptt[(PCB).ag_ap]; | |
939 ag_ra(); | |
940 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
941 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
942 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
943 do { | |
944 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
945 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
946 else ag_t2 = ag_tx; | |
947 } while (ag_t1 < ag_t2); | |
948 (PCB).ag_ap = ag_pstt[ag_t1]; | |
949 if ((ag_r_procs_scan[ag_astt[ag_t1]])() == 0) break; | |
950 } | |
951 return (PCB).exit_flag == AG_RUNNING_CODE; | |
952 } | |
953 | |
954 static int ag_action_6_proc(void) { | |
955 int ag_sd = ag_fl[(PCB).ag_ap]; | |
956 (PCB).reduction_token = (readhelp_token_type) ag_ptt[(PCB).ag_ap]; | |
957 if ((PCB).drt == -1) { | |
958 (PCB).drt=(PCB).token_number; | |
959 (PCB).dssx=(PCB).ssx; | |
960 (PCB).dsn=(PCB).sn; | |
961 } | |
962 if (ag_sd) { | |
963 (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
964 } | |
965 else { | |
966 ag_prot(); | |
967 (PCB).vs[(PCB).ssx] = ag_null_value; | |
968 GET_CONTEXT; | |
969 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
970 } | |
971 (PCB).la_ptr = (PCB).pointer; | |
972 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
973 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
974 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
975 do { | |
976 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
977 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
978 else ag_t2 = ag_tx; | |
979 } while (ag_t1 < ag_t2); | |
980 (PCB).ag_ap = ag_pstt[ag_t1]; | |
981 if ((ag_r_procs_scan[ag_astt[ag_t1]])() == 0) break; | |
982 } | |
983 return (PCB).exit_flag == AG_RUNNING_CODE; | |
984 } | |
985 | |
986 | |
987 void init_readhelp(void) { | |
988 (PCB).la_ptr = (PCB).pointer; | |
989 (PCB).ss[0] = (PCB).sn = (PCB).ssx = 0; | |
990 (PCB).exit_flag = AG_RUNNING_CODE; | |
991 (PCB).line = FIRST_LINE; | |
992 (PCB).column = FIRST_COLUMN; | |
993 (PCB).btsx = 0, (PCB).drt = -1; | |
994 } | |
995 | |
996 void readhelp(void) { | |
997 init_readhelp(); | |
998 (PCB).exit_flag = AG_RUNNING_CODE; | |
999 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
1000 unsigned ag_t1 = ag_sbt[(PCB).sn]; | |
1001 if (ag_tstt[ag_t1]) { | |
1002 unsigned ag_t2 = ag_sbe[(PCB).sn] - 1; | |
1003 (PCB).token_number = (readhelp_token_type) AG_TCV(INPUT_CODE(*(PCB).la_ptr)); | |
1004 (PCB).la_ptr++; | |
1005 if (ag_key_index[(PCB).sn]) { | |
1006 unsigned ag_k = ag_key_index[(PCB).sn]; | |
1007 int ag_ch = CONVERT_CASE(INPUT_CODE(*(PCB).pointer)); | |
1008 if (ag_ch <= 255) { | |
1009 while (ag_key_ch[ag_k] < ag_ch) ag_k++; | |
1010 if (ag_key_ch[ag_k] == ag_ch) ag_get_key_word(ag_k); | |
1011 } | |
1012 } | |
1013 do { | |
1014 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
1015 if (ag_tstt[ag_tx] > (unsigned char)(PCB).token_number) | |
1016 ag_t1 = ag_tx + 1; | |
1017 else ag_t2 = ag_tx; | |
1018 } while (ag_t1 < ag_t2); | |
1019 if (ag_tstt[ag_t1] != (unsigned char)(PCB).token_number) | |
1020 ag_t1 = ag_sbe[(PCB).sn]; | |
1021 } | |
1022 (PCB).ag_ap = ag_pstt[ag_t1]; | |
1023 (ag_gt_procs_scan[ag_astt[ag_t1]])(); | |
1024 } | |
1025 } | |
1026 | |
1027 |