Mercurial > ~dholland > hg > ag > index.cgi
comparison help2html/mhh6.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 /* | |
3 * AnaGram, A System for Syntax Directed Programming | |
4 * File generated by: Version 2.40-current, built Jun 13 2007 | |
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 MHH6_H_1193795958 | |
27 #include "mhh6.h" | |
28 #endif | |
29 | |
30 #ifndef MHH6_H_1193795958 | |
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 mhh6_pcb_type mhh6_pcb; | |
44 #define PCB mhh6_pcb | |
45 | |
46 #line 387 "/disk/disk0/home/dholland/projects/ag/src/help2html/mhh6.syn" | |
47 /* ----- Embedded C --------------------------------------------*/ | |
48 | |
49 | |
50 #include <stdio.h> | |
51 #include <string.h> | |
52 #include <malloc.h> | |
53 #include <assert.h> | |
54 #include <ctype.h> | |
55 #include <assert.h> | |
56 #include <err.h> | |
57 #include "uintarray.h" | |
58 #include "support.h" | |
59 #include "buffer.h" | |
60 #include "stringdict.h" | |
61 #include "must.h" | |
62 | |
63 int verbose = 0; | |
64 | |
65 int total1sttextline = 0; | |
66 int total1sttextlineb = 0; | |
67 int total1sttableline = 0; | |
68 int total1stlist1line = 0; | |
69 int total1stlist2line = 0; | |
70 int total1stlisttabline = 0; | |
71 int total1stcodeline = 0; | |
72 | |
73 int title_count =0; | |
74 int title_line_count = 0; | |
75 | |
76 char *helpentStr; | |
77 struct buffer title; | |
78 struct buffer title1; | |
79 struct buffer titleLine; | |
80 struct buffer titleLine1; | |
81 struct stringdict *titleDict; | |
82 struct stringdict *titleDict1; // upper case | |
83 struct stringdict *titleLineDict; | |
84 struct stringdict *titleLineDict1; // upper case | |
85 struct buffer topicFrag; | |
86 struct buffer tabFrag; | |
87 struct buffer blankFrag; | |
88 struct buffer topicBody; | |
89 struct stringdict *topicBodyDict; | |
90 struct uintarray titleToTitleLine; | |
91 struct intstack paragType; | |
92 | |
93 enum paragTypes {Tnone=0, Ttext=1, Ttable=2, Tlist1=3, Tlist2=4, | |
94 Tlisttab=5, Tcode=6}; | |
95 | |
96 char *charToEntity(const char *instring); | |
97 void putTitle(void); | |
98 void appendTitle(void); | |
99 void saveTitleLine(void); | |
100 void appendEnd(int c); | |
101 void removeFinalNewline(void); | |
102 void saveTopicBody(void); | |
103 void printDict(const struct stringdict *dictionary); | |
104 void writeSortedHtml(FILE *output); | |
105 void writeFullTopics(FILE *output, const struct stringdict *dictionary, | |
106 const struct stringdict *dictionary1, | |
107 const struct stringdict *dictionaryb); | |
108 void writeTitles(FILE *output, const struct stringdict *dictionary, | |
109 const struct stringdict *dictionary1); | |
110 int processLinkString(FILE *filein, FILE *fileout); | |
111 | |
112 | |
113 // replace &, <, > in S with entities | |
114 char *charToEntity(const char *s) { | |
115 char *ret; | |
116 int i, j, len=0; | |
117 | |
118 for (i=0; s[i]; i++) { | |
119 if (s[i] == '&') len += 5; /* & */ | |
120 else if (s[i] == '<') len += 4; /* < */ | |
121 else if (s[i] == '>') len += 4; /* > */ | |
122 else len++; | |
123 } | |
124 | |
125 ret = malloc(len+1); | |
126 if (!ret) { | |
127 errx(1, "Out of memory"); | |
128 } | |
129 | |
130 for (i=j=0; s[i]; i++) { | |
131 if (s[i] == '&') { strcpy(ret+j, "&"); j += 5; } | |
132 else if (s[i] == '<' ) { strcpy(ret+j, "<"); j += 4; } | |
133 else if (s[i] == '>' ) { strcpy(ret+j, ">"); j += 4; } | |
134 else ret[j++] = s[i]; | |
135 } | |
136 ret[j] = 0; | |
137 | |
138 return ret; | |
139 } | |
140 | |
141 // Save title both ways, make map entry for title<--->title line | |
142 void saveTitle(void) { | |
143 if (stringdict_exists(titleDict, title.text)) { | |
144 fprintf( stderr, "Warning: Repeated title %s\n", title.text ); | |
145 } | |
146 #if 0 | |
147 else if (!strcmp(title.text, "Secret of Life")) { | |
148 // Do not save "Secret of Life" title | |
149 return; | |
150 } | |
151 #endif | |
152 else { | |
153 // Save title in dictionary | |
154 unsigned titleIndex = stringdict_intern(titleDict, title.text); | |
155 | |
156 // Save title in upper case dictionary | |
157 stringdict_intern(titleDict1, title1.text); | |
158 | |
159 // count() should give next index | |
160 unsigned titleLineIndex = stringdict_count(titleLineDict); | |
161 | |
162 // use an array for this (the keys are array indexes anyway) | |
163 if (titleIndex >= uintarray_num(&titleToTitleLine)) { | |
164 unsigned x, old = uintarray_num(&titleToTitleLine); | |
165 uintarray_setsize(&titleToTitleLine, titleIndex+1); | |
166 for (x=old; x<titleIndex; x++) { | |
167 uintarray_set(&titleToTitleLine, x, (unsigned) -1); | |
168 } | |
169 } | |
170 // Store indices in map | |
171 uintarray_set(&titleToTitleLine, titleIndex, titleLineIndex); | |
172 } | |
173 } | |
174 | |
175 | |
176 void putTitle(void) { | |
177 // Save title itself in both reg. and upper case title dicts | |
178 saveTitle(); | |
179 buffer_append(&titleLine, title.text); | |
180 buffer_append(&titleLine1, title1.text); | |
181 } | |
182 | |
183 | |
184 void appendTitle() { | |
185 // Save title itself in both reg. and upper case title dicts | |
186 saveTitle(); | |
187 buffer_append(&titleLine, ", "); | |
188 buffer_append(&titleLine1, ", "); | |
189 buffer_append(&titleLine, title.text); | |
190 buffer_append(&titleLine1, title1.text); | |
191 } | |
192 | |
193 | |
194 void saveTitleLine() { | |
195 #if 0 | |
196 static int foundSoL=0; | |
197 if (stringdict_count(titleLineDict)==0 && | |
198 strcmp(titleLine.text, "Secret of Life")!=0 && foundSoL==0) { | |
199 fprintf(stderr, "Warning: Secret of Life does not lead file!\n"); | |
200 } | |
201 #endif | |
202 | |
203 #if 0 | |
204 if (!strcmp(titleLine.text, "Secret of Life")) { | |
205 // Don't save title line in dicts. | |
206 // Should be at beginning of help file | |
207 assert(stringdict_count(titleLineDict)==0); | |
208 foundSoL = 1; | |
209 if (verbose) { | |
210 printf( "\n Found Secret of Life!\n\n" ); | |
211 } | |
212 } | |
213 else | |
214 #endif | |
215 if ( stringdict_exists(titleLineDict, titleLine.text) ) { | |
216 fprintf( stderr, "Warning: Repeated title line %s\n", | |
217 titleLine.text ); | |
218 } | |
219 else { | |
220 // Save title line in dictionary | |
221 stringdict_intern(titleLineDict, titleLine.text); | |
222 // Save title line in upper case dictionary | |
223 stringdict_intern(titleLineDict1, titleLine1.text); | |
224 } | |
225 buffer_clear(&titleLine); | |
226 buffer_clear(&titleLine1); | |
227 } | |
228 | |
229 | |
230 // Append the latter part of the line | |
231 void appendEnd(int c) { | |
232 buffer_add(&topicBody, c); | |
233 buffer_append(&topicBody, topicFrag.text); | |
234 buffer_append(&topicBody, "\n" ); | |
235 buffer_clear(&topicFrag); | |
236 } | |
237 | |
238 // Append a cell to the table row | |
239 void appendTableCell(int c) { | |
240 // Could insert <pre> </pre> or <code> </code> tags here for cell | |
241 buffer_append(&topicBody, "<code> " ); | |
242 buffer_add(&topicBody, c); | |
243 buffer_append(&topicBody, topicFrag.text); | |
244 buffer_append(&topicBody, "</code>" ); | |
245 //buffer_append(&topicBody, "\n" ); | |
246 buffer_clear(&topicFrag); | |
247 } | |
248 | |
249 void removeFinalNewline(void) { | |
250 int x = topicBody.len; | |
251 assert(topicBody.text[x-2]=='\n' && topicBody.text[x-1]=='\n'); | |
252 topicBody.text[x-1] = 0; | |
253 } | |
254 | |
255 void saveTopicBody(void) { | |
256 #if 0 | |
257 // do not save Secret of Life topic body | |
258 if (stringdict_count(titleLineDict) != 0) { | |
259 #endif | |
260 // save topic body | |
261 stringdict_intern(topicBodyDict, topicBody.text); | |
262 #if 0 | |
263 } | |
264 #endif | |
265 buffer_clear(&topicBody); | |
266 } | |
267 | |
268 /* | |
269 void startTable(void) { | |
270 // If we don't currently have table, start a new one | |
271 if (paragType.top() != Ttable) { | |
272 // Start table | |
273 paragType.push( Ttable ); | |
274 } | |
275 } | |
276 */ | |
277 | |
278 void finishList(int listtype){ | |
279 //printf( "\nfinishList() - top type = %d, listtype = %d, " | |
280 // "stack size = %d\n" | |
281 // " titleLineDict size = %d\n", | |
282 // paragType.top(), listtype, paragType.size(), | |
283 // titleLineDict.size() ); | |
284 assert(intstack_top(¶gType) == listtype); | |
285 intstack_pop(¶gType); | |
286 buffer_append(&topicBody, "\n</ul>"); | |
287 } | |
288 | |
289 void printDict(const struct stringdict *dictionary) { | |
290 unsigned i; | |
291 for (i=0; i<stringdict_count(dictionary); i++) { | |
292 printf("%4d: %s\n", i, stringdict_getbynum(dictionary, i)); | |
293 } | |
294 } | |
295 | |
296 char *SqueezeWS(const char *Input) { | |
297 /* return a (strdup()-like) copy of Input, with whitespace squeezed out */ | |
298 char *copy; | |
299 int cnt, outcnt; | |
300 | |
301 copy = must_malloc(strlen(Input)+1); | |
302 | |
303 for (cnt=0, outcnt=0; Input[cnt]; cnt++) { | |
304 unsigned char ch = Input[cnt]; | |
305 if (!isspace(ch)) { | |
306 copy[outcnt]=ch; | |
307 outcnt++; | |
308 } | |
309 } | |
310 copy[outcnt]=0; | |
311 | |
312 return copy; | |
313 } | |
314 | |
315 void writeFullTopics(FILE *output, | |
316 const struct stringdict *dictionary, /* title lines */ | |
317 const struct stringdict *dictionary1, /* UC titlelines*/ | |
318 const struct stringdict *dictionaryb) /* topic bodies */ | |
319 { | |
320 unsigned i; | |
321 | |
322 #if 0 | |
323 /* Write "Secret of Life" topic at beginning of topics */ | |
324 //fprintf(output, "Secret of Life>\n\n"); | |
325 //fprintf(output, "No help message for this topic.\n##\n"); | |
326 #endif | |
327 | |
328 assert( stringdict_count(dictionary) == stringdict_count(dictionary1) ); | |
329 struct permutation *perm = mySort(dictionary1); // Sort dictionary1 | |
330 | |
331 | |
332 /* Write out topics in a definition list <dl> */ | |
333 fprintf( output, "\n\n<dl>\n\n" ); | |
334 | |
335 // write dictionary, sorted according to dict1 | |
336 for (i = 0; i < stringdict_count(dictionary); i++) { | |
337 //fprintf(output, "<dt><b><a name=\"%04d\">%s</a></b></dt>\n" | |
338 // "<dd>%s\n</dd><br/>\n\n", | |
339 // perm->v[i], | |
340 // stringdict_getbynum(dictionary, perm->v[i]), | |
341 // stringdict_getbynum(dictionaryb, perm->v[i]) ); | |
342 | |
343 char *anchorname=SqueezeWS(stringdict_getbynum(dictionary, perm->v[i])); | |
344 fprintf(output, "<dt><b><a name=\"%s\">%s</a></b></dt>\n" | |
345 "<dd>%s\n</dd>\n\n", | |
346 anchorname, | |
347 stringdict_getbynum(dictionary, perm->v[i]), | |
348 stringdict_getbynum(dictionaryb, perm->v[i]) ); | |
349 free(anchorname); | |
350 } | |
351 fprintf( output, "\n\n</dl>\n\n" ); | |
352 permutation_destroy(perm); | |
353 } | |
354 | |
355 void writeTitles(FILE *output, | |
356 const struct stringdict *dictionary, /* titles */ | |
357 const struct stringdict *dictionary1) /* uppercase titles */ | |
358 { | |
359 assert( stringdict_count(dictionary) == stringdict_count(dictionary1) ); | |
360 struct permutation *perm = mySort(dictionary1); // Sort dictionary1 | |
361 | |
362 /* Write 2-column table of titles */ | |
363 /* | |
364 // n_t is true title count w/o Secret of Life | |
365 int n_t = stringdict_count(dictionary); | |
366 // we better have some titles | |
367 assert( n_t >= 2 ); | |
368 // n_t1 is #titles in 1st column | |
369 int n_t1 = n_t%2 ? n_t/2 +1 : n_t/2; | |
370 // n_t2 is #titles in 2nd column | |
371 int n_t2 = n_t%2; | |
372 int i; | |
373 fprintf( output, "\n\n<table width=\"100%%\" " | |
374 "style=\"margin-left: auto ; margin-right: auto\" \n" | |
375 " cellpadding=\"15\" cellspacing=\"5\" >\n" | |
376 "<tr align=\"left\">\n" | |
377 "<td valign=\"top\" style=\"white-space: nowrap\">" | |
378 "\n\n\n"); | |
379 | |
380 // Write out dictionary sorted acc. to dictionary1 | |
381 // write out the first half, sorted | |
382 for (i = 0; i < n_t1; i++) { | |
383 fprintf(output, " \xA9%s\xAA\n<br/>", | |
384 stringdict_getbynum(dictionary, perm->v[i])); | |
385 } | |
386 | |
387 fprintf(output, "</td>\n\n"); | |
388 fprintf(output, "<td valign=\"top\" style=\"white-space: nowrap\">\n\n"); | |
389 | |
390 // write out the last half, sorted | |
391 for ( i = n_t1; i < n_t; i++) { | |
392 fprintf(output, " \xA9%s\xAA\n<br/>", | |
393 stringdict_getbynum(dictionary, perm->v[i])); | |
394 } | |
395 | |
396 fprintf(output, "</td>\n</tr>\n</table>\n\n<hr><br/><br/>\n\n" ); | |
397 */ | |
398 | |
399 /* Write 1-column list of titles */ | |
400 | |
401 // n_t is true title count w/o Secret of Life | |
402 unsigned n_t = stringdict_count(dictionary); | |
403 // we better have some titles | |
404 assert( n_t >= 2 ); | |
405 unsigned i; | |
406 | |
407 fprintf(output, "<h2>Help Topic Index</h2>\n\n" ); | |
408 // Write out the index, sorted acc. to dictionary1 | |
409 for (i = 0; i < n_t; i++) { | |
410 fprintf(output, "\xA9%s\xAA\n<br/>", | |
411 stringdict_getbynum(dictionary, perm->v[i])); | |
412 } | |
413 } | |
414 | |
415 void writeSortedHtml( FILE *output ) { | |
416 /* Leading HTML */ | |
417 | |
418 #ifdef XML_OUTPUT | |
419 fprintf(output, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" | |
420 "<?xml-stylesheet type=\"text/xsl\" href=\"../ag_web.xml\"?>\n" | |
421 "\n" | |
422 "<body rootdir=\"..\" navname=\"Documentation: AnaGram Help\">\n"); | |
423 | |
424 #else | |
425 fprintf(output, "<html>\n<head>\n"); | |
426 fprintf(output, "<title>AnaGram Help Topics - HTML version</title>\n"); | |
427 fprintf(output, "</head>\n\n\n"); | |
428 fprintf(output, "<body bgcolor=\"#ffffff\" text=\"#000000\""); | |
429 fprintf(output, " link=\"#0033CC\" vlink=\"#CC0033\" alink=\"#CC0099\">"); | |
430 fprintf(output, "\n\n\n"); | |
431 #endif | |
432 | |
433 /* Write page title */ | |
434 #ifdef XML_OUTPUT | |
435 fprintf(output, "<h1>AnaGram Help</h1>\n\n"); | |
436 #else | |
437 fprintf(output, "<hr><h2>AnaGram Help Topics - HTML Version</h2><hr>\n\n"); | |
438 #endif | |
439 /* Write 2-column table of titles */ | |
440 writeTitles( output, titleDict, titleDict1 ); | |
441 | |
442 /* Write full topics in single- column table */ | |
443 //fprintf( output, "\n\n<table width=\"100%%\">\n<tr><td>\n<p>\n\n"); | |
444 //writeFullTopics( output, titleLineDict, titleLineDict1, topicBodyDict ); | |
445 //fprintf( output, "</td></tr>\n</table>\n" ); | |
446 | |
447 /* Write full topics directly to the output page */ | |
448 writeFullTopics( output, titleLineDict, titleLineDict1, topicBodyDict ); | |
449 | |
450 #ifdef XML_OUTPUT | |
451 fprintf(output,"\n</body>\n"); | |
452 #else | |
453 /* Ending HTML */ | |
454 fprintf( output, "\n<p><br/><address><a " | |
455 "NAME=\"copyright\">AnaGram Help Topics, HTML version.</a>\n" | |
456 "<br> Copyright © Parsifal Software, 2001.<br>\n" | |
457 "All Rights Reserved.</address>" | |
458 "\n\n</body>\n</html>\n\n" ); | |
459 #endif | |
460 } | |
461 | |
462 int processLinkString( FILE *filein, FILE *fileout ) { | |
463 struct buffer linkString; // lower case | |
464 struct buffer linkString1; // upper case version | |
465 unsigned index; | |
466 int c; | |
467 int wspaceFlag =0; | |
468 | |
469 buffer_init(&linkString); | |
470 buffer_init(&linkString1); | |
471 | |
472 while ( (c=fgetc(filein)) != EOF ) { | |
473 | |
474 if ( c != 0xAA) { // test for end of link char | |
475 if ( c == 0x20 || c == 0x0D || c == 0x0A ) { | |
476 // don't append these chars | |
477 wspaceFlag = 1; | |
478 } | |
479 else { | |
480 if (wspaceFlag) { | |
481 // Replace space, cr, lf with single space | |
482 buffer_add(&linkString, 0x20); | |
483 buffer_add(&linkString1, toupper(0x20)); | |
484 } | |
485 buffer_add(&linkString, c); | |
486 buffer_add(&linkString1, toupper(c)); | |
487 wspaceFlag = 0; | |
488 } | |
489 } | |
490 else { | |
491 // end of link - look up using upper case string | |
492 if (!stringdict_exists(titleDict1, linkString1.text)) { | |
493 // try match w/o final S | |
494 if ( linkString1.text[linkString1.len - 1] == 'S' ) { | |
495 linkString1.text[linkString1.len - 1] = 0; | |
496 if (stringdict_exists(titleDict1, linkString1.text)) { | |
497 goto matched; // Eccch - a goto! | |
498 } | |
499 } | |
500 | |
501 fprintf(stderr, "Can't find this link in titleDict1: %s\n", | |
502 linkString1.text); | |
503 return 21; | |
504 } | |
505 | |
506 /* find corresp. index in title line direc. */ | |
507 matched: | |
508 | |
509 index = stringdict_findbyname(titleDict1, linkString1.text); | |
510 | |
511 unsigned ilink = uintarray_get(&titleToTitleLine, index); | |
512 assert(ilink != (unsigned) -1); | |
513 | |
514 // Write out string, linked to title line | |
515 char *linkname=SqueezeWS(stringdict_getbynum(titleLineDict, ilink)); | |
516 //fprintf(fileout, "<a href=\"#%04d\">%s</a>", ilink, linkString.text); | |
517 fprintf( fileout, "<a href=\"#%s\">%s</a>", linkname, linkString.text); | |
518 free(linkname); | |
519 | |
520 buffer_cleanup(&linkString); | |
521 buffer_cleanup(&linkString1); | |
522 | |
523 return 0; // normal return - have found and written link | |
524 } | |
525 } | |
526 // Error - unexpected end of file | |
527 fprintf(stderr, "Error: EOF detected while searching for end of link.\n"); | |
528 fprintf(stderr, " Current link string is: %s\n", linkString.text ); | |
529 return 23; | |
530 } | |
531 | |
532 static void init(void) { | |
533 buffer_init(&title); | |
534 buffer_init(&title1); | |
535 buffer_init(&titleLine); | |
536 buffer_init(&titleLine1); | |
537 titleDict = stringdict_create(); | |
538 titleDict1 = stringdict_create(); | |
539 titleLineDict = stringdict_create(); | |
540 titleLineDict1 = stringdict_create(); | |
541 topicBodyDict = stringdict_create(); | |
542 buffer_init(&topicFrag); | |
543 buffer_init(&tabFrag); | |
544 buffer_init(&blankFrag); | |
545 buffer_init(&topicBody); | |
546 intstack_init(¶gType); | |
547 uintarray_init(&titleToTitleLine); | |
548 } | |
549 | |
550 /* -- Main Program -- */ | |
551 | |
552 int main(int argc, char *argv[]) { | |
553 | |
554 FILE *input; | |
555 | |
556 long fileLength; | |
557 size_t stringLength; | |
558 char *helpsrcString; | |
559 | |
560 init(); | |
561 | |
562 if (verbose) { | |
563 printf( "\n This program reads a help.src-type file, " | |
564 "replaces &, <, > with entities,\n" | |
565 "sorts in a case-insensitive manner and writes " | |
566 "to output file as HTML\n" | |
567 "with a preceding list of the help topics. \n\n" ); | |
568 } | |
569 | |
570 /* Check for enough arguments */ | |
571 if (argc != 3) { | |
572 fprintf(stderr, "Usage: mhh6 helpdata.src help.html\n"); | |
573 return 1; | |
574 } | |
575 | |
576 /* Open input file */ | |
577 input = fopen(argv[1],"r"); | |
578 if (input == NULL) { | |
579 fprintf(stderr, "Cannot open %s\n", argv[1]); | |
580 return 2; | |
581 } | |
582 | |
583 /* find out how big the input file is */ | |
584 if (fseek(input, SEEK_SET, SEEK_END)) { | |
585 fprintf(stderr, "Strange problems with %s\n", argv[1]); | |
586 return 3; | |
587 } | |
588 fileLength = ftell(input); | |
589 if (fileLength < 0 ) { // -1L is error return | |
590 fprintf(stderr, "Error getting file length (%ld) of %s\n", | |
591 fileLength, argv[1]); | |
592 return 4; | |
593 } | |
594 | |
595 /* fseek to beginning of file */ | |
596 if (fseek(input, 0, SEEK_SET)) { | |
597 fprintf(stderr, "Strange problems with %s\n", argv[1]); | |
598 return 5; | |
599 } | |
600 | |
601 /* Allocate storage for input string */ | |
602 helpsrcString = must_malloc(fileLength + 1); | |
603 | |
604 /* read file */ | |
605 stringLength = fread(helpsrcString, 1, (unsigned)fileLength, input); | |
606 if (stringLength == 0) { | |
607 fprintf(stderr, "Unable to read %s\n", argv[1]); | |
608 free(helpsrcString); | |
609 fclose(input); | |
610 return 7; | |
611 } | |
612 // Terminate string with null | |
613 helpsrcString[stringLength] = 0; | |
614 | |
615 /* first, replace < > & with entities */ | |
616 helpentStr = charToEntity( helpsrcString ); | |
617 | |
618 /* no more need for input string or file */ | |
619 free(helpsrcString); | |
620 fclose(input); | |
621 | |
622 /* initialize stack of parag types */ | |
623 intstack_push(¶gType, Tnone); | |
624 | |
625 /* call parser */ | |
626 PCB.pointer = (unsigned char *)(const char *)helpentStr; | |
627 mhh6(); | |
628 | |
629 /* Print file statistics */ | |
630 if (verbose) { | |
631 printf("No. of title lines in line dict.= %d\n", | |
632 stringdict_count(titleLineDict) ); | |
633 printDict(titleLineDict); // print title lines | |
634 printf( "\n\n" ); | |
635 | |
636 printf( "title count = %d, includes Secret of Life \n\n", title_count ); | |
637 printf( "title line count = %d, includes Secret of Life \n\n", | |
638 title_line_count ); | |
639 printf( "total1sttextline = %d, \n", total1sttextline ); | |
640 printf( "total1sttextlineb = %d \n", total1sttextlineb ); | |
641 printf( "total1sttableline = %d \n", total1sttableline ); | |
642 printf( "total1stlist1line = %d \n", total1stlist1line ); | |
643 printf( "total1stlist2line = %d \n", total1stlist2line ); | |
644 printf( "total1stlisttabline = %d \n", total1stlisttabline ); | |
645 printf( "total1stcodeline = %d \n", total1stcodeline ); | |
646 } | |
647 | |
648 /* check for error */ | |
649 if (verbose) { | |
650 printf( "PCB.exit_flag = %d (%d for success)\n", PCB.exit_flag, | |
651 AG_SUCCESS_CODE); | |
652 } | |
653 if (PCB.exit_flag != AG_SUCCESS_CODE) { | |
654 fprintf(stderr, "File %s: error at line %d, column %d\n", | |
655 argv[1], | |
656 PCB.line, | |
657 PCB.column); | |
658 return 8; | |
659 } | |
660 | |
661 // Write sorted title lines & topics as HTML to intermediate file | |
662 FILE *intermed; | |
663 const char *filename = "intermed.html"; | |
664 /* Open intermediate file */ | |
665 intermed = fopen(filename ,"w+"); // create intermediate text file | |
666 if (intermed == NULL) { | |
667 fprintf(stderr, "Cannot open %s\n", filename); | |
668 return 9; | |
669 } | |
670 if (verbose) { | |
671 printf( "Writing sorted title lines & topic bodies to " | |
672 "intermediate file in HTML format...\n"); | |
673 } | |
674 writeSortedHtml(intermed); | |
675 rewind(intermed); | |
676 | |
677 /* Create output HTML file, inserting links */ | |
678 FILE *output; | |
679 /* Open output file */ | |
680 output = fopen(argv[2] ,"w"); | |
681 if (output == NULL) { | |
682 fprintf(stderr, "Cannot open %s\n", argv[2]); | |
683 return 10; | |
684 } | |
685 | |
686 if (verbose) { | |
687 printf( "Writing output file with HTML links...\n"); | |
688 } | |
689 | |
690 int c = 0; | |
691 int ctest = 0; | |
692 | |
693 while ( (c=fgetc(intermed)) != EOF ){ | |
694 | |
695 if ( c == 0xA9 ) { // begins link string | |
696 // printf( "\n Found beginning of link" ); | |
697 int itest = processLinkString(intermed, output); | |
698 if (itest !=0) return itest; // error return | |
699 } | |
700 else { | |
701 ctest = fputc( c, output ); // write out current character | |
702 if (ctest == EOF) return 11; | |
703 } | |
704 } | |
705 | |
706 fclose(intermed); | |
707 fclose(output); | |
708 | |
709 | |
710 /* done */ | |
711 if (verbose) { | |
712 printf( "All done.\n" ); | |
713 } | |
714 return 0; // normal return | |
715 | |
716 } /* -- End of main() function -- */ | |
717 | |
718 #line 719 "mhh6.c" | |
719 | |
720 #ifndef CONVERT_CASE | |
721 #define CONVERT_CASE(c) (c) | |
722 #endif | |
723 #ifndef TAB_SPACING | |
724 #define TAB_SPACING 8 | |
725 #endif | |
726 | |
727 static void ag_rp_1(void) { | |
728 #line 71 "/disk/disk0/home/dholland/projects/ag/src/help2html/mhh6.syn" | |
729 title_line_count++; | |
730 // buffer_append(&titleLine, "</h3>\n<p>"); | |
731 saveTitleLine(); | |
732 | |
733 #line 734 "mhh6.c" | |
734 } | |
735 | |
736 #define ag_rp_2() (title_count++, putTitle()) | |
737 | |
738 #define ag_rp_3() (title_count++, appendTitle()) | |
739 | |
740 #define ag_rp_4(c) (buffer_start(&title, c), buffer_start(&title1, toupper(c))) | |
741 | |
742 #define ag_rp_5(c) (buffer_add(&title, c), buffer_add(&title1, toupper(c))) | |
743 | |
744 static void ag_rp_6(void) { | |
745 #line 92 "/disk/disk0/home/dholland/projects/ag/src/help2html/mhh6.syn" | |
746 saveTopicBody(); | |
747 #line 748 "mhh6.c" | |
748 } | |
749 | |
750 #define ag_rp_7() (buffer_append(&topicBody,"\n")) | |
751 | |
752 #define ag_rp_8() (buffer_append(&topicBody,"\n")) | |
753 | |
754 #define ag_rp_9() (finishList(Tlist1)) | |
755 | |
756 #define ag_rp_10() (finishList(Tlist2)) | |
757 | |
758 #define ag_rp_11() (finishList(Tlisttab)) | |
759 | |
760 #define ag_rp_12() (finishList(Tlist1)) | |
761 | |
762 #define ag_rp_13() (finishList(Tlisttab)) | |
763 | |
764 #define ag_rp_14() (buffer_append(&topicBody, "<p>")) | |
765 | |
766 #define ag_rp_15() (buffer_append(&topicBody, "</p>")) | |
767 | |
768 #define ag_rp_16() (buffer_append(&topicBody, "\n</table>\n\n")) | |
769 | |
770 #define ag_rp_17() (buffer_append(&topicBody, "</li>\n")) | |
771 | |
772 #define ag_rp_18() (buffer_append(&topicBody, "</li>\n")) | |
773 | |
774 #define ag_rp_19() (buffer_append(&topicBody, "</li>\n")) | |
775 | |
776 #define ag_rp_20() (buffer_append(&topicBody, "</li>\n")) | |
777 | |
778 #define ag_rp_21() (buffer_append(&topicBody, "</li>\n")) | |
779 | |
780 #define ag_rp_22() (buffer_append(&topicBody, "</li>\n")) | |
781 | |
782 #define ag_rp_23() (buffer_append(&topicBody, "\n</pre>")) | |
783 | |
784 static void ag_rp_24(int c) { | |
785 #line 172 "/disk/disk0/home/dholland/projects/ag/src/help2html/mhh6.syn" | |
786 total1sttextline++; | |
787 appendEnd(c); | |
788 | |
789 #line 790 "mhh6.c" | |
790 } | |
791 | |
792 static void ag_rp_25(int c) { | |
793 #line 176 "/disk/disk0/home/dholland/projects/ag/src/help2html/mhh6.syn" | |
794 total1sttextlineb++; | |
795 buffer_add(&topicBody, 0x20); | |
796 appendEnd(c); | |
797 | |
798 #line 799 "mhh6.c" | |
799 } | |
800 | |
801 #define ag_rp_26(c) (appendEnd(c)) | |
802 | |
803 #define ag_rp_27() (buffer_append(&topicBody, "</td></tr>")) | |
804 | |
805 static void ag_rp_28(int c) { | |
806 #line 211 "/disk/disk0/home/dholland/projects/ag/src/help2html/mhh6.syn" | |
807 | |
808 total1sttableline++; | |
809 buffer_append(&topicBody, | |
810 "\n\n<table cellpadding=\"7\" cellspacing=\"2\" >\n<tr><td> "); | |
811 appendTableCell(c); | |
812 buffer_clear(&tabFrag); | |
813 buffer_clear(&blankFrag); | |
814 | |
815 #line 816 "mhh6.c" | |
816 } | |
817 | |
818 static void ag_rp_29(int c) { | |
819 #line 222 "/disk/disk0/home/dholland/projects/ag/src/help2html/mhh6.syn" | |
820 buffer_append(&topicBody, "</td>\n<td> "); | |
821 appendTableCell(c); | |
822 buffer_clear(&tabFrag); | |
823 buffer_clear(&blankFrag); | |
824 | |
825 #line 826 "mhh6.c" | |
826 } | |
827 | |
828 #define ag_rp_30() (buffer_append(&topicBody, "</td></tr>")) | |
829 | |
830 static void ag_rp_31(int c) { | |
831 #line 234 "/disk/disk0/home/dholland/projects/ag/src/help2html/mhh6.syn" | |
832 buffer_append(&topicBody, "\n\n<tr><td> "); | |
833 appendTableCell(c); | |
834 buffer_clear(&tabFrag); | |
835 buffer_clear(&blankFrag); | |
836 | |
837 #line 838 "mhh6.c" | |
838 } | |
839 | |
840 static void ag_rp_32(int c) { | |
841 #line 242 "/disk/disk0/home/dholland/projects/ag/src/help2html/mhh6.syn" | |
842 buffer_append(&topicBody, "</td>\n<td> "); | |
843 appendTableCell(c); | |
844 buffer_clear(&tabFrag); | |
845 buffer_clear(&blankFrag); | |
846 | |
847 #line 848 "mhh6.c" | |
848 } | |
849 | |
850 static void ag_rp_33(int c) { | |
851 #line 252 "/disk/disk0/home/dholland/projects/ag/src/help2html/mhh6.syn" | |
852 total1stlist1line++; | |
853 if (intstack_top(¶gType) != Tlist1) { | |
854 intstack_push(¶gType, Tlist1); | |
855 buffer_append(&topicBody, "\n<ul>"); | |
856 } | |
857 buffer_append(&topicBody, "\n<li>"); | |
858 buffer_add(&topicBody, 0x20); | |
859 appendEnd(c); | |
860 | |
861 #line 862 "mhh6.c" | |
862 } | |
863 | |
864 #define ag_rp_34(c) (appendEnd(c)) | |
865 | |
866 static void ag_rp_35(int c) { | |
867 #line 268 "/disk/disk0/home/dholland/projects/ag/src/help2html/mhh6.syn" | |
868 total1stlist2line++; | |
869 if (intstack_top(¶gType) != Tlist2) { | |
870 intstack_push(¶gType, Tlist2); | |
871 buffer_append(&topicBody, "\n<ul>"); | |
872 } | |
873 buffer_append(&topicBody, "\n<li>"); | |
874 buffer_append(&topicBody, " "); | |
875 appendEnd(c); | |
876 | |
877 #line 878 "mhh6.c" | |
878 } | |
879 | |
880 #define ag_rp_36(c) (appendEnd(c)) | |
881 | |
882 static void ag_rp_37(int t, int c) { | |
883 #line 284 "/disk/disk0/home/dholland/projects/ag/src/help2html/mhh6.syn" | |
884 total1stlisttabline++; | |
885 if (intstack_top(¶gType) != Tlisttab) { | |
886 intstack_push(¶gType, Tlisttab); | |
887 buffer_append(&topicBody, "\n<ul>"); | |
888 } | |
889 buffer_append(&topicBody, "\n<li>"); | |
890 buffer_add(&topicBody, t); | |
891 appendEnd(c); | |
892 | |
893 #line 894 "mhh6.c" | |
894 } | |
895 | |
896 #define ag_rp_38(c) (appendEnd(c)) | |
897 | |
898 static void ag_rp_39(int c) { | |
899 #line 301 "/disk/disk0/home/dholland/projects/ag/src/help2html/mhh6.syn" | |
900 total1stcodeline++; | |
901 buffer_append(&topicBody, "\n<pre> "); | |
902 appendEnd(c); | |
903 | |
904 #line 905 "mhh6.c" | |
905 } | |
906 | |
907 static void ag_rp_40(int c) { | |
908 #line 306 "/disk/disk0/home/dholland/projects/ag/src/help2html/mhh6.syn" | |
909 total1stcodeline++; | |
910 buffer_append(&topicBody, "\n<pre> "); | |
911 appendEnd(c); | |
912 | |
913 #line 914 "mhh6.c" | |
914 } | |
915 | |
916 static void ag_rp_41(int c) { | |
917 #line 311 "/disk/disk0/home/dholland/projects/ag/src/help2html/mhh6.syn" | |
918 total1stcodeline++; | |
919 buffer_append(&topicBody, "\n<pre> "); | |
920 appendEnd(c); | |
921 | |
922 #line 923 "mhh6.c" | |
923 } | |
924 | |
925 static void ag_rp_42(int c) { | |
926 #line 316 "/disk/disk0/home/dholland/projects/ag/src/help2html/mhh6.syn" | |
927 total1stcodeline++; | |
928 buffer_append(&topicBody, "\n<pre> "); | |
929 appendEnd(c); | |
930 | |
931 #line 932 "mhh6.c" | |
932 } | |
933 | |
934 static void ag_rp_43(int c) { | |
935 #line 320 "/disk/disk0/home/dholland/projects/ag/src/help2html/mhh6.syn" | |
936 | |
937 total1stcodeline++; | |
938 buffer_append(&topicBody, "\n<pre> "); | |
939 appendEnd(c); | |
940 | |
941 #line 942 "mhh6.c" | |
942 } | |
943 | |
944 static void ag_rp_44(int c) { | |
945 #line 326 "/disk/disk0/home/dholland/projects/ag/src/help2html/mhh6.syn" | |
946 total1stcodeline++; | |
947 buffer_append(&topicBody, "\n<pre> "); | |
948 appendEnd(c); | |
949 | |
950 #line 951 "mhh6.c" | |
951 } | |
952 | |
953 static void ag_rp_45(int c) { | |
954 #line 330 "/disk/disk0/home/dholland/projects/ag/src/help2html/mhh6.syn" | |
955 | |
956 total1stcodeline++; | |
957 buffer_append(&topicBody, "\n<pre> "); | |
958 appendEnd(c); | |
959 | |
960 #line 961 "mhh6.c" | |
961 } | |
962 | |
963 static void ag_rp_46(int c) { | |
964 #line 339 "/disk/disk0/home/dholland/projects/ag/src/help2html/mhh6.syn" | |
965 buffer_append(&topicBody, " "); | |
966 appendEnd(c); | |
967 | |
968 #line 969 "mhh6.c" | |
969 } | |
970 | |
971 static void ag_rp_47(int c) { | |
972 #line 343 "/disk/disk0/home/dholland/projects/ag/src/help2html/mhh6.syn" | |
973 buffer_append(&topicBody, " "); | |
974 appendEnd(c); | |
975 | |
976 #line 977 "mhh6.c" | |
977 } | |
978 | |
979 static void ag_rp_48(int c) { | |
980 #line 347 "/disk/disk0/home/dholland/projects/ag/src/help2html/mhh6.syn" | |
981 buffer_append(&topicBody, " "); | |
982 appendEnd(c); | |
983 | |
984 #line 985 "mhh6.c" | |
985 } | |
986 | |
987 static void ag_rp_49(int c) { | |
988 #line 351 "/disk/disk0/home/dholland/projects/ag/src/help2html/mhh6.syn" | |
989 buffer_append(&topicBody, " "); | |
990 appendEnd(c); | |
991 | |
992 #line 993 "mhh6.c" | |
993 } | |
994 | |
995 static void ag_rp_50(int c) { | |
996 #line 355 "/disk/disk0/home/dholland/projects/ag/src/help2html/mhh6.syn" | |
997 buffer_append(&topicBody, " "); | |
998 appendEnd(c); | |
999 | |
1000 #line 1001 "mhh6.c" | |
1001 } | |
1002 | |
1003 static void ag_rp_51(int c) { | |
1004 #line 359 "/disk/disk0/home/dholland/projects/ag/src/help2html/mhh6.syn" | |
1005 buffer_append(&topicBody, " "); | |
1006 appendEnd(c); | |
1007 | |
1008 #line 1009 "mhh6.c" | |
1009 } | |
1010 | |
1011 static void ag_rp_52(int c) { | |
1012 #line 363 "/disk/disk0/home/dholland/projects/ag/src/help2html/mhh6.syn" | |
1013 buffer_append(&topicBody, " "); | |
1014 appendEnd(c); | |
1015 | |
1016 #line 1017 "mhh6.c" | |
1017 } | |
1018 | |
1019 #define ag_rp_53(c) (buffer_start(&topicFrag, c)) | |
1020 | |
1021 #define ag_rp_54(c) (buffer_add(&topicFrag, c)) | |
1022 | |
1023 #define ag_rp_55(c) (buffer_start(&topicFrag, c)) | |
1024 | |
1025 #define ag_rp_56(c) (buffer_add(&topicFrag, c)) | |
1026 | |
1027 #define ag_rp_57(t) (buffer_start(&tabFrag, t)) | |
1028 | |
1029 #define ag_rp_58(t) (buffer_add(&tabFrag, t)) | |
1030 | |
1031 #define ag_rp_59() (buffer_start(&blankFrag, 0x20)) | |
1032 | |
1033 #define ag_rp_60() (buffer_add(&blankFrag, 0x20)) | |
1034 | |
1035 | |
1036 #define READ_COUNTS | |
1037 #define WRITE_COUNTS | |
1038 #undef V | |
1039 #define V(i,t) (*t (&(PCB).vs[(PCB).ssx + i])) | |
1040 #undef VS | |
1041 #define VS(i) (PCB).vs[(PCB).ssx + i] | |
1042 | |
1043 #ifndef GET_CONTEXT | |
1044 #define GET_CONTEXT CONTEXT = (PCB).input_context | |
1045 #endif | |
1046 | |
1047 typedef enum { | |
1048 ag_action_1, | |
1049 ag_action_2, | |
1050 ag_action_3, | |
1051 ag_action_4, | |
1052 ag_action_5, | |
1053 ag_action_6, | |
1054 ag_action_7, | |
1055 ag_action_8, | |
1056 ag_action_9, | |
1057 ag_action_10, | |
1058 ag_action_11, | |
1059 ag_action_12 | |
1060 } ag_parser_action; | |
1061 | |
1062 | |
1063 #ifndef NULL_VALUE_INITIALIZER | |
1064 #define NULL_VALUE_INITIALIZER = 0 | |
1065 #endif | |
1066 | |
1067 static int const ag_null_value NULL_VALUE_INITIALIZER; | |
1068 | |
1069 static const unsigned char ag_rpx[] = { | |
1070 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
1071 0, 0, 1, 2, 3, 4, 5, 0, 0, 0, 6, 7, 8, 0, 0, 9, 10, 11, | |
1072 0, 0, 0, 12, 13, 0, 0, 0, 0, 14, 0, 0, 0, 0, 15, 16, 0, 0, | |
1073 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 18, 19, 0, 0, 0, 0, 20, 0, | |
1074 0, 0, 0, 0, 0, 0, 0, 0, 21, 22, 23, 0, 0, 0, 0, 24, 25, 26, | |
1075 27, 0, 0, 0, 0, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, | |
1076 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, | |
1077 59, 60 | |
1078 }; | |
1079 | |
1080 static const unsigned char ag_key_itt[] = { | |
1081 0 | |
1082 }; | |
1083 | |
1084 static const unsigned short ag_key_pt[] = { | |
1085 0 | |
1086 }; | |
1087 | |
1088 static const unsigned char ag_key_ch[] = { | |
1089 0, 32,255, 32,255, 32,255, 32,255, 32,255, 32,255, 32,255, 32,255, 10, | |
1090 13, 32, 35,255, 10, 13, 35,255, 32,255, 32,255, 32,255, 32,255, 32,255, | |
1091 32,255, 32,255, 32,255, 32,255 | |
1092 }; | |
1093 | |
1094 static const unsigned char ag_key_act[] = { | |
1095 0,3,4,1,4,2,4,1,4,1,4,1,4,1,4,1,4,3,3,2,3,4,3,3,3,4,3,4,1,4,2,4,1,4,1, | |
1096 4,1,4,1,4,1,4,2,4 | |
1097 }; | |
1098 | |
1099 static const unsigned char ag_key_parm[] = { | |
1100 0, 84, 0, 83, 0, 0, 0, 82, 0, 81, 0, 80, 0, 79, 0, 78, 0, 25, | |
1101 26, 0, 24, 0, 25, 26, 24, 0, 84, 0, 83, 0, 0, 0, 82, 0, 81, 0, | |
1102 80, 0, 79, 0, 78, 0, 0, 0 | |
1103 }; | |
1104 | |
1105 static const unsigned char ag_key_jmp[] = { | |
1106 0, 7, 0, 1, 0, 3, 0, 5, 0, 7, 0, 9, 0, 11, 0, 13, 0, 0, | |
1107 3, 15, 9, 0, 11, 14, 18, 0, 20, 0, 26, 0, 28, 0, 30, 0, 32, 0, | |
1108 34, 0, 36, 0, 38, 0, 40, 0 | |
1109 }; | |
1110 | |
1111 static const unsigned char ag_key_index[] = { | |
1112 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
1113 0, 17, 22, 22, 22, 0, 0, 17, 0, 0, 0, 0, 0, 0, 0, 17, 22, 22, | |
1114 22, 0, 17, 22, 0, 0, 22, 22, 42, 0, 0, 0, 0, 0, 0, 0, 17, 0, | |
1115 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22, 22, 0, 22, | |
1116 0, 0, 0, 17, 17, 0, 22, 0, 0, 0, 0, 0, 0, 22, 0, 0, 0, 0, | |
1117 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
1118 0, 0, 0, 0, 0, 0, 0, 22, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
1119 0, 0, 0, 0, 0, 0, 0, 0 | |
1120 }; | |
1121 | |
1122 static const unsigned char ag_key_ends[] = { | |
1123 35,35,0, 10,35,35,0, 32,0, 35,0, 35,35,0, 10,35,35,0, 35,0, | |
1124 32,0, | |
1125 }; | |
1126 | |
1127 #define AG_TCV(x) ag_tcv[(x)] | |
1128 | |
1129 static const unsigned char ag_tcv[] = { | |
1130 8, 22, 22, 22, 22, 22, 22, 76, 22, 77, 2, 22, 22, 3, 22, 22, 22, 22, | |
1131 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 5, 22, 22, 22, | |
1132 22, 22, 22, 22, 22, 22, 22, 22, 21, 22, 22, 22, 22, 22, 22, 22, 22, 22, | |
1133 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, | |
1134 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, | |
1135 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, | |
1136 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, | |
1137 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, | |
1138 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, | |
1139 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, | |
1140 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, | |
1141 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, | |
1142 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, | |
1143 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, | |
1144 22, 22, 22, 22 | |
1145 }; | |
1146 | |
1147 #ifndef SYNTAX_ERROR | |
1148 #define SYNTAX_ERROR fprintf(stderr,"%s, line %d, column %d\n", \ | |
1149 (PCB).error_message, (PCB).line, (PCB).column) | |
1150 #endif | |
1151 | |
1152 #ifndef FIRST_LINE | |
1153 #define FIRST_LINE 1 | |
1154 #endif | |
1155 | |
1156 #ifndef FIRST_COLUMN | |
1157 #define FIRST_COLUMN 1 | |
1158 #endif | |
1159 | |
1160 #ifndef PARSER_STACK_OVERFLOW | |
1161 #define PARSER_STACK_OVERFLOW {fprintf(stderr, \ | |
1162 "\nParser stack overflow, line %d, column %d\n",\ | |
1163 (PCB).line, (PCB).column);} | |
1164 #endif | |
1165 | |
1166 #ifndef REDUCTION_TOKEN_ERROR | |
1167 #define REDUCTION_TOKEN_ERROR {fprintf(stderr, \ | |
1168 "\nReduction token error, line %d, column %d\n", \ | |
1169 (PCB).line, (PCB).column);} | |
1170 #endif | |
1171 | |
1172 | |
1173 #ifndef INPUT_CODE | |
1174 #define INPUT_CODE(T) (T) | |
1175 #endif | |
1176 | |
1177 typedef enum | |
1178 {ag_accept_key, ag_set_key, ag_jmp_key, ag_end_key, ag_no_match_key, | |
1179 ag_cf_accept_key, ag_cf_set_key, ag_cf_end_key} key_words; | |
1180 | |
1181 static void ag_get_key_word(int ag_k) { | |
1182 int ag_save = (int) ((PCB).la_ptr - (PCB).pointer); | |
1183 const unsigned char *ag_p; | |
1184 int ag_ch; | |
1185 while (1) { | |
1186 switch (ag_key_act[ag_k]) { | |
1187 case ag_cf_end_key: { | |
1188 const unsigned char *sp = ag_key_ends + ag_key_jmp[ag_k]; | |
1189 do { | |
1190 if ((ag_ch = *sp++) == 0) { | |
1191 int ag_k1 = ag_key_parm[ag_k]; | |
1192 int ag_k2 = ag_key_pt[ag_k1]; | |
1193 if (ag_key_itt[ag_k2 + CONVERT_CASE(*(PCB).la_ptr)]) goto ag_fail; | |
1194 (PCB).token_number = (mhh6_token_type) ag_key_pt[ag_k1 + 1]; | |
1195 return; | |
1196 } | |
1197 } while (CONVERT_CASE(*(PCB).la_ptr++) == ag_ch); | |
1198 goto ag_fail; | |
1199 } | |
1200 case ag_end_key: { | |
1201 const unsigned char *sp = ag_key_ends + ag_key_jmp[ag_k]; | |
1202 do { | |
1203 if ((ag_ch = *sp++) == 0) { | |
1204 (PCB).token_number = (mhh6_token_type) ag_key_parm[ag_k]; | |
1205 return; | |
1206 } | |
1207 } while (CONVERT_CASE(*(PCB).la_ptr++) == ag_ch); | |
1208 } | |
1209 case ag_no_match_key: | |
1210 ag_fail: | |
1211 (PCB).la_ptr = (PCB).pointer + ag_save; | |
1212 return; | |
1213 case ag_cf_set_key: { | |
1214 int ag_k1 = ag_key_parm[ag_k]; | |
1215 int ag_k2 = ag_key_pt[ag_k1]; | |
1216 ag_k = ag_key_jmp[ag_k]; | |
1217 if (ag_key_itt[ag_k2 + CONVERT_CASE(*(PCB).la_ptr)]) break; | |
1218 ag_save = (int) ((PCB).la_ptr - (PCB).pointer); | |
1219 (PCB).token_number = (mhh6_token_type) ag_key_pt[ag_k1+1]; | |
1220 break; | |
1221 } | |
1222 case ag_set_key: | |
1223 ag_save = (int) ((PCB).la_ptr - (PCB).pointer); | |
1224 (PCB).token_number = (mhh6_token_type) ag_key_parm[ag_k]; | |
1225 case ag_jmp_key: | |
1226 ag_k = ag_key_jmp[ag_k]; | |
1227 break; | |
1228 case ag_accept_key: | |
1229 (PCB).token_number = (mhh6_token_type) ag_key_parm[ag_k]; | |
1230 return; | |
1231 case ag_cf_accept_key: { | |
1232 int ag_k1 = ag_key_parm[ag_k]; | |
1233 int ag_k2 = ag_key_pt[ag_k1]; | |
1234 if (ag_key_itt[ag_k2 + CONVERT_CASE(*(PCB).la_ptr)]) | |
1235 (PCB).la_ptr = (PCB).pointer + ag_save; | |
1236 else (PCB).token_number = (mhh6_token_type) ag_key_pt[ag_k1+1]; | |
1237 return; | |
1238 } | |
1239 } | |
1240 ag_ch = CONVERT_CASE(*(PCB).la_ptr++); | |
1241 ag_p = &ag_key_ch[ag_k]; | |
1242 if (ag_ch <= 255) while (*ag_p < ag_ch) ag_p++; | |
1243 if (ag_ch > 255 || *ag_p != ag_ch) { | |
1244 (PCB).la_ptr = (PCB).pointer + ag_save; | |
1245 return; | |
1246 } | |
1247 ag_k = (int) (ag_p - ag_key_ch); | |
1248 } | |
1249 } | |
1250 | |
1251 | |
1252 #ifndef AG_NEWLINE | |
1253 #define AG_NEWLINE 10 | |
1254 #endif | |
1255 | |
1256 #ifndef AG_RETURN | |
1257 #define AG_RETURN 13 | |
1258 #endif | |
1259 | |
1260 #ifndef AG_FORMFEED | |
1261 #define AG_FORMFEED 12 | |
1262 #endif | |
1263 | |
1264 #ifndef AG_TABCHAR | |
1265 #define AG_TABCHAR 9 | |
1266 #endif | |
1267 | |
1268 static void ag_track(void) { | |
1269 int ag_k = (int) ((PCB).la_ptr - (PCB).pointer); | |
1270 while (ag_k--) { | |
1271 switch (*(PCB).pointer++) { | |
1272 case AG_NEWLINE: | |
1273 (PCB).column = 1, (PCB).line++; | |
1274 case AG_RETURN: | |
1275 case AG_FORMFEED: | |
1276 break; | |
1277 case AG_TABCHAR: | |
1278 (PCB).column += (TAB_SPACING) - ((PCB).column - 1) % (TAB_SPACING); | |
1279 break; | |
1280 default: | |
1281 (PCB).column++; | |
1282 } | |
1283 } | |
1284 } | |
1285 | |
1286 | |
1287 static void ag_prot(void) { | |
1288 int ag_k; | |
1289 ag_k = 128 - ++(PCB).btsx; | |
1290 if (ag_k <= (PCB).ssx) { | |
1291 (PCB).exit_flag = AG_STACK_ERROR_CODE; | |
1292 PARSER_STACK_OVERFLOW; | |
1293 return; | |
1294 } | |
1295 (PCB).bts[(PCB).btsx] = (PCB).sn; | |
1296 (PCB).bts[ag_k] = (PCB).ssx; | |
1297 (PCB).vs[ag_k] = (PCB).vs[(PCB).ssx]; | |
1298 (PCB).ss[ag_k] = (PCB).ss[(PCB).ssx]; | |
1299 } | |
1300 | |
1301 static void ag_undo(void) { | |
1302 if ((PCB).drt == -1) return; | |
1303 while ((PCB).btsx) { | |
1304 int ag_k = 128 - (PCB).btsx; | |
1305 (PCB).sn = (PCB).bts[(PCB).btsx--]; | |
1306 (PCB).ssx = (PCB).bts[ag_k]; | |
1307 (PCB).vs[(PCB).ssx] = (PCB).vs[ag_k]; | |
1308 (PCB).ss[(PCB).ssx] = (PCB).ss[ag_k]; | |
1309 } | |
1310 (PCB).token_number = (mhh6_token_type) (PCB).drt; | |
1311 (PCB).ssx = (PCB).dssx; | |
1312 (PCB).sn = (PCB).dsn; | |
1313 (PCB).drt = -1; | |
1314 } | |
1315 | |
1316 | |
1317 static const unsigned char ag_tstt[] = { | |
1318 22,3,2,0,1,10,11,12,14,15, | |
1319 2,0, | |
1320 3,2,0,1, | |
1321 22,0,16,19,20, | |
1322 22,8,5,3,2,0,1,11,13,14,15, | |
1323 77,22,5,0, | |
1324 21,0, | |
1325 3,2,0,9, | |
1326 8,5,0,4,6,7, | |
1327 22,8,5,3,2,0, | |
1328 22,5,0,6,7, | |
1329 2,0, | |
1330 22,21,5,3,2,0,1,14,15, | |
1331 5,0, | |
1332 8,0, | |
1333 22,0,20, | |
1334 22,21,5,0,17,27,28,35,36,37, | |
1335 77,22,5,0, | |
1336 22,21,5,0,38, | |
1337 84,83,82,81,80,79,78,76,0,31,33,34,45,48,56,59,63,64, | |
1338 77,0,30,42,43,69,70, | |
1339 3,2,0,1,14, | |
1340 26,25,24,0,18, | |
1341 77,22,21,5,3,2,0,67,68, | |
1342 22,21,0, | |
1343 84,83,82,81,80,79,78,77,76,26,25,24,22,21,3,2,0,39,40,41, | |
1344 22,21,0, | |
1345 22,21,0, | |
1346 22,21,0, | |
1347 22,21,0, | |
1348 22,21,0, | |
1349 22,21,0, | |
1350 22,21,0, | |
1351 84,83,82,81,80,79,78,0,65, | |
1352 26,25,24,22,21,5,3,2,0,36,37, | |
1353 77,76,26,25,24,22,21,3,2,0,60,61,62, | |
1354 76,26,25,24,3,2,0,56,57,58,59, | |
1355 77,5,0, | |
1356 84,83,82,81,80,79,78,77,76,26,25,24,22,21,3,2,0,49,50,51, | |
1357 76,26,25,24,3,2,0,45,46,47,48, | |
1358 77,22,21,5,0,71,72, | |
1359 77,3,2,0,9,70, | |
1360 77,0,44,70,75, | |
1361 26,25,24,22,21,5,3,2,0,36,37, | |
1362 84,83,82,81,80,79,78,77,76,22,21,5,3,2,0,1,28,29,30,31,32,33,34,35,36,37,42, | |
1363 43,45,48,52,56,59,63,64,69,70, | |
1364 5,3,2,0,6,7, | |
1365 5,3,2,0,6,7, | |
1366 5,3,2,0,6,7, | |
1367 77,22,21,5,0, | |
1368 3,2,0,9, | |
1369 77,22,21,5,3,2,0,67,68, | |
1370 77,22,21,5,3,2,0,67,68, | |
1371 22,21,0,39, | |
1372 77,22,21,5,3,2,0,67,68, | |
1373 77,22,21,5,3,2,0,67,68, | |
1374 77,22,21,5,3,2,0,67,68, | |
1375 77,22,21,5,3,2,0,67,68, | |
1376 77,22,21,5,3,2,0,67,68, | |
1377 77,22,21,5,3,2,0,67,68, | |
1378 77,22,21,5,3,2,0,67,68, | |
1379 22,21,0, | |
1380 22,21,0, | |
1381 22,21,0, | |
1382 22,21,0, | |
1383 22,21,0, | |
1384 22,21,0, | |
1385 22,21,0, | |
1386 77,22,21,5,3,2,0,67,68, | |
1387 22,21,0,60, | |
1388 77,0,30,42,43,69,70, | |
1389 77,0, | |
1390 76,0,56,59, | |
1391 22,21,0, | |
1392 22,21,0, | |
1393 77,22,21,5,3,2,0,67,68, | |
1394 22,21,0,49, | |
1395 84,83,82,81,80,79,78,77,0,30,34,42,43,63,64,69,70, | |
1396 5,0, | |
1397 76,0,45,48, | |
1398 5,0, | |
1399 22,21,0, | |
1400 77,22,21,5,0,71,72, | |
1401 77,22,21,5,0,71,72, | |
1402 77,3,2,0,9,70, | |
1403 77,5,0, | |
1404 26,25,24,22,21,3,2,0,53,54,55, | |
1405 3,2,0,9, | |
1406 3,2,0,9, | |
1407 3,2,0,9, | |
1408 3,2,0,9, | |
1409 3,2,0,9, | |
1410 3,2,0,9, | |
1411 3,2,0,9, | |
1412 3,2,0,9, | |
1413 3,2,0,9, | |
1414 3,2,0,9, | |
1415 3,2,0,9, | |
1416 3,2,0,9, | |
1417 77,22,21,5,3,2,0,67,68, | |
1418 77,22,21,5,3,2,0,67,68, | |
1419 77,22,21,5,3,2,0,67,68, | |
1420 77,22,21,5,3,2,0,67,68, | |
1421 77,22,21,5,3,2,0,67,68, | |
1422 77,22,21,5,3,2,0,67,68, | |
1423 77,22,21,5,3,2,0,67,68, | |
1424 3,2,0,9, | |
1425 77,22,21,5,3,2,0,67,68, | |
1426 77,22,21,5,3,2,0,67,68, | |
1427 3,2,0,9, | |
1428 77,76,22,21,5,3,2,0,73,74, | |
1429 22,21,0, | |
1430 22,21,0, | |
1431 77,22,21,5,0,71,72, | |
1432 22,21,5,0, | |
1433 77,22,21,5,3,2,0,67,68, | |
1434 22,21,0,53, | |
1435 3,2,0,9, | |
1436 3,2,0,9, | |
1437 3,2,0,9, | |
1438 3,2,0,9, | |
1439 3,2,0,9, | |
1440 3,2,0,9, | |
1441 3,2,0,9, | |
1442 3,2,0,9, | |
1443 3,2,0,9, | |
1444 76,22,21,5,0, | |
1445 77,76,22,21,5,3,2,0,73,74, | |
1446 77,76,22,21,5,3,2,0,73,74, | |
1447 22,21,0, | |
1448 22,21,0, | |
1449 3,2,0,9, | |
1450 77,76,22,21,5,3,2,0,73,74, | |
1451 77,22,21,5,3,2,0,67,68, | |
1452 3,2,0,9, | |
1453 | |
1454 }; | |
1455 | |
1456 | |
1457 static unsigned const char ag_astt[839] = { | |
1458 8,1,1,7,1,0,1,1,1,1,3,7,1,9,5,3,2,7,1,1,1,8,8,8,1,1,7,1,3,1,1,1,10,10,10,4, | |
1459 1,4,1,1,7,1,8,1,7,3,1,1,5,5,5,5,5,7,8,1,7,1,1,3,7,8,8,8,1,1,7,1,1,1,9,5,3, | |
1460 7,2,7,1,4,4,4,7,1,1,2,1,1,1,10,10,10,4,1,1,1,7,1,1,1,1,1,1,1,1,1,5,2,2,1,1, | |
1461 1,1,1,1,1,2,5,1,1,1,1,1,1,1,4,1,1,1,1,1,7,3,2,2,2,2,8,8,7,1,1,1,1,7,5,5,5, | |
1462 5,5,5,5,5,5,5,5,5,1,1,5,5,7,1,1,2,1,1,7,1,1,7,1,1,7,1,1,7,1,1,7,1,1,7,1,1, | |
1463 7,1,1,1,1,1,1,1,4,3,5,5,5,4,4,4,5,5,7,3,1,8,5,5,5,5,1,1,5,5,7,1,1,1,1,5,5, | |
1464 5,5,5,7,1,1,3,1,1,1,7,8,8,8,8,8,8,8,8,5,5,5,5,1,1,5,5,7,1,1,1,1,5,5,5,5,5, | |
1465 7,1,1,3,1,10,8,8,2,7,1,1,2,1,2,7,2,1,2,4,3,1,1,5,5,5,4,4,4,5,5,7,3,1,1,1,1, | |
1466 1,1,1,1,2,1,4,4,4,1,9,7,3,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,8,8, | |
1467 7,1,1,1,8,8,7,1,1,1,8,8,7,1,1,10,10,10,10,5,1,2,7,2,2,2,2,2,8,8,7,1,1,2,2, | |
1468 2,2,8,8,7,1,1,1,1,5,3,2,2,2,2,8,8,7,1,1,2,2,2,2,8,8,7,1,1,2,2,2,2,8,8,7,1, | |
1469 1,2,2,2,2,8,8,7,1,1,2,2,2,2,8,8,7,1,1,2,2,2,2,8,8,7,1,1,2,2,2,2,8,8,7,1,1, | |
1470 1,1,7,1,1,7,1,1,7,1,1,7,1,1,7,1,1,7,1,1,7,2,2,2,2,8,8,7,1,1,1,1,5,3,2,4,2, | |
1471 1,1,1,1,1,7,1,5,3,1,1,1,7,1,1,7,2,2,2,2,8,8,7,1,1,1,1,5,3,1,1,1,1,1,1,1,2, | |
1472 4,2,2,1,1,1,1,1,1,1,7,1,5,3,1,10,5,1,1,7,10,8,8,2,7,1,1,10,8,8,2,7,1,1,2,1, | |
1473 2,7,2,1,1,1,7,5,5,5,1,1,5,5,7,1,1,2,1,3,7,3,1,3,7,3,1,3,7,3,1,2,7,2,1,2,7, | |
1474 2,1,2,7,2,1,2,7,2,1,2,7,2,1,2,7,2,1,2,7,2,1,2,7,2,1,2,7,2,2,2,2,2,8,8,7,1, | |
1475 1,2,2,2,2,8,8,7,1,1,2,2,2,2,8,8,7,1,1,2,2,2,2,8,8,7,1,1,2,2,2,2,8,8,7,1,1, | |
1476 2,2,2,2,8,8,7,1,1,2,2,2,2,8,8,7,1,1,1,2,7,2,2,2,2,2,8,8,7,1,1,2,2,2,2,8,8, | |
1477 7,1,1,1,2,7,2,5,2,2,2,2,5,5,7,1,2,1,1,7,1,1,7,10,8,8,2,7,1,1,1,1,1,7,2,2,2, | |
1478 2,8,8,7,1,1,1,1,5,3,1,2,7,2,1,2,7,2,1,2,7,2,1,2,7,2,1,2,7,2,1,2,7,2,1,2,7, | |
1479 2,1,2,7,2,1,2,7,2,10,10,10,10,5,5,2,2,2,2,5,5,7,1,2,5,2,2,2,2,5,5,7,1,2,1, | |
1480 1,7,1,1,7,1,2,7,2,5,2,2,2,2,5,5,7,1,2,2,2,2,2,8,8,7,1,1,1,2,7,2 | |
1481 }; | |
1482 | |
1483 | |
1484 static const unsigned char ag_pstt[] = { | |
1485 3,1,2,0,2,0,4,4,2,3, | |
1486 2,1, | |
1487 1,16,18,16, | |
1488 23,3,7,6,5, | |
1489 3,8,8,1,9,4,9,11,8,2,3, | |
1490 24,24,24,21, | |
1491 10,20, | |
1492 11,12,7,12, | |
1493 14,13,8,14,13,14, | |
1494 15,13,13,15,15,9, | |
1495 15,13,10,13,15, | |
1496 9,11, | |
1497 16,16,16,1,2,12,2,2,16, | |
1498 4,6, | |
1499 7,14, | |
1500 23,15,17, | |
1501 45,45,45,16,22,21,29,20,19,18, | |
1502 24,24,24,22, | |
1503 23,23,24,18,25, | |
1504 26,27,28,29,30,31,32,37,43,39,40,34,39,38,36,35,33,33, | |
1505 124,37,43,42,42,41,40, | |
1506 1,44,28,44,44, | |
1507 45,46,47,22,19, | |
1508 120,120,120,120,49,49,23,48,49, | |
1509 50,50,24, | |
1510 48,48,48,48,48,48,48,48,48,48,48,48,51,51,48,48,25,52,52,50, | |
1511 53,53,26, | |
1512 54,54,27, | |
1513 55,55,28, | |
1514 56,56,29, | |
1515 57,57,30, | |
1516 58,58,31, | |
1517 59,59,32, | |
1518 60,61,62,63,64,65,66,82,84, | |
1519 41,41,41,45,45,45,41,41,34,42,18, | |
1520 69,78,78,78,78,67,67,78,78,35,68,68,69, | |
1521 70,73,73,73,73,73,36,71,71,75,35, | |
1522 72,73,37, | |
1523 76,76,76,76,76,76,76,76,61,61,61,61,74,74,61,61,38,75,75,76, | |
1524 77,56,56,56,56,56,39,78,78,58,38, | |
1525 125,80,80,126,40,79,80, | |
1526 124,11,90,41,90,81, | |
1527 124,51,53,82,83, | |
1528 38,38,38,45,45,45,38,38,43,44,18, | |
1529 26,27,28,29,30,31,32,124,84,45,45,45,1,16,44,16,30,30,30,33,34,35,30,20,19, | |
1530 18,42,42,39,38,85,36,35,33,33,41,40, | |
1531 13,86,86,45,13,86, | |
1532 13,87,87,46,13,87, | |
1533 13,88,88,47,13,88, | |
1534 121,121,121,121,86, | |
1535 11,87,49,87, | |
1536 120,120,120,120,89,89,50,48,89, | |
1537 120,120,120,120,90,90,51,48,90, | |
1538 51,51,49,47, | |
1539 120,120,120,120,91,91,53,48,91, | |
1540 120,120,120,120,92,92,54,48,92, | |
1541 120,120,120,120,93,93,55,48,93, | |
1542 120,120,120,120,94,94,56,48,94, | |
1543 120,120,120,120,95,95,57,48,95, | |
1544 120,120,120,120,96,96,58,48,96, | |
1545 120,120,120,120,97,97,59,48,97, | |
1546 98,98,60, | |
1547 99,99,61, | |
1548 100,100,62, | |
1549 101,101,63, | |
1550 102,102,64, | |
1551 103,103,65, | |
1552 104,104,66, | |
1553 120,120,120,120,105,105,67,48,105, | |
1554 67,67,79,77, | |
1555 124,80,81,42,42,41,40, | |
1556 72,70, | |
1557 70,74,72,35, | |
1558 106,106,72, | |
1559 107,107,73, | |
1560 120,120,120,120,108,108,74,48,108, | |
1561 74,74,62,60, | |
1562 26,27,28,29,30,31,32,124,63,64,65,42,42,33,33,41,40, | |
1563 73,77, | |
1564 77,57,55,38, | |
1565 127,92, | |
1566 109,109,80, | |
1567 125,110,110,126,81,79,110, | |
1568 125,111,111,126,82,79,111, | |
1569 124,11,97,83,97,112, | |
1570 72,113,84, | |
1571 68,68,68,114,114,68,68,85,115,115,70, | |
1572 11,27,86,27, | |
1573 11,26,87,26, | |
1574 11,25,88,25, | |
1575 11,88,89,88, | |
1576 11,89,90,89, | |
1577 11,112,91,112, | |
1578 11,111,92,111, | |
1579 11,110,93,110, | |
1580 11,109,94,109, | |
1581 11,108,95,108, | |
1582 11,107,96,107, | |
1583 11,106,97,106, | |
1584 120,120,120,120,116,116,98,48,116, | |
1585 120,120,120,120,117,117,99,48,117, | |
1586 120,120,120,120,118,118,100,48,118, | |
1587 120,120,120,120,119,119,101,48,119, | |
1588 120,120,120,120,120,120,102,48,120, | |
1589 120,120,120,120,121,121,103,48,121, | |
1590 120,120,120,120,122,122,104,48,122, | |
1591 11,105,105,105, | |
1592 120,120,120,120,123,123,106,48,123, | |
1593 120,120,120,120,124,124,107,48,124, | |
1594 11,101,108,101, | |
1595 93,122,122,122,122,93,93,109,125,95, | |
1596 126,126,110, | |
1597 127,127,111, | |
1598 125,128,128,126,112,79,128, | |
1599 107,107,129,113, | |
1600 120,120,120,120,130,130,114,48,130, | |
1601 114,114,69,67, | |
1602 11,119,116,119, | |
1603 11,118,117,118, | |
1604 11,117,118,117, | |
1605 11,116,119,116, | |
1606 11,115,120,115, | |
1607 11,114,121,114, | |
1608 11,113,122,113, | |
1609 11,104,123,104, | |
1610 11,100,124,100, | |
1611 123,123,123,123,94, | |
1612 93,122,122,122,122,93,93,126,125,96, | |
1613 93,122,122,122,122,93,93,127,125,98, | |
1614 131,131,128, | |
1615 132,132,129, | |
1616 11,103,130,103, | |
1617 93,122,122,122,122,93,93,131,125,99, | |
1618 120,120,120,120,133,133,132,48,133, | |
1619 11,102,133,102, | |
1620 | |
1621 }; | |
1622 | |
1623 | |
1624 static const unsigned short ag_sbt[] = { | |
1625 0, 10, 12, 16, 21, 32, 36, 38, 42, 48, 54, 59, 61, 70, | |
1626 72, 74, 77, 87, 91, 96, 114, 121, 126, 131, 140, 143, 163, 166, | |
1627 169, 172, 175, 178, 181, 184, 193, 204, 217, 228, 231, 251, 262, 269, | |
1628 275, 280, 291, 328, 334, 340, 346, 351, 355, 364, 373, 377, 386, 395, | |
1629 404, 413, 422, 431, 440, 443, 446, 449, 452, 455, 458, 461, 470, 474, | |
1630 481, 483, 487, 490, 493, 502, 506, 523, 525, 529, 531, 534, 541, 548, | |
1631 554, 557, 568, 572, 576, 580, 584, 588, 592, 596, 600, 604, 608, 612, | |
1632 616, 625, 634, 643, 652, 661, 670, 679, 683, 692, 701, 705, 715, 718, | |
1633 721, 728, 732, 741, 745, 749, 753, 757, 761, 765, 769, 773, 777, 781, | |
1634 786, 796, 806, 809, 812, 816, 826, 835, 839 | |
1635 }; | |
1636 | |
1637 | |
1638 static const unsigned short ag_sbe[] = { | |
1639 3, 11, 14, 17, 26, 35, 37, 40, 44, 53, 56, 60, 66, 71, | |
1640 73, 75, 80, 90, 94, 104, 115, 123, 129, 137, 142, 159, 165, 168, | |
1641 171, 174, 177, 180, 183, 191, 201, 213, 223, 230, 247, 257, 266, 272, | |
1642 276, 288, 305, 331, 337, 343, 350, 353, 361, 370, 375, 383, 392, 401, | |
1643 410, 419, 428, 437, 442, 445, 448, 451, 454, 457, 460, 467, 472, 475, | |
1644 482, 484, 489, 492, 499, 504, 514, 524, 526, 530, 533, 538, 545, 551, | |
1645 556, 564, 570, 574, 578, 582, 586, 590, 594, 598, 602, 606, 610, 614, | |
1646 622, 631, 640, 649, 658, 667, 676, 681, 689, 698, 703, 712, 717, 720, | |
1647 725, 731, 738, 743, 747, 751, 755, 759, 763, 767, 771, 775, 779, 785, | |
1648 793, 803, 808, 811, 814, 823, 832, 837, 839 | |
1649 }; | |
1650 | |
1651 | |
1652 static const unsigned char ag_fl[] = { | |
1653 1,1,2,1,2,0,1,2,1,2,1,2,0,1,3,1,2,0,1,6,1,1,4,1,2,3,3,3,1,1,3,1,1,1,1, | |
1654 1,1,1,2,2,2,2,3,1,3,0,1,2,0,1,3,1,1,2,1,2,0,1,2,1,2,0,1,2,3,3,1,2,0,1, | |
1655 2,1,2,0,1,2,1,2,0,1,2,3,1,1,2,0,1,3,4,3,2,0,1,0,1,4,5,2,4,5,5,3,6,3,5, | |
1656 3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,1,2,1,2,1,2,1,2 | |
1657 }; | |
1658 | |
1659 static const unsigned char ag_ptt[] = { | |
1660 0, 1, 1, 6, 6, 7, 7, 4, 9, 9, 12, 12, 13, 13, 10, 14, 14, 15, | |
1661 15, 11, 16, 19, 19, 20, 20, 18, 18, 18, 17, 27, 27, 29, 29, 29, 29, 29, | |
1662 29, 28, 28, 28, 28, 28, 28, 35, 35, 37, 40, 40, 41, 41, 36, 30, 42, 42, | |
1663 46, 46, 47, 47, 31, 50, 50, 51, 51, 45, 45, 45, 54, 54, 55, 55, 32, 57, | |
1664 57, 58, 58, 33, 61, 61, 62, 62, 56, 56, 34, 63, 63, 68, 68, 38, 38, 39, | |
1665 43, 72, 72, 74, 74, 69, 69, 44, 75, 75, 48, 49, 52, 53, 59, 60, 64, 64, | |
1666 64, 64, 64, 64, 64, 65, 65, 65, 65, 65, 65, 65, 67, 67, 73, 73, 70, 70, | |
1667 71, 71 | |
1668 }; | |
1669 | |
1670 | |
1671 static void ag_ra(void) | |
1672 { | |
1673 switch(ag_rpx[(PCB).ag_ap]) { | |
1674 case 1: ag_rp_1(); break; | |
1675 case 2: ag_rp_2(); break; | |
1676 case 3: ag_rp_3(); break; | |
1677 case 4: ag_rp_4(VS(0)); break; | |
1678 case 5: ag_rp_5(VS(1)); break; | |
1679 case 6: ag_rp_6(); break; | |
1680 case 7: ag_rp_7(); break; | |
1681 case 8: ag_rp_8(); break; | |
1682 case 9: ag_rp_9(); break; | |
1683 case 10: ag_rp_10(); break; | |
1684 case 11: ag_rp_11(); break; | |
1685 case 12: ag_rp_12(); break; | |
1686 case 13: ag_rp_13(); break; | |
1687 case 14: ag_rp_14(); break; | |
1688 case 15: ag_rp_15(); break; | |
1689 case 16: ag_rp_16(); break; | |
1690 case 17: ag_rp_17(); break; | |
1691 case 18: ag_rp_18(); break; | |
1692 case 19: ag_rp_19(); break; | |
1693 case 20: ag_rp_20(); break; | |
1694 case 21: ag_rp_21(); break; | |
1695 case 22: ag_rp_22(); break; | |
1696 case 23: ag_rp_23(); break; | |
1697 case 24: ag_rp_24(VS(0)); break; | |
1698 case 25: ag_rp_25(VS(1)); break; | |
1699 case 26: ag_rp_26(VS(0)); break; | |
1700 case 27: ag_rp_27(); break; | |
1701 case 28: ag_rp_28(VS(2)); break; | |
1702 case 29: ag_rp_29(VS(3)); break; | |
1703 case 30: ag_rp_30(); break; | |
1704 case 31: ag_rp_31(VS(2)); break; | |
1705 case 32: ag_rp_32(VS(3)); break; | |
1706 case 33: ag_rp_33(VS(2)); break; | |
1707 case 34: ag_rp_34(VS(0)); break; | |
1708 case 35: ag_rp_35(VS(3)); break; | |
1709 case 36: ag_rp_36(VS(0)); break; | |
1710 case 37: ag_rp_37(VS(1), VS(2)); break; | |
1711 case 38: ag_rp_38(VS(0)); break; | |
1712 case 39: ag_rp_39(VS(1)); break; | |
1713 case 40: ag_rp_40(VS(1)); break; | |
1714 case 41: ag_rp_41(VS(1)); break; | |
1715 case 42: ag_rp_42(VS(1)); break; | |
1716 case 43: ag_rp_43(VS(1)); break; | |
1717 case 44: ag_rp_44(VS(1)); break; | |
1718 case 45: ag_rp_45(VS(1)); break; | |
1719 case 46: ag_rp_46(VS(1)); break; | |
1720 case 47: ag_rp_47(VS(1)); break; | |
1721 case 48: ag_rp_48(VS(1)); break; | |
1722 case 49: ag_rp_49(VS(1)); break; | |
1723 case 50: ag_rp_50(VS(1)); break; | |
1724 case 51: ag_rp_51(VS(1)); break; | |
1725 case 52: ag_rp_52(VS(1)); break; | |
1726 case 53: ag_rp_53(VS(0)); break; | |
1727 case 54: ag_rp_54(VS(1)); break; | |
1728 case 55: ag_rp_55(VS(0)); break; | |
1729 case 56: ag_rp_56(VS(1)); break; | |
1730 case 57: ag_rp_57(VS(0)); break; | |
1731 case 58: ag_rp_58(VS(1)); break; | |
1732 case 59: ag_rp_59(); break; | |
1733 case 60: ag_rp_60(); break; | |
1734 } | |
1735 (PCB).la_ptr = (PCB).pointer; | |
1736 } | |
1737 | |
1738 #define TOKEN_NAMES mhh6_token_names | |
1739 const char *const mhh6_token_names[87] = { | |
1740 "help sourcefile", | |
1741 "blank line", | |
1742 "'\\n'", | |
1743 "'\\r'", | |
1744 "eof line", | |
1745 "blank", | |
1746 "", | |
1747 "", | |
1748 "eof", | |
1749 "eol", | |
1750 "help sourcefile", | |
1751 "topic", | |
1752 "", | |
1753 "", | |
1754 "", | |
1755 "", | |
1756 "title line", | |
1757 "topic lines", | |
1758 "end topic", | |
1759 "title line too", | |
1760 "title", | |
1761 "','", | |
1762 "lead title char", | |
1763 "title char", | |
1764 "\"##\"", | |
1765 "\"\\n##\"", | |
1766 "\"\\r\\n##\"", | |
1767 "topic lines too", | |
1768 "text parag", | |
1769 "parag", | |
1770 "table parag", | |
1771 "list1 parag", | |
1772 "list2 parag", | |
1773 "listtab parag", | |
1774 "code parag", | |
1775 "partial text parag", | |
1776 "text block", | |
1777 "", | |
1778 "first text line", | |
1779 "other text line", | |
1780 "", | |
1781 "", | |
1782 "table parag too", | |
1783 "first table line", | |
1784 "other table line", | |
1785 "list1 block", | |
1786 "", | |
1787 "", | |
1788 "first list1 line", | |
1789 "other list1 line", | |
1790 "", | |
1791 "", | |
1792 "first list2 line", | |
1793 "other list2 line", | |
1794 "", | |
1795 "", | |
1796 "listtab block", | |
1797 "", | |
1798 "", | |
1799 "first listtab line", | |
1800 "other listtab line", | |
1801 "", | |
1802 "", | |
1803 "code parag too", | |
1804 "first code line", | |
1805 "other code line", | |
1806 "lead topic char", | |
1807 "text frag", | |
1808 "", | |
1809 "first table line body", | |
1810 "tab seq", | |
1811 "blank seq", | |
1812 "", | |
1813 "table frag", | |
1814 "", | |
1815 "other table line body", | |
1816 "bullet", | |
1817 "tab", | |
1818 "\" \"", | |
1819 "\" \"", | |
1820 "\" \"", | |
1821 "\" \"", | |
1822 "\" \"", | |
1823 "\" \"", | |
1824 "\" \"", | |
1825 "text char", | |
1826 "table char", | |
1827 | |
1828 }; | |
1829 | |
1830 #ifndef MISSING_FORMAT | |
1831 #define MISSING_FORMAT "Missing %s" | |
1832 #endif | |
1833 #ifndef UNEXPECTED_FORMAT | |
1834 #define UNEXPECTED_FORMAT "Unexpected %s" | |
1835 #endif | |
1836 #ifndef UNNAMED_TOKEN | |
1837 #define UNNAMED_TOKEN "input" | |
1838 #endif | |
1839 | |
1840 | |
1841 static void ag_diagnose(void) { | |
1842 int ag_snd = (PCB).sn; | |
1843 int ag_k = ag_sbt[ag_snd]; | |
1844 | |
1845 if (*TOKEN_NAMES[ag_tstt[ag_k]] && ag_astt[ag_k + 1] == ag_action_8) { | |
1846 sprintf((PCB).ag_msg, MISSING_FORMAT, TOKEN_NAMES[ag_tstt[ag_k]]); | |
1847 } | |
1848 else if (ag_astt[ag_sbe[(PCB).sn]] == ag_action_8 | |
1849 && (ag_k = (int) ag_sbe[(PCB).sn] + 1) == (int) ag_sbt[(PCB).sn+1] - 1 | |
1850 && *TOKEN_NAMES[ag_tstt[ag_k]]) { | |
1851 sprintf((PCB).ag_msg, MISSING_FORMAT, TOKEN_NAMES[ag_tstt[ag_k]]); | |
1852 } | |
1853 else if ((PCB).token_number && *TOKEN_NAMES[(PCB).token_number]) { | |
1854 sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, TOKEN_NAMES[(PCB).token_number]); | |
1855 } | |
1856 else if (isprint(INPUT_CODE((*(PCB).pointer))) && INPUT_CODE((*(PCB).pointer)) != '\\') { | |
1857 char buf[20]; | |
1858 sprintf(buf, "\'%c\'", (char) INPUT_CODE((*(PCB).pointer))); | |
1859 sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, buf); | |
1860 } | |
1861 else sprintf((PCB).ag_msg, UNEXPECTED_FORMAT, UNNAMED_TOKEN); | |
1862 (PCB).error_message = (PCB).ag_msg; | |
1863 | |
1864 | |
1865 } | |
1866 static int ag_action_1_r_proc(void); | |
1867 static int ag_action_2_r_proc(void); | |
1868 static int ag_action_3_r_proc(void); | |
1869 static int ag_action_4_r_proc(void); | |
1870 static int ag_action_1_s_proc(void); | |
1871 static int ag_action_3_s_proc(void); | |
1872 static int ag_action_1_proc(void); | |
1873 static int ag_action_2_proc(void); | |
1874 static int ag_action_3_proc(void); | |
1875 static int ag_action_4_proc(void); | |
1876 static int ag_action_5_proc(void); | |
1877 static int ag_action_6_proc(void); | |
1878 static int ag_action_7_proc(void); | |
1879 static int ag_action_8_proc(void); | |
1880 static int ag_action_9_proc(void); | |
1881 static int ag_action_10_proc(void); | |
1882 static int ag_action_11_proc(void); | |
1883 static int ag_action_8_proc(void); | |
1884 | |
1885 | |
1886 static int (*const ag_r_procs_scan[])(void) = { | |
1887 ag_action_1_r_proc, | |
1888 ag_action_2_r_proc, | |
1889 ag_action_3_r_proc, | |
1890 ag_action_4_r_proc | |
1891 }; | |
1892 | |
1893 static int (*const ag_s_procs_scan[])(void) = { | |
1894 ag_action_1_s_proc, | |
1895 ag_action_2_r_proc, | |
1896 ag_action_3_s_proc, | |
1897 ag_action_4_r_proc | |
1898 }; | |
1899 | |
1900 static int (*const ag_gt_procs_scan[])(void) = { | |
1901 ag_action_1_proc, | |
1902 ag_action_2_proc, | |
1903 ag_action_3_proc, | |
1904 ag_action_4_proc, | |
1905 ag_action_5_proc, | |
1906 ag_action_6_proc, | |
1907 ag_action_7_proc, | |
1908 ag_action_8_proc, | |
1909 ag_action_9_proc, | |
1910 ag_action_10_proc, | |
1911 ag_action_11_proc, | |
1912 ag_action_8_proc | |
1913 }; | |
1914 | |
1915 | |
1916 static int ag_action_10_proc(void) { | |
1917 int ag_t = (PCB).token_number; | |
1918 (PCB).btsx = 0, (PCB).drt = -1; | |
1919 do { | |
1920 ag_track(); | |
1921 (PCB).token_number = (mhh6_token_type) AG_TCV(INPUT_CODE(*(PCB).la_ptr)); | |
1922 (PCB).la_ptr++; | |
1923 if (ag_key_index[(PCB).sn]) { | |
1924 unsigned ag_k = ag_key_index[(PCB).sn]; | |
1925 int ag_ch = CONVERT_CASE(INPUT_CODE(*(PCB).pointer)); | |
1926 if (ag_ch <= 255) { | |
1927 while (ag_key_ch[ag_k] < ag_ch) ag_k++; | |
1928 if (ag_key_ch[ag_k] == ag_ch) ag_get_key_word(ag_k); | |
1929 } | |
1930 } | |
1931 } while ((PCB).token_number == (mhh6_token_type) ag_t); | |
1932 (PCB).la_ptr = (PCB).pointer; | |
1933 return 1; | |
1934 } | |
1935 | |
1936 static int ag_action_11_proc(void) { | |
1937 int ag_t = (PCB).token_number; | |
1938 | |
1939 (PCB).btsx = 0, (PCB).drt = -1; | |
1940 do { | |
1941 (PCB).vs[(PCB).ssx] = *(PCB).pointer; | |
1942 (PCB).ssx--; | |
1943 ag_track(); | |
1944 ag_ra(); | |
1945 if ((PCB).exit_flag != AG_RUNNING_CODE) return 0; | |
1946 (PCB).ssx++; | |
1947 (PCB).token_number = (mhh6_token_type) AG_TCV(INPUT_CODE(*(PCB).la_ptr)); | |
1948 (PCB).la_ptr++; | |
1949 if (ag_key_index[(PCB).sn]) { | |
1950 unsigned ag_k = ag_key_index[(PCB).sn]; | |
1951 int ag_ch = CONVERT_CASE(INPUT_CODE(*(PCB).pointer)); | |
1952 if (ag_ch <= 255) { | |
1953 while (ag_key_ch[ag_k] < ag_ch) ag_k++; | |
1954 if (ag_key_ch[ag_k] == ag_ch) ag_get_key_word(ag_k); | |
1955 } | |
1956 } | |
1957 } | |
1958 while ((PCB).token_number == (mhh6_token_type) ag_t); | |
1959 (PCB).la_ptr = (PCB).pointer; | |
1960 return 1; | |
1961 } | |
1962 | |
1963 static int ag_action_3_r_proc(void) { | |
1964 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
1965 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
1966 (PCB).btsx = 0, (PCB).drt = -1; | |
1967 (PCB).reduction_token = (mhh6_token_type) ag_ptt[(PCB).ag_ap]; | |
1968 ag_ra(); | |
1969 return (PCB).exit_flag == AG_RUNNING_CODE; | |
1970 } | |
1971 | |
1972 static int ag_action_3_s_proc(void) { | |
1973 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
1974 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
1975 (PCB).btsx = 0, (PCB).drt = -1; | |
1976 (PCB).reduction_token = (mhh6_token_type) ag_ptt[(PCB).ag_ap]; | |
1977 ag_ra(); | |
1978 return (PCB).exit_flag == AG_RUNNING_CODE; | |
1979 } | |
1980 | |
1981 static int ag_action_4_r_proc(void) { | |
1982 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
1983 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
1984 (PCB).reduction_token = (mhh6_token_type) ag_ptt[(PCB).ag_ap]; | |
1985 return 1; | |
1986 } | |
1987 | |
1988 static int ag_action_2_proc(void) { | |
1989 (PCB).btsx = 0, (PCB).drt = -1; | |
1990 if ((PCB).ssx >= 128) { | |
1991 (PCB).exit_flag = AG_STACK_ERROR_CODE; | |
1992 PARSER_STACK_OVERFLOW; | |
1993 } | |
1994 (PCB).vs[(PCB).ssx] = *(PCB).pointer; | |
1995 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
1996 (PCB).ssx++; | |
1997 (PCB).sn = (PCB).ag_ap; | |
1998 ag_track(); | |
1999 return 0; | |
2000 } | |
2001 | |
2002 static int ag_action_9_proc(void) { | |
2003 if ((PCB).drt == -1) { | |
2004 (PCB).drt=(PCB).token_number; | |
2005 (PCB).dssx=(PCB).ssx; | |
2006 (PCB).dsn=(PCB).sn; | |
2007 } | |
2008 ag_prot(); | |
2009 (PCB).vs[(PCB).ssx] = ag_null_value; | |
2010 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
2011 (PCB).ssx++; | |
2012 (PCB).sn = (PCB).ag_ap; | |
2013 (PCB).la_ptr = (PCB).pointer; | |
2014 return (PCB).exit_flag == AG_RUNNING_CODE; | |
2015 } | |
2016 | |
2017 static int ag_action_2_r_proc(void) { | |
2018 (PCB).ssx++; | |
2019 (PCB).sn = (PCB).ag_ap; | |
2020 return 0; | |
2021 } | |
2022 | |
2023 static int ag_action_7_proc(void) { | |
2024 --(PCB).ssx; | |
2025 (PCB).la_ptr = (PCB).pointer; | |
2026 (PCB).exit_flag = AG_SUCCESS_CODE; | |
2027 return 0; | |
2028 } | |
2029 | |
2030 static int ag_action_1_proc(void) { | |
2031 ag_track(); | |
2032 (PCB).exit_flag = AG_SUCCESS_CODE; | |
2033 return 0; | |
2034 } | |
2035 | |
2036 static int ag_action_1_r_proc(void) { | |
2037 (PCB).exit_flag = AG_SUCCESS_CODE; | |
2038 return 0; | |
2039 } | |
2040 | |
2041 static int ag_action_1_s_proc(void) { | |
2042 (PCB).exit_flag = AG_SUCCESS_CODE; | |
2043 return 0; | |
2044 } | |
2045 | |
2046 static int ag_action_4_proc(void) { | |
2047 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
2048 (PCB).reduction_token = (mhh6_token_type) ag_ptt[(PCB).ag_ap]; | |
2049 (PCB).btsx = 0, (PCB).drt = -1; | |
2050 (PCB).vs[(PCB).ssx] = *(PCB).pointer; | |
2051 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
2052 else (PCB).ss[(PCB).ssx] = (PCB).sn; | |
2053 ag_track(); | |
2054 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
2055 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
2056 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
2057 do { | |
2058 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
2059 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
2060 else ag_t2 = ag_tx; | |
2061 } while (ag_t1 < ag_t2); | |
2062 (PCB).ag_ap = ag_pstt[ag_t1]; | |
2063 if ((ag_s_procs_scan[ag_astt[ag_t1]])() == 0) break; | |
2064 } | |
2065 return 0; | |
2066 } | |
2067 | |
2068 static int ag_action_3_proc(void) { | |
2069 int ag_sd = ag_fl[(PCB).ag_ap] - 1; | |
2070 (PCB).btsx = 0, (PCB).drt = -1; | |
2071 (PCB).vs[(PCB).ssx] = *(PCB).pointer; | |
2072 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
2073 else (PCB).ss[(PCB).ssx] = (PCB).sn; | |
2074 ag_track(); | |
2075 (PCB).reduction_token = (mhh6_token_type) ag_ptt[(PCB).ag_ap]; | |
2076 ag_ra(); | |
2077 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
2078 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
2079 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
2080 do { | |
2081 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
2082 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
2083 else ag_t2 = ag_tx; | |
2084 } while (ag_t1 < ag_t2); | |
2085 (PCB).ag_ap = ag_pstt[ag_t1]; | |
2086 if ((ag_s_procs_scan[ag_astt[ag_t1]])() == 0) break; | |
2087 } | |
2088 return 0; | |
2089 } | |
2090 | |
2091 static int ag_action_8_proc(void) { | |
2092 ag_undo(); | |
2093 (PCB).la_ptr = (PCB).pointer; | |
2094 (PCB).exit_flag = AG_SYNTAX_ERROR_CODE; | |
2095 ag_diagnose(); | |
2096 SYNTAX_ERROR; | |
2097 {(PCB).la_ptr = (PCB).pointer + 1; ag_track();} | |
2098 return (PCB).exit_flag == AG_RUNNING_CODE; | |
2099 } | |
2100 | |
2101 static int ag_action_5_proc(void) { | |
2102 int ag_sd = ag_fl[(PCB).ag_ap]; | |
2103 (PCB).btsx = 0, (PCB).drt = -1; | |
2104 if (ag_sd) (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
2105 else { | |
2106 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
2107 } | |
2108 (PCB).la_ptr = (PCB).pointer; | |
2109 (PCB).reduction_token = (mhh6_token_type) ag_ptt[(PCB).ag_ap]; | |
2110 ag_ra(); | |
2111 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
2112 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
2113 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
2114 do { | |
2115 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
2116 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
2117 else ag_t2 = ag_tx; | |
2118 } while (ag_t1 < ag_t2); | |
2119 (PCB).ag_ap = ag_pstt[ag_t1]; | |
2120 if ((ag_r_procs_scan[ag_astt[ag_t1]])() == 0) break; | |
2121 } | |
2122 return (PCB).exit_flag == AG_RUNNING_CODE; | |
2123 } | |
2124 | |
2125 static int ag_action_6_proc(void) { | |
2126 int ag_sd = ag_fl[(PCB).ag_ap]; | |
2127 (PCB).reduction_token = (mhh6_token_type) ag_ptt[(PCB).ag_ap]; | |
2128 if ((PCB).drt == -1) { | |
2129 (PCB).drt=(PCB).token_number; | |
2130 (PCB).dssx=(PCB).ssx; | |
2131 (PCB).dsn=(PCB).sn; | |
2132 } | |
2133 if (ag_sd) { | |
2134 (PCB).sn = (PCB).ss[(PCB).ssx -= ag_sd]; | |
2135 } | |
2136 else { | |
2137 ag_prot(); | |
2138 (PCB).vs[(PCB).ssx] = ag_null_value; | |
2139 (PCB).ss[(PCB).ssx] = (PCB).sn; | |
2140 } | |
2141 (PCB).la_ptr = (PCB).pointer; | |
2142 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
2143 unsigned ag_t1 = ag_sbe[(PCB).sn] + 1; | |
2144 unsigned ag_t2 = ag_sbt[(PCB).sn+1] - 1; | |
2145 do { | |
2146 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
2147 if (ag_tstt[ag_tx] < (unsigned char)(PCB).reduction_token) ag_t1 = ag_tx + 1; | |
2148 else ag_t2 = ag_tx; | |
2149 } while (ag_t1 < ag_t2); | |
2150 (PCB).ag_ap = ag_pstt[ag_t1]; | |
2151 if ((ag_r_procs_scan[ag_astt[ag_t1]])() == 0) break; | |
2152 } | |
2153 return (PCB).exit_flag == AG_RUNNING_CODE; | |
2154 } | |
2155 | |
2156 | |
2157 void init_mhh6(void) { | |
2158 (PCB).la_ptr = (PCB).pointer; | |
2159 (PCB).ss[0] = (PCB).sn = (PCB).ssx = 0; | |
2160 (PCB).exit_flag = AG_RUNNING_CODE; | |
2161 (PCB).line = FIRST_LINE; | |
2162 (PCB).column = FIRST_COLUMN; | |
2163 (PCB).btsx = 0, (PCB).drt = -1; | |
2164 } | |
2165 | |
2166 void mhh6(void) { | |
2167 init_mhh6(); | |
2168 (PCB).exit_flag = AG_RUNNING_CODE; | |
2169 while ((PCB).exit_flag == AG_RUNNING_CODE) { | |
2170 unsigned ag_t1 = ag_sbt[(PCB).sn]; | |
2171 if (ag_tstt[ag_t1]) { | |
2172 unsigned ag_t2 = ag_sbe[(PCB).sn] - 1; | |
2173 (PCB).token_number = (mhh6_token_type) AG_TCV(INPUT_CODE(*(PCB).la_ptr)); | |
2174 (PCB).la_ptr++; | |
2175 if (ag_key_index[(PCB).sn]) { | |
2176 unsigned ag_k = ag_key_index[(PCB).sn]; | |
2177 int ag_ch = CONVERT_CASE(INPUT_CODE(*(PCB).pointer)); | |
2178 if (ag_ch <= 255) { | |
2179 while (ag_key_ch[ag_k] < ag_ch) ag_k++; | |
2180 if (ag_key_ch[ag_k] == ag_ch) ag_get_key_word(ag_k); | |
2181 } | |
2182 } | |
2183 do { | |
2184 unsigned ag_tx = (ag_t1 + ag_t2)/2; | |
2185 if (ag_tstt[ag_tx] > (unsigned char)(PCB).token_number) | |
2186 ag_t1 = ag_tx + 1; | |
2187 else ag_t2 = ag_tx; | |
2188 } while (ag_t1 < ag_t2); | |
2189 if (ag_tstt[ag_t1] != (unsigned char)(PCB).token_number) | |
2190 ag_t1 = ag_sbe[(PCB).sn]; | |
2191 } | |
2192 (PCB).ag_ap = ag_pstt[ag_t1]; | |
2193 (ag_gt_procs_scan[ag_astt[ag_t1]])(); | |
2194 } | |
2195 } | |
2196 | |
2197 |