Pristine Ack-5.5
[Ack-5.5.git] / util / LLgen / src / Lpars.c.dist
1 /* LLgen generated code from source . */
2 #include "Lpars.h"
3 #define LLNOFIRSTS
4 #if __STDC__ || __cplusplus
5 #define LL_ANSI_C 1
6 #endif
7 #define LL_LEXI scanner
8 /* $Id: incl,v 2.13 1997/02/21 15:44:09 ceriel Exp $ */
9 #ifdef LL_DEBUG
10 #include <assert.h>
11 #include <stdio.h>
12 #define LL_assert(x)    assert(x)
13 #else
14 #define LL_assert(x)    /* nothing */
15 #endif
16
17 extern int LLsymb;
18
19 #define LL_SAFE(x)      /* Nothing */
20 #define LL_SSCANDONE(x) if (LLsymb != x) LLsafeerror(x)
21 #define LL_SCANDONE(x)  if (LLsymb != x) LLerror(x)
22 #define LL_NOSCANDONE(x) LLscan(x)
23 #ifdef LL_FASTER
24 #define LLscan(x)       if ((LLsymb = LL_LEXI()) != x) LLerror(x)
25 #endif
26
27 extern unsigned int LLscnt[];
28 extern unsigned int LLtcnt[];
29 extern int LLcsymb;
30
31 #if LL_NON_CORR
32 extern int LLstartsymb;
33 #endif
34
35 #define LLsdecr(d)      {LL_assert(LLscnt[d] > 0); LLscnt[d]--;}
36 #define LLtdecr(d)      {LL_assert(LLtcnt[d] > 0); LLtcnt[d]--;}
37 #define LLsincr(d)      LLscnt[d]++
38 #define LLtincr(d)      LLtcnt[d]++
39
40 #if LL_ANSI_C
41 extern int LL_LEXI(void);
42 extern void LLread(void);
43 extern int LLskip(void);
44 extern int LLnext(int);
45 extern void LLerror(int);
46 extern void LLsafeerror(int);
47 extern void LLnewlevel(unsigned int *);
48 extern void LLoldlevel(unsigned int *);
49 #ifndef LL_FASTER
50 extern void LLscan(int);
51 #endif
52 #ifndef LLNOFIRSTS
53 extern int LLfirst(int, int);
54 #endif
55 #if LL_NON_CORR
56 extern void LLnc_recover(void);
57 #endif
58 #else /* not LL_ANSI_C */
59 extern LLread();
60 extern int LLskip();
61 extern int LLnext();
62 extern LLerror();
63 extern LLsafeerror();
64 extern LLnewlevel();
65 extern LLoldlevel();
66 #ifndef LL_FASTER
67 extern LLscan();
68 #endif
69 #ifndef LLNOFIRSTS
70 extern int LLfirst();
71 #endif
72 #if LL_NON_CORR
73 extern LLnc_recover();
74 #endif
75 #endif /* not LL_ANSI_C */
76 #define LL_SSIZE 4
77 #define LL_NSETS 6
78 #define LL_NTERMINALS 32
79 #if LL_ANSI_C
80 void LL0_spec(void);
81 #endif
82 #if LL_ANSI_C
83 void LLparse(void)
84 #else
85 LLparse()
86 #endif
87  {
88         unsigned int s[LL_NTERMINALS+LL_NSETS+2];
89         LLnewlevel(s);
90         LLread();
91 LL0_spec();
92         LL_SCANDONE(EOFILE);
93         LLoldlevel(s);
94 }
95 static char LLsets[] = {
96 '\204','\343','\1','\0',
97 '\234','\4','\176','\354',
98 '\0','\4','\6','\0',
99 '\234','\0','\60','\350',
100 '\10','\0','\0','\340',
101 '\124','\0','\0','\0',
102 0 };
103 #define LLindex (LL_index+1)
104 static short LL_index[] = {0,0,
105 -1,
106 -1,
107 -1,
108 -1,
109 -1,
110 -1,
111 -1,
112 -1,
113 -1,
114 -1,
115 -1,
116 -1,
117 -1,
118 -1,
119 -1,
120 -1,
121 -1,
122 -1,
123 -1,
124 -1,
125 -1,
126 -1,
127 -1,
128 -1,
129 -1,
130 -1,
131 -1,
132 -1,
133 -1,
134 -1,
135 -1,
136 -1,
137 -1,
138 -1,
139 -1,
140 -1,
141 -1,
142 -1,
143 -1,
144 -1,
145 -1,
146 30,
147 31,
148 23,
149 -1,
150 -1,
151 -1,
152 -1,
153 -1,
154 -1,
155 -1,
156 -1,
157 -1,
158 -1,
159 -1,
160 -1,
161 -1,
162 25,
163 24,
164 -1,
165 -1,
166 -1,
167 29,
168 -1,
169 -1,
170 -1,
171 -1,
172 -1,
173 -1,
174 -1,
175 -1,
176 -1,
177 -1,
178 -1,
179 -1,
180 -1,
181 -1,
182 -1,
183 -1,
184 -1,
185 -1,
186 -1,
187 -1,
188 -1,
189 -1,
190 -1,
191 -1,
192 -1,
193 -1,
194 -1,
195 27,
196 -1,
197 28,
198 -1,
199 -1,
200 -1,
201 -1,
202 -1,
203 -1,
204 -1,
205 -1,
206 -1,
207 -1,
208 -1,
209 -1,
210 -1,
211 -1,
212 -1,
213 -1,
214 -1,
215 -1,
216 -1,
217 -1,
218 -1,
219 -1,
220 -1,
221 -1,
222 -1,
223 -1,
224 -1,
225 -1,
226 -1,
227 -1,
228 26,
229 -1,
230 -1,
231 -1,
232 -1,
233 -1,
234 -1,
235 -1,
236 -1,
237 -1,
238 -1,
239 -1,
240 -1,
241 -1,
242 -1,
243 -1,
244 -1,
245 -1,
246 -1,
247 -1,
248 -1,
249 -1,
250 -1,
251 -1,
252 -1,
253 -1,
254 -1,
255 -1,
256 -1,
257 -1,
258 -1,
259 -1,
260 -1,
261 -1,
262 -1,
263 -1,
264 -1,
265 -1,
266 -1,
267 -1,
268 -1,
269 -1,
270 -1,
271 -1,
272 -1,
273 -1,
274 -1,
275 -1,
276 -1,
277 -1,
278 -1,
279 -1,
280 -1,
281 -1,
282 -1,
283 -1,
284 -1,
285 -1,
286 -1,
287 -1,
288 -1,
289 -1,
290 -1,
291 -1,
292 -1,
293 -1,
294 -1,
295 -1,
296 -1,
297 -1,
298 -1,
299 -1,
300 -1,
301 -1,
302 -1,
303 -1,
304 -1,
305 -1,
306 -1,
307 -1,
308 -1,
309 -1,
310 -1,
311 -1,
312 -1,
313 -1,
314 -1,
315 -1,
316 -1,
317 -1,
318 -1,
319 -1,
320 -1,
321 -1,
322 -1,
323 -1,
324 -1,
325 -1,
326 -1,
327 -1,
328 -1,
329 -1,
330 -1,
331 -1,
332 -1,
333 -1,
334 -1,
335 -1,
336 -1,
337 -1,
338 -1,
339 -1,
340 -1,
341 -1,
342 -1,
343 -1,
344 -1,
345 -1,
346 -1,
347 -1,
348 -1,
349 -1,
350 -1,
351 -1,
352 -1,
353 -1,
354 -1,
355 -1,
356 -1,
357 -1,
358 -1,
359 -1,
360 0,
361 1,
362 2,
363 3,
364 4,
365 5,
366 6,
367 7,
368 8,
369 9,
370 10,
371 11,
372 12,
373 13,
374 14,
375 15,
376 16,
377 17,
378 18,
379 19,
380 20,
381 21,
382 22,
383 0 };
384 #define LL_NEWMESS
385 /* 
386  * Some grammar independent code.
387  * This file is copied into Lpars.c.
388  */
389
390 #ifndef lint
391 static char *rcsid = "$Id: rec,v 2.24 1998/11/10 14:26:06 ceriel Exp $";
392 #endif
393
394 unsigned int    LLtcnt[LL_NTERMINALS];
395 unsigned int    LLscnt[LL_NSETS];
396 int             LLcsymb, LLsymb;
397 static int      LLlevel;
398
399 #if LL_NON_CORR
400 int             LLstartsymb;
401 static int      fake_eof = 0;
402 #endif
403
404 #if LL_ANSI_C
405 #define LL_VOIDCST (void)
406 void    LLmessage(int);
407 #else
408 #define LL_VOIDCST
409 #endif
410 #ifdef LL_USERHOOK
411 #if LL_ANSI_C
412 static int      LLdoskip(int);
413 static int      LLuserhook(int, int*);
414 #else
415 static int      LLdoskip();
416 static int      LLuserhook();
417 #endif
418 #endif
419
420 #ifndef LL_FASTER
421 #if LL_ANSI_C
422 void LLscan(int t)
423 #else
424 LLscan(t)
425         int     t;
426 #endif
427 {
428         /*
429          * Check if the next symbol is equal to the parameter
430          */
431
432 #if LL_NON_CORR
433         /* See if the error recovery has eaten an eof */
434         if (fake_eof) {
435                 LLsymb = EOFILE;
436                 fake_eof = 0;
437         }
438         else {
439                 LLsymb = LL_LEXI();
440         }
441
442         if (LLsymb == t) {
443 #else
444         if ((LLsymb = LL_LEXI()) == t) {
445 #endif
446
447 #if LL_NON_CORR
448                 /* Check if a previous parser has 'crashed', in that
449                  * case continue with non-correcting parser 
450                  */
451                 if (err_seen && !nc_done) {
452                         LLnc_recover();
453                         nc_done = 1;
454                         /* Remember that the error recovery has eaten an eof */
455                         fake_eof = 1;
456                         if (t != LLsymb) {
457                                 LLerror(t);
458                         }
459                         else
460                                 return;
461                 }
462 #endif
463                 return;
464         }
465         /*
466          * If we come here, an error has been detected
467          */
468         LLerror(t);
469 }
470 #endif
471
472 #if LL_ANSI_C
473 void LLread(void) {
474 #else
475 LLread() {
476 #endif
477
478 #if LL_NON_CORR
479         /* Again, check if another parser has crashed,
480          * in that case intercept and go to the
481          * non-correcting parser
482          */
483
484         if (err_seen && !nc_done) {
485                 LLnc_recover();
486                 nc_done = 1;
487                 /* Pretend we read end of file */
488                 LLsymb = EOFILE;
489                 LLcsymb = LLindex[EOFILE];
490                 fake_eof = 0;
491                 return;
492         }
493
494         if (fake_eof) {
495                 LLsymb = EOFILE;
496                 LLcsymb = LLindex[EOFILE];
497                 fake_eof = 0;
498                 return;
499         }
500 #endif
501
502         for (;;) {
503                 if ((LLcsymb = LLindex[(LLsymb = LL_LEXI())]) >= 0) return;
504                 LLmessage(0);
505         }
506         /* NOTREACHED */
507 }
508
509 #if LL_ANSI_C
510 void LLerror(int t)
511 #else
512 LLerror(t)
513         int     t;
514 #endif
515 {
516         register int i;
517
518         if (t == EOFILE && LLsymb <= 0) return;
519 #ifdef LL_NEWMESS
520         if (t == EOFILE) {
521 #ifdef LL_USERHOOK
522                 static int lst[] = { EOFILE, 0 };
523                 LL_VOIDCST LLuserhook(EOFILE, lst);
524 #endif /* LL_USERHOOK */
525                 if (LLsymb != EOFILE && LLsymb > 0) {
526                         LLmessage(-1);
527                         while ((LLsymb = LL_LEXI()) > 0 && LLsymb != EOFILE) 
528                                 /* nothing */ ;
529                 }
530                 return;
531         }
532 #endif
533
534 #if LL_NON_CORR
535         if ((!nc_done) && (LLsymb > 0) && (LLsymb != EOFILE)) {
536                 LLmessage(0);
537                 LLnc_recover();
538                 nc_done = 1;
539                 LLsymb = EOFILE;
540         }
541 #endif
542         
543         if ((LLcsymb = LLindex[LLsymb]) < 0) {
544                 LLmessage(0);
545                 LLread();
546         }
547         i = LLindex[t];
548         LLtcnt[i]++;
549 #ifdef LL_USERHOOK
550         LL_VOIDCST LLdoskip(t);
551 #else
552         LL_VOIDCST LLskip();
553 #endif
554         LLtcnt[i]--;
555         if (LLsymb != t) {
556 #if LL_NON_CORR
557                 /* A little kludge here; when using non-correcting recovery
558                  * it can happen that a program is correct but incomplete. 
559                  * Here, we test this, and make sure the appropriate 
560                  * message is generated 
561                  */
562                 if (! nc_done) {
563                         int oldLLsymb;
564                         oldLLsymb = LLsymb;
565                         LLsymb = EOFILE;
566                         LLmessage(0);
567                         nc_done = 1;    
568                 /* Not really, but to prevent more than 1 error message */
569                         LLsymb = oldLLsymb;
570                 }
571 #endif
572                 LLmessage(t);
573         }
574 }
575
576 #if LL_ANSI_C
577 void LLsafeerror(int t)
578 #else
579 LLsafeerror(t)
580         int     t;
581 #endif
582 {
583         if (t == EOFILE && LLsymb <= 0) return;
584 #ifdef LL_NEWMESS
585         if (t == EOFILE) {
586 #ifdef LL_USERHOOK
587                 static int lst[] = { EOFILE, 0 };
588                 LL_VOIDCST LLuserhook(EOFILE, lst);
589 #endif /* LL_USERHOOK */
590                 if (LLsymb != EOFILE && LLsymb > 0) {
591                         LLmessage(-1);
592                         while ((LLsymb = LL_LEXI()) > 0 && LLsymb != EOFILE) 
593                                 /* nothing */ ;
594                 }
595                 return;
596         }
597 #endif
598 #if LL_NON_CORR
599         if ((!nc_done) && (LLsymb > 0) && (LLsymb != EOFILE)) {
600                 LLmessage(0);
601                 LLnc_recover();
602                 nc_done = 1;
603                 LLsymb = EOFILE;
604         }
605         /* A little kludge here; when using non-correcting recovery
606          * it can happen that a program is correct but incomplete.
607          * Here, we test this, and make sure the appropriate
608          * message is generated
609          */
610         if (! nc_done) {
611                 int oldLLsymb;
612                 oldLLsymb = LLsymb;
613                 LLsymb = EOFILE;
614                 LLmessage(0);
615                 nc_done = 1;
616         /* Not really, but to prevent more than 1 error message */
617                 LLsymb = oldLLsymb;
618         }
619 #endif
620         LLmessage(t);
621 }
622
623 #ifndef LLNOFIRSTS
624 #if LL_ANSI_C
625 int LLfirst(int x, int d) {
626 #else
627 int LLfirst(x, d) {
628 #endif
629         register int i;
630
631         return (i = LLindex[x]) >= 0 &&
632                 (LLsets[d + (i >> 3)] & (1 << (i & 07)));
633 }
634 #endif
635
636 #if LL_ANSI_C
637 int LLnext(int n)
638 #else
639 int LLnext(n)
640         int     n;
641 #endif
642 {
643         /*      returns: 0 if the current symbol is'nt skipped, and it
644                          is'nt a member of "n",
645                          1 if we have a new symbol, but it is'nt a member,
646                          2 if the current symbol is a member,
647                          and 3 if we have a new symbol and it is a member.
648                 So, the low order bit indicates wether we have a new symbol,
649                 and the next bit indicates wether it is a member of "n".
650         */
651
652         int retval = 0;
653
654         if (LLskip()) retval = 1;
655         if (n <= 0 && LLsets[(LLcsymb >> 3) - n] & (1 << (LLcsymb & 07))) {
656                 retval |= 2;
657         }
658         else if (n > 0 && LLcsymb == LLindex[n]) retval |= 2;
659         return retval;
660 }
661
662 #if LL_ANSI_C
663 int LLskip(void) {
664 #else
665 int LLskip() {
666 #endif
667         /*      returns 0 if the current symbol is'nt skipped, and
668                 1 if it is, t.i., we have a new symbol
669         */
670 #ifdef LL_USERHOOK
671         return LLdoskip(0);
672 }
673
674 #if LL_ANSI_C
675 extern void LL_USERHOOK(int, int *);
676 static int LLuserhook(int e, int *list)
677 #else
678 static int LLuserhook(e, list)
679         int e;
680         int *list;
681 #endif
682 {
683         int old = LLsymb;
684         LL_USERHOOK(e, list);
685         LLread();
686         return LLsymb != old;
687 }
688
689 #if LL_ANSI_C
690 static void LLmklist(register int *list)
691 #else
692 static LLmklist(list)
693         register int *list;
694 #endif
695 {
696         char Xset[LL_SSIZE];
697         register char *p;
698         register int i;
699
700         for (p = &Xset[0]; p < &Xset[LL_SSIZE]; ) *p++ = 0;
701         for (i = 0; i < LL_NTERMINALS; i++) {
702                 if (LLtcnt[i] != 0) Xset[i >> 3] |= (1 << (i & 07));
703         }
704         for (i = LL_NSETS - 1; i >= 0; i--) if (LLscnt[i] != 0) {
705                 register char *q = &LLsets[LL_SSIZE * i];
706
707                 p = &Xset[0];
708                 while (p < &Xset[LL_SSIZE]) *p++ |= *q++;
709         }
710         for (i = 0; i < LL_NTERMINALS; i++) {
711                 if (Xset[i >> 3] & (1 << (i & 07))) {
712                         *list++ = LLtok[i];
713                 }
714         }
715         *list = 0;
716 }
717
718 #if LL_ANSI_C
719 static int LLdoskip(int e)
720 #else
721 static int LLdoskip(e)
722         int     e;
723 #endif
724 {
725         int LLx;
726         int list[LL_NTERMINALS+1];
727 #endif /* LL_USERHOOK */
728         register int i;
729         int retval;
730         int LLi, LLb;
731
732         retval = 0;
733 #ifdef LL_USERHOOK
734         LLmklist(list);
735         LLx = LLuserhook(e, list);
736         if (LLx) retval = 1;
737 #endif /* LL_USERHOOK */
738         for (;;) {
739                 if (LLtcnt[LLcsymb] != 0) {
740 #ifdef LL_USERHOOK
741                         if (!e || !LLx || LLcsymb == LLindex[e])
742 #endif
743                         return retval;
744                 }
745                 LLi = LLcsymb >> 3;
746                 LLb = 1 << (LLcsymb & 07);
747                 for (i = LL_NSETS - 1; i >= 0; i--) {
748                         if (LLscnt[i] != 0) {
749                                 if (LLsets[LL_SSIZE*i+LLi] & LLb) {
750 #ifdef LL_USERHOOK
751                                         if (!e || !LLx || LLcsymb == LLindex[e])
752 #endif
753                                         return retval;
754                                 }
755                         }
756                 }
757 #ifdef LL_USERHOOK
758                 if (LLx) {
759                         LLx = LLuserhook(e, list);
760                         continue;
761                 }
762 #endif /* LL_USERHOOK */
763 #if LL_NON_CORR
764                 if ((!nc_done) && (LLsymb > 0)) {
765                         LLmessage(0);
766                         LLnc_recover();
767                         nc_done = 1;
768                         fake_eof = 1;
769                 }
770                 else {
771                         LLmessage(0);
772                 }
773 #else
774                 LLmessage(0);
775 #endif
776                 retval = 1;
777                 LLread();
778         }
779         /* NOTREACHED */
780 }
781
782 #if LL_ANSI_C
783 void LLnewlevel(unsigned int *LLsinfo) {
784 #else
785 LLnewlevel(LLsinfo) unsigned int *LLsinfo; {
786 #endif
787         register int i;
788
789         if (LLlevel++) {
790                 LLsinfo[LL_NSETS+LL_NTERMINALS] = (unsigned) LLsymb;
791                 LLsinfo[LL_NSETS+LL_NTERMINALS+1] = (unsigned) LLcsymb;
792                 for (i = LL_NTERMINALS - 1; i >= 0; i--) {
793                         LLsinfo[i] = LLtcnt[i];
794                         LLtcnt[i] = 0;
795                 }
796                 for (i = LL_NSETS - 1; i >= 0; i--) {
797                         LLsinfo[LL_NTERMINALS+i] = LLscnt[i];
798                         LLscnt[i] = 0;
799                 }
800         }
801         LLtincr(0);
802 }
803
804 #if LL_ANSI_C
805 void LLoldlevel(unsigned int *LLsinfo) {
806 #else
807 LLoldlevel(LLsinfo) unsigned int *LLsinfo; {
808 #endif
809         register int i;
810
811         LLtdecr(0);
812 #ifdef LL_DEBUG
813         for (i = 0; i < LL_NTERMINALS; i++) LL_assert(LLtcnt[i] == 0);
814         for (i = 0; i < LL_NSETS; i++) LL_assert(LLscnt[i] == 0);
815 #endif
816         if (--LLlevel) {
817                 for (i = LL_NSETS - 1; i >= 0; i--) {
818                         LLscnt[i] = LLsinfo[LL_NTERMINALS+i];
819                 }
820                 for (i = LL_NTERMINALS - 1; i >= 0; i--) {
821                         LLtcnt[i] = LLsinfo[i];
822                 }
823                 LLsymb = (int) LLsinfo[LL_NSETS+LL_NTERMINALS];
824                 LLcsymb = (int) LLsinfo[LL_NSETS+LL_NTERMINALS+1];
825         }
826 }