Pristine Ack-5.5
[Ack-5.5.git] / util / LLgen / src / LLgen.c.dist
1 /* LLgen generated code from source LLgen.g */
2 #include "Lpars.h"
3 #define LL_LEXI scanner
4 #define LLNOFIRSTS
5 #if __STDC__ || __cplusplus
6 #define LL_ANSI_C 1
7 #endif
8 #define LL_LEXI scanner
9 /* $Id: incl,v 2.13 1997/02/21 15:44:09 ceriel Exp $ */
10 #ifdef LL_DEBUG
11 #include <assert.h>
12 #include <stdio.h>
13 #define LL_assert(x)    assert(x)
14 #else
15 #define LL_assert(x)    /* nothing */
16 #endif
17
18 extern int LLsymb;
19
20 #define LL_SAFE(x)      /* Nothing */
21 #define LL_SSCANDONE(x) if (LLsymb != x) LLsafeerror(x)
22 #define LL_SCANDONE(x)  if (LLsymb != x) LLerror(x)
23 #define LL_NOSCANDONE(x) LLscan(x)
24 #ifdef LL_FASTER
25 #define LLscan(x)       if ((LLsymb = LL_LEXI()) != x) LLerror(x)
26 #endif
27
28 extern unsigned int LLscnt[];
29 extern unsigned int LLtcnt[];
30 extern int LLcsymb;
31
32 #if LL_NON_CORR
33 extern int LLstartsymb;
34 #endif
35
36 #define LLsdecr(d)      {LL_assert(LLscnt[d] > 0); LLscnt[d]--;}
37 #define LLtdecr(d)      {LL_assert(LLtcnt[d] > 0); LLtcnt[d]--;}
38 #define LLsincr(d)      LLscnt[d]++
39 #define LLtincr(d)      LLtcnt[d]++
40
41 #if LL_ANSI_C
42 extern int LL_LEXI(void);
43 extern void LLread(void);
44 extern int LLskip(void);
45 extern int LLnext(int);
46 extern void LLerror(int);
47 extern void LLsafeerror(int);
48 extern void LLnewlevel(unsigned int *);
49 extern void LLoldlevel(unsigned int *);
50 #ifndef LL_FASTER
51 extern void LLscan(int);
52 #endif
53 #ifndef LLNOFIRSTS
54 extern int LLfirst(int, int);
55 #endif
56 #if LL_NON_CORR
57 extern void LLnc_recover(void);
58 #endif
59 #else /* not LL_ANSI_C */
60 extern LLread();
61 extern int LLskip();
62 extern int LLnext();
63 extern LLerror();
64 extern LLsafeerror();
65 extern LLnewlevel();
66 extern LLoldlevel();
67 #ifndef LL_FASTER
68 extern LLscan();
69 #endif
70 #ifndef LLNOFIRSTS
71 extern int LLfirst();
72 #endif
73 #if LL_NON_CORR
74 extern LLnc_recover();
75 #endif
76 #endif /* not LL_ANSI_C */
77 # line 20 "LLgen.g"
78
79 # include "types.h"
80 # include "io.h"
81 # include "extern.h"
82 # include "assert.h"
83 # include "cclass.h"
84
85 # ifndef NORCSID
86 static string   rcsid = "$Id: LLgen.g,v 2.28 1997/02/21 11:27:38 ceriel Exp $";
87 # endif
88 p_mem           alloc(), ralloc();
89 string          store();
90 p_gram          search();
91 long            ftell();
92
93 static int      acount;                 /* count #of global actions */
94 static p_term t_list;
95 static int t_cnt;
96 static p_gram   alt_table;
97 static int      n_alts;
98 static int      max_alts;
99 #define ALTINCR 32
100
101 static p_gram   rule_table;
102 static int      n_rules;
103 static int      max_rules;
104 #define RULEINCR        32
105
106 /* Here are defined : */
107 STATIC          newnorder();
108 STATIC          newtorder();
109 STATIC          mkalt();
110 STATIC          mkterm();
111 STATIC p_gram   copyrule();
112 /* and of course LLparse() */
113
114 STATIC
115 newnorder(index) {
116         static int porder;
117
118         if (norder != -1) {
119                 nonterms[porder].n_next = index;
120         }
121         else    norder = index;
122         porder = index;
123         nonterms[porder].n_next = -1;
124 }
125
126 STATIC
127 newtorder(index) {
128         static int porder;
129
130         if (torder != -1) {
131                 tokens[porder].t_next = index;
132         }
133         else    torder = index;
134         porder = index;
135         tokens[porder].t_next = -1;
136 }
137
138 p_init()
139 {
140         alt_table = (p_gram )alloc(ALTINCR*sizeof(t_gram));
141         n_alts = 0;
142         max_alts = ALTINCR;
143         rule_table = (p_gram )alloc(RULEINCR*sizeof(t_gram));
144         n_rules = 0;
145         max_rules = RULEINCR;
146 }
147
148 #if LL_ANSI_C
149 static void LL1_def(void);
150 static void LL2_rule(void);
151 static void LL3_listel(void);
152 static void LL4_firsts(void);
153 static void LL5_productions(
154 # line 244 "LLgen.g"
155 p_gram *p) ;
156 static void LL6_simpleproduction(
157 # line 330 "LLgen.g"
158 p_gram *p ,register int *conflres) ;
159 static void LL7_elem(
160 # line 478 "LLgen.g"
161 register p_gram pres) ;
162 static void LL8_repeats(
163 # line 600 "LLgen.g"
164 int *kind ,int *cnt) ;
165 static void LL9_number(
166 # line 617 "LLgen.g"
167 int *t) ;
168 #else
169 static LL1_def();
170 static LL2_rule();
171 static LL3_listel();
172 static LL4_firsts();
173 static LL5_productions();
174 static LL6_simpleproduction();
175 static LL7_elem();
176 static LL8_repeats();
177 static LL9_number();
178 #endif
179 #if LL_ANSI_C
180 void
181 #endif
182 LL0_spec(
183 #if LL_ANSI_C
184 void
185 #endif
186 ) {
187 LLsincr(0);
188 # line 94 "LLgen.g"
189 {       acount = 0; p_init(); }
190 for (;;) {
191 goto L_1;
192 L_1 : {switch(LLcsymb) {
193 case /*  EOFILE  */ 0 : ;
194 break;
195 default:{int LL_1=LLnext(0);
196 ;if (!LL_1) {
197 break;
198 }
199 else if (LL_1 & 1) goto L_1;}
200 case /*  C_IDENT  */ 2 : ;
201 case /*  C_ACTION  */ 7 : ;
202 case /*  C_TOKEN  */ 8 : ;
203 case /*  C_START  */ 9 : ;
204 case /*  C_FIRST  */ 13 : ;
205 case /*  C_LEXICAL  */ 14 : ;
206 case /*  C_PREFIX  */ 15 : ;
207 case /*  C_ONERROR  */ 16 : ;
208 LL1_def();
209 LLread();
210 continue;
211 }
212 }
213 LLsdecr(0);
214 break;
215 }
216 # line 96 "LLgen.g"
217 {       /*
218                                  * Put an endmarker in temporary file
219                                  */
220                                 putc('\0', fact);
221                                 putc('\0', fact);
222                                 free((p_mem) rule_table);
223                                 free((p_mem) alt_table);
224                         }
225 }
226 static
227 #if LL_ANSI_C
228 void
229 #endif
230 LL1_def(
231 #if LL_ANSI_C
232 void
233 #endif
234 ) {
235 # line 106 "LLgen.g"
236         register string p; 
237 switch(LLcsymb) {
238 case /*  C_IDENT  */ 2 : ;
239 LL2_rule();
240 break;
241 case /*  C_TOKEN  */ 8 : ;
242 LLtincr(23);
243 LLtincr(24);
244 LL_SAFE(C_TOKEN);
245 LL3_listel();
246 LLread();
247 for (;;) {
248 goto L_4;
249 L_4 : {switch(LLcsymb) {
250 case /* ';' */ 24 : ;
251 break;
252 default:{int LL_2=LLnext(44);
253 ;if (!LL_2) {
254 break;
255 }
256 else if (LL_2 & 1) goto L_4;}
257 case /* ',' */ 23 : ;
258 LL_SAFE(',');
259 LL3_listel();
260 LLread();
261 continue;
262 }
263 }
264 LLtdecr(23);
265 break;
266 }
267 LLtdecr(24);
268 LL_SSCANDONE(';');
269 break;
270 case /*  C_START  */ 9 : ;
271 LLtincr(23);
272 LLtincr(2);
273 LLtincr(24);
274 LL_SAFE(C_START);
275 LL_NOSCANDONE(C_IDENT);
276 # line 116 "LLgen.g"
277 {       p = store(lextoken.t_string); }
278 LLtdecr(23);
279 LL_NOSCANDONE(',');
280 LLtdecr(2);
281 LL_NOSCANDONE(C_IDENT);
282 # line 121 "LLgen.g"
283 {       /*
284                                  * Put the declaration in the list
285                                  * of start symbols
286                                  */
287                                 register p_gram temp;
288                                 register p_start ff;
289
290                                 temp = search(NONTERM,lextoken.t_string,BOTH);
291                                 ff = (p_start) alloc(sizeof(t_start));
292                                 ff->ff_nont = g_getcont(temp);
293                                 ff->ff_name = p;
294                                 ff->ff_next = start;
295                                 start = ff;
296                                 while (ff = ff->ff_next) {
297                                         if (! strcmp(p, ff->ff_name)) {
298                                                 error(linecount, "\"%s\" already used in a %%start", p);
299                                                 break;
300                                         }
301                                 }
302                         }
303 LLtdecr(24);
304 LL_NOSCANDONE(';');
305 break;
306 case /*  C_LEXICAL  */ 14 : ;
307 LLtincr(24);
308 LL_SAFE(C_LEXICAL);
309 LL_NOSCANDONE(C_IDENT);
310 # line 147 "LLgen.g"
311 {       if (!lexical) {
312                                         lexical = store(lextoken.t_string);
313                                 }
314                                 else    error(linecount,"Duplicate %%lexical");
315                         }
316 LLtdecr(24);
317 LL_NOSCANDONE(';');
318 break;
319 case /*  C_PREFIX  */ 15 : ;
320 LLtincr(24);
321 LL_SAFE(C_PREFIX);
322 LL_NOSCANDONE(C_IDENT);
323 # line 157 "LLgen.g"
324 {       if (!prefix) {
325                                         prefix = store(lextoken.t_string);
326                                         if (strlen(prefix) > 6) {
327                                                 error(linecount,
328                                                         "%%prefix too long");
329                                                 prefix[6] = 0;
330                                         }
331                                 }
332                                 else    error(linecount,"Duplicate %%prefix");
333                         }
334 LLtdecr(24);
335 LL_NOSCANDONE(';');
336 break;
337 case /*  C_ONERROR  */ 16 : ;
338 LLtincr(24);
339 LL_SAFE(C_ONERROR);
340 LL_NOSCANDONE(C_IDENT);
341 # line 169 "LLgen.g"
342 {
343 #ifdef NON_CORRECTING
344                                 if (non_corr) {
345                                         warning(linecount, "%%onerror conflicts with -n option");
346                                 }
347                                 else
348 #endif
349                                   if (! onerror) {
350                                         onerror = store(lextoken.t_string);
351                                 }
352                                 else    error(linecount,"Duplicate %%onerror");
353                         }
354 LLtdecr(24);
355 LL_NOSCANDONE(';');
356 break;
357 default:
358 LL_SSCANDONE(C_ACTION);
359 # line 182 "LLgen.g"
360 {       acount++; }
361 break;
362 case /*  C_FIRST  */ 13 : ;
363 LL4_firsts();
364 break;
365 }
366 }
367 static
368 #if LL_ANSI_C
369 void
370 #endif
371 LL3_listel(
372 #if LL_ANSI_C
373 void
374 #endif
375 ) {
376 LL_NOSCANDONE(C_IDENT);
377 # line 192 "LLgen.g"
378 {       p_gram temp = search(TERMINAL,lextoken.t_string,ENTERING);
379                                 newtorder(g_getcont(temp));
380                                 tokens[g_getcont(temp)].t_lineno = linecount;
381                         }
382 }
383 static
384 #if LL_ANSI_C
385 void
386 #endif
387 LL2_rule(
388 #if LL_ANSI_C
389 void
390 #endif
391 ) {
392 # line 198 "LLgen.g"
393         register p_nont p;
394                                 p_gram rr;
395                                 register p_gram temp;
396                         
397 LLtincr(6);
398 LLtincr(7);
399 LLtincr(25);
400 LLsincr(1);
401 LLtincr(24);
402 LL_SAFE(C_IDENT);
403 # line 205 "LLgen.g"
404 {       temp = search(NONTERM,lextoken.t_string,BOTH);
405                                 p = &nonterms[g_getcont(temp)];
406                                 if (p->n_rule) {
407                                         error(linecount,
408 "Nonterminal %s already defined", lextoken.t_string);
409                                 }
410                                 /*
411                                  * Remember the order in which the nonterminals
412                                  * were defined. Code must be generated in that
413                                  * order to keep track with the actions on the
414                                  * temporary file
415                                  */
416                                 newnorder(p - nonterms);
417                                 p->n_count = acount;
418                                 acount = 0;
419                                 p->n_lineno = linecount;
420                                 p->n_off = ftell(fact);
421                         }
422 LLread();
423 goto L_1;
424 L_1 : {switch(LLcsymb) {
425 case /*  C_ACTION  */ 7 : ;
426 case /* ':' */ 25 : ;
427 LLtdecr(6);
428 break;
429 default:{int LL_3=LLnext(262);
430 ;if (!LL_3) {
431 LLtdecr(6);
432 break;
433 }
434 else if (LL_3 & 1) goto L_1;}
435 case /*  C_PARAMS  */ 6 : ;
436 LLtdecr(6);
437 LL_SAFE(C_PARAMS);
438 # line 223 "LLgen.g"
439 {       if (lextoken.t_num > 0) {
440                                         p->n_flags |= PARAMS;
441                                         if (lextoken.t_num > 15) {
442                                                 error(linecount,"Too many parameters");
443                                         }
444                                         else    setntparams(p,lextoken.t_num);
445                                 }
446                         }
447 LLread();
448 }
449 }
450 goto L_2;
451 L_2 : {switch(LLcsymb) {
452 case /* ':' */ 25 : ;
453 LLtdecr(7);
454 break;
455 default:{int LL_4=LLnext(263);
456 ;if (!LL_4) {
457 LLtdecr(7);
458 break;
459 }
460 else if (LL_4 & 1) goto L_2;}
461 case /*  C_ACTION  */ 7 : ;
462 LLtdecr(7);
463 LL_SAFE(C_ACTION);
464 # line 232 "LLgen.g"
465 {       p->n_flags |= LOCALS; }
466 LLread();
467 }
468 }
469 LLtdecr(25);
470 LL_SCANDONE(':');
471 # line 234 "LLgen.g"
472 {       in_production = 1; }
473 LLread();
474 LLsdecr(1);
475 LL5_productions(
476 # line 235 "LLgen.g"
477 &rr);
478 LLtdecr(24);
479 LL_SCANDONE(';');
480 # line 236 "LLgen.g"
481 {       in_production = 0; }
482 # line 241 "LLgen.g"
483 {       nonterms[g_getcont(temp)].n_rule = rr;}
484 }
485 static
486 #if LL_ANSI_C
487 void
488 #endif
489 LL5_productions(
490 #if LL_ANSI_C
491 # line 244 "LLgen.g"
492 p_gram *p)  
493 #else
494 # line 244 "LLgen.g"
495  p) p_gram *p; 
496 #endif
497 {
498 # line 248 "LLgen.g"
499         p_gram          prod;
500                 int             conflres = 0;
501                 int             t = 0;
502                 int             haddefault = 0;
503                 int             altcnt = 0;
504                 int             o_lc, n_lc;
505         
506 LLtincr(26);
507 # line 255 "LLgen.g"
508 {       o_lc = linecount; }
509 LL6_simpleproduction(
510 # line 256 "LLgen.g"
511 p,&conflres);
512 # line 257 "LLgen.g"
513 {       if (conflres & DEF) haddefault = 1; }
514 goto L_2; /* so that the label is used for certain */
515 L_2: ;
516 switch(LLcsymb) {
517 case /* '|' */ 26 : ;
518 LLtdecr(26);
519 LLsincr(1);
520 LLsdecr(1);
521 LLtincr(26);
522 for (;;) {
523 LL_SAFE('|');
524 # line 259 "LLgen.g"
525 {       n_lc = linecount; }
526 LLread();
527 LL6_simpleproduction(
528 # line 260 "LLgen.g"
529 &prod,&t);
530 # line 261 "LLgen.g"
531 {       if (n_alts >= max_alts-2) {
532                                         alt_table = (p_gram ) ralloc(
533                                                 (p_mem) alt_table,
534                                                 (unsigned)(max_alts+=ALTINCR)*sizeof(t_gram));
535                                 }
536                                 if (t & DEF) {
537                                         if (haddefault) {
538                                                 error(n_lc,
539                 "More than one %%default in alternation");
540                                         }
541                                         haddefault = 1;
542                                 }
543                                 mkalt(*p,conflres,o_lc,&alt_table[n_alts++]);
544                                 altcnt++;
545                                 o_lc = n_lc;
546                                 conflres = t;
547                                 t = 0;
548                                 *p = prod;
549                         }
550 goto L_4;
551 L_4 : {switch(LLcsymb) {
552 case /* ';' */ 24 : ;
553 case /* ']' */ 28 : ;
554 break;
555 default:{int LL_5=LLnext(124);
556 ;if (!LL_5) {
557 break;
558 }
559 else if (LL_5 & 1) goto L_4;}
560 case /* '|' */ 26 : ;
561 continue;
562 }
563 }
564 LLtdecr(26);
565 break;
566 }
567 # line 280 "LLgen.g"
568 {       if (conflres & (COND|PREFERING|AVOIDING)) {
569                                         error(n_lc,
570                 "Resolver on last alternative not allowed");
571                                 }
572                                 mkalt(*p,conflres,n_lc,&alt_table[n_alts++]);
573                                 altcnt++;
574                                 g_settype((&alt_table[n_alts]),EORULE);
575                                 *p = copyrule(&alt_table[n_alts-altcnt],altcnt+1);
576                         }
577 break;
578 case /* ';' */ 24 : ;
579 case /* ']' */ 28 : ;
580 goto L_3;
581 L_3: ;
582 LLtdecr(26);
583 # line 290 "LLgen.g"
584 {       if (conflres & (COND|PREFERING|AVOIDING)) {
585                                         error(o_lc,
586                 "No alternation conflict resolver allowed here");
587                                 }
588                                 /*
589                                 if (conflres & DEF) {
590                                         error(o_lc,
591                 "No %%default allowed here");
592                                 }
593                                 */
594                         }
595 break;
596 default: if (LLskip()) goto L_2;
597 goto L_3;
598 }
599 # line 302 "LLgen.g"
600 {       n_alts -= altcnt; }
601 }
602 # line 304 "LLgen.g"
603
604
605 STATIC
606 mkalt(prod,condition,lc,res) p_gram prod; register p_gram res; {
607         /*
608          * Create an alternation and initialise it.
609          */
610         register p_link         l;
611         static p_link list;
612         static int cnt;
613
614         if (! cnt) {
615                 cnt = 50;
616                 list = (p_link) alloc(50 * sizeof(t_link));
617         }
618         cnt--;
619         l = list++;
620         l->l_rule = prod;
621         l->l_flag = condition;
622         g_setlink(res,l);
623         g_settype(res,ALTERNATION);
624         res->g_lineno = lc;
625         nalts++;
626 }
627 static
628 #if LL_ANSI_C
629 void
630 #endif
631 LL6_simpleproduction(
632 #if LL_ANSI_C
633 # line 330 "LLgen.g"
634 p_gram *p ,register int *conflres)  
635 #else
636 # line 330 "LLgen.g"
637  p,conflres) p_gram *p; register int *conflres; 
638 #endif
639 {
640 # line 331 "LLgen.g"
641         t_gram          elem;
642                 int             elmcnt = 0;
643                 int             cnt, kind;
644                 int             termdeleted = 0;
645         
646 LLtincr(19);
647 LLsincr(2);
648 LLtincr(22);
649 LLsincr(3);
650 goto L_1;
651 L_1 : {switch(LLcsymb) {
652 case /*  C_IDENT  */ 2 : ;
653 case /*  C_LITERAL  */ 4 : ;
654 case /*  C_ACTION  */ 7 : ;
655 case /*  C_IF  */ 10 : ;
656 case /*  C_AVOID  */ 17 : ;
657 case /*  C_PREFER  */ 18 : ;
658 case /*  C_SUBSTART  */ 20 : ;
659 case /*  C_ERRONEOUS  */ 21 : ;
660 case /*  C_ILLEGAL  */ 22 : ;
661 case /* ';' */ 24 : ;
662 case /* '|' */ 26 : ;
663 case /* '[' */ 27 : ;
664 case /* ']' */ 28 : ;
665 LLtdecr(19);
666 break;
667 default:{int LL_6=LLnext(275);
668 ;if (!LL_6) {
669 LLtdecr(19);
670 break;
671 }
672 else if (LL_6 & 1) goto L_1;}
673 case /*  C_DEFAULT  */ 19 : ;
674 LLtdecr(19);
675 LL_SAFE(C_DEFAULT);
676 # line 336 "LLgen.g"
677 {       *conflres |= DEF; }
678 LLread();
679 }
680 }
681 goto L_2;
682 L_2 : {switch(LLcsymb) {
683 case /*  C_IDENT  */ 2 : ;
684 case /*  C_LITERAL  */ 4 : ;
685 case /*  C_ACTION  */ 7 : ;
686 case /*  C_SUBSTART  */ 20 : ;
687 case /*  C_ERRONEOUS  */ 21 : ;
688 case /*  C_ILLEGAL  */ 22 : ;
689 case /* ';' */ 24 : ;
690 case /* '|' */ 26 : ;
691 case /* '[' */ 27 : ;
692 case /* ']' */ 28 : ;
693 LLsdecr(2);
694 break;
695 default:{int LL_7=LLnext(-8);
696 ;if (!LL_7) {
697 LLsdecr(2);
698 break;
699 }
700 else if (LL_7 & 1) goto L_2;}
701 case /*  C_IF  */ 10 : ;
702 case /*  C_AVOID  */ 17 : ;
703 case /*  C_PREFER  */ 18 : ;
704 LLsdecr(2);
705 switch(LLcsymb) {
706 case /*  C_IF  */ 10 : ;
707 LL_SAFE(C_IF);
708 LL_NOSCANDONE(C_EXPR);
709 # line 342 "LLgen.g"
710 {       *conflres |= COND; }
711 break;
712 default:
713 LL_SAFE(C_PREFER);
714 # line 343 "LLgen.g"
715 {       *conflres |= PREFERING; }
716 break;
717 case /*  C_AVOID  */ 17 : ;
718 LL_SAFE(C_AVOID);
719 # line 344 "LLgen.g"
720 {       *conflres |= AVOIDING; }
721 break;
722 }
723 LLread();
724 }
725 }
726 goto L_6;
727 L_6 : {switch(LLcsymb) {
728 case /*  C_IDENT  */ 2 : ;
729 case /*  C_LITERAL  */ 4 : ;
730 case /*  C_ACTION  */ 7 : ;
731 case /*  C_SUBSTART  */ 20 : ;
732 case /*  C_ERRONEOUS  */ 21 : ;
733 case /* ';' */ 24 : ;
734 case /* '|' */ 26 : ;
735 case /* '[' */ 27 : ;
736 case /* ']' */ 28 : ;
737 LLtdecr(22);
738 break;
739 default:{int LL_8=LLnext(278);
740 ;if (!LL_8) {
741 LLtdecr(22);
742 break;
743 }
744 else if (LL_8 & 1) goto L_6;}
745 case /*  C_ILLEGAL  */ 22 : ;
746 LLtdecr(22);
747 LL_SAFE(C_ILLEGAL);
748 # line 346 "LLgen.g"
749 {
750 #ifdef NON_CORRECTING
751                                 if (n_rules >= max_rules-2) {
752                                         rule_table = (p_gram) ralloc(
753                                                   (p_mem) rule_table,
754                                                   (unsigned)(max_rules+=RULEINCR)*sizeof(t_gram));
755                                 }
756                                 elmcnt++;
757                                 rule_table[n_rules++] =
758                                     *search(TERMINAL, "LLILLEGAL", BOTH);
759                                 if (*conflres & DEF) {
760                                         error(linecount, "%%illegal not allowed in %%default rule");
761                                 }
762 #endif
763                         }
764 LLread();
765 }
766 }
767 for (;;) {
768 goto L_7;
769 L_7 : {switch(LLcsymb) {
770 case /* ';' */ 24 : ;
771 case /* '|' */ 26 : ;
772 case /* ']' */ 28 : ;
773 break;
774 default:{int LL_9=LLnext(-12);
775 ;if (!LL_9) {
776 break;
777 }
778 else if (LL_9 & 1) goto L_7;}
779 case /*  C_IDENT  */ 2 : ;
780 case /*  C_NUMBER  */ 3 : ;
781 case /*  C_LITERAL  */ 4 : ;
782 case /*  C_ACTION  */ 7 : ;
783 case /*  C_SUBSTART  */ 20 : ;
784 case /*  C_ERRONEOUS  */ 21 : ;
785 case /* '[' */ 27 : ;
786 case /* '?' */ 29 : ;
787 case /* '*' */ 30 : ;
788 case /* '+' */ 31 : ;
789 LLsincr(4);
790 LL7_elem(
791 # line 362 "LLgen.g"
792 &elem);
793 # line 363 "LLgen.g"
794 {       if (n_rules >= max_rules-2) {
795                                         rule_table = (p_gram) ralloc(
796                                                   (p_mem) rule_table,
797                                                   (unsigned)(max_rules+=RULEINCR)*sizeof(t_gram));
798                                 }
799                                 kind = FIXED;
800                                 cnt = 0;
801                         }
802 goto L_9; /* so that the label is used for certain */
803 L_9: ;
804 switch(LLcsymb) {
805 case /*  C_NUMBER  */ 3 : ;
806 case /* '?' */ 29 : ;
807 case /* '*' */ 30 : ;
808 case /* '+' */ 31 : ;
809 LLsdecr(4);
810 LL8_repeats(
811 # line 371 "LLgen.g"
812 &kind, &cnt);
813 # line 372 "LLgen.g"
814 {       if (g_gettype(&elem) != TERM) {
815                                         rule_table[n_rules] = elem;
816                                         g_settype((&rule_table[n_rules+1]),EORULE);
817                                         mkterm(copyrule(&rule_table[n_rules],2),
818                                                0,
819                                                elem.g_lineno,
820                                                &elem);
821                                 }
822                         }
823 break;
824 case /*  C_IDENT  */ 2 : ;
825 case /*  C_LITERAL  */ 4 : ;
826 case /*  C_ACTION  */ 7 : ;
827 case /*  C_SUBSTART  */ 20 : ;
828 case /*  C_ERRONEOUS  */ 21 : ;
829 case /* ';' */ 24 : ;
830 case /* '|' */ 26 : ;
831 case /* '[' */ 27 : ;
832 case /* ']' */ 28 : ;
833 goto L_10;
834 L_10: ;
835 LLsdecr(4);
836 # line 382 "LLgen.g"
837 { if (g_gettype(&elem) == TERM) {
838                                 register p_term q = g_getterm(&elem);
839
840                                 if (! (q->t_flags & RESOLVER) &&
841                                     g_gettype(q->t_rule) != ALTERNATION &&
842                                     g_gettype(q->t_rule) != EORULE) {
843                                     while (g_gettype(q->t_rule) != EORULE) {
844                                         rule_table[n_rules++] = *q->t_rule++;
845                                         elmcnt++;
846                                         if (n_rules >= max_rules-2) {
847                                             rule_table = (p_gram) ralloc(
848                                                   (p_mem) rule_table,
849                                                   (unsigned)(max_rules+=RULEINCR)*sizeof(t_gram));
850                                         }
851                                     }
852                                     elem = *--(q->t_rule);
853                                     n_rules--;
854                                     elmcnt--;
855                                     if (q == t_list - 1) {
856                                         t_list--;
857                                         nterms--;
858                                         t_cnt++;
859                                     }
860                                     termdeleted = 1;
861                                 }
862                           }
863                         }
864 break;
865 default: if (LLskip()) goto L_9;
866 goto L_10;
867 }
868 # line 409 "LLgen.g"
869 {       if (!termdeleted && g_gettype(&elem) == TERM) {
870                                         register p_term q;
871
872                                         q = g_getterm(&elem);
873                                         r_setkind(q,kind);
874                                         r_setnum(q,cnt);
875                                         if ((q->t_flags & RESOLVER) &&
876                                             (kind == PLUS || kind == FIXED)) {
877                                                 error(linecount,
878                 "%%while not allowed in this term");
879                                         }
880                                         /*
881                                          * A persistent fixed term is the same
882                                          * as a non-persistent fixed term.
883                                          * Should we complain?
884                                         if ((q->t_flags & PERSISTENT) &&
885                                             kind == FIXED) {
886                                                 error(linecount,
887                                                         "Illegal %%persistent");
888                                         }
889                                         */
890                                 }
891                                 termdeleted = 0;
892                                 elmcnt++;
893                                 rule_table[n_rules++] = elem;
894                         }
895 continue;
896 }
897 }
898 LLsdecr(3);
899 break;
900 }
901 # line 435 "LLgen.g"
902 {       register p_term q;
903
904                                 g_settype((&rule_table[n_rules]),EORULE);
905                                 *p = 0;
906                                 n_rules -= elmcnt;
907                                 if (g_gettype(&rule_table[n_rules]) == TERM &&
908                                     elmcnt == 1) {
909                                         q = g_getterm(&rule_table[n_rules]);
910                                         if (r_getkind(q) == FIXED &&
911                                             r_getnum(q) == 0) {
912                                                 *p = q->t_rule;
913                                         }
914                                 }
915                                 if (!*p) *p = copyrule(&rule_table[n_rules],
916                                                 elmcnt+1);
917                         }
918 }
919 # line 452 "LLgen.g"
920
921
922 STATIC
923 mkterm(prod,flags,lc,result) p_gram prod; register p_gram result; {
924         /*
925          * Create a term, initialise it and return
926          * a grammar element containing it
927          */
928         register p_term         q;
929
930         if (! t_cnt) {
931                 t_cnt = 50;
932                 t_list = (p_term) alloc(50 * sizeof(t_term));
933         }
934         t_cnt--;
935         q = t_list++;
936         q->t_rule = prod;
937         q->t_contains = 0;
938         q->t_flags = flags;
939         g_settype(result,TERM);
940         g_setterm(result,q);
941         result->g_lineno = lc;
942         nterms++;
943 }
944 static
945 #if LL_ANSI_C
946 void
947 #endif
948 LL7_elem(
949 #if LL_ANSI_C
950 # line 478 "LLgen.g"
951 register p_gram pres)  
952 #else
953 # line 478 "LLgen.g"
954  pres) register p_gram pres; 
955 #endif
956 {
957 # line 479 "LLgen.g"
958         register int    t = 0;
959                 p_gram          p1;
960                 int             ln;
961                 p_gram          pe;
962 #ifdef NON_CORRECTING
963                 int             erroneous = 0;
964 #endif
965         
966 switch(LLcsymb) {
967 case /* '[' */ 27 : ;
968 LLtincr(11);
969 LLtincr(12);
970 LLsincr(1);
971 LLtincr(28);
972 LL_SAFE('[');
973 # line 487 "LLgen.g"
974 {       ln = linecount; }
975 LLread();
976 goto L_4;
977 L_4 : {switch(LLcsymb) {
978 case /*  C_IDENT  */ 2 : ;
979 case /*  C_LITERAL  */ 4 : ;
980 case /*  C_ACTION  */ 7 : ;
981 case /*  C_IF  */ 10 : ;
982 case /*  C_PERSISTENT  */ 12 : ;
983 case /*  C_AVOID  */ 17 : ;
984 case /*  C_PREFER  */ 18 : ;
985 case /*  C_DEFAULT  */ 19 : ;
986 case /*  C_SUBSTART  */ 20 : ;
987 case /*  C_ERRONEOUS  */ 21 : ;
988 case /*  C_ILLEGAL  */ 22 : ;
989 case /* '|' */ 26 : ;
990 case /* '[' */ 27 : ;
991 case /* ']' */ 28 : ;
992 LLtdecr(11);
993 break;
994 default:{int LL_10=LLnext(267);
995 ;if (!LL_10) {
996 LLtdecr(11);
997 break;
998 }
999 else if (LL_10 & 1) goto L_4;}
1000 case /*  C_WHILE  */ 11 : ;
1001 LLtdecr(11);
1002 LL_SAFE(C_WHILE);
1003 LL_NOSCANDONE(C_EXPR);
1004 # line 488 "LLgen.g"
1005 {       t |= RESOLVER; }
1006 LLread();
1007 }
1008 }
1009 goto L_5;
1010 L_5 : {switch(LLcsymb) {
1011 case /*  C_IDENT  */ 2 : ;
1012 case /*  C_LITERAL  */ 4 : ;
1013 case /*  C_ACTION  */ 7 : ;
1014 case /*  C_IF  */ 10 : ;
1015 case /*  C_AVOID  */ 17 : ;
1016 case /*  C_PREFER  */ 18 : ;
1017 case /*  C_DEFAULT  */ 19 : ;
1018 case /*  C_SUBSTART  */ 20 : ;
1019 case /*  C_ERRONEOUS  */ 21 : ;
1020 case /*  C_ILLEGAL  */ 22 : ;
1021 case /* '|' */ 26 : ;
1022 case /* '[' */ 27 : ;
1023 case /* ']' */ 28 : ;
1024 LLtdecr(12);
1025 break;
1026 default:{int LL_11=LLnext(268);
1027 ;if (!LL_11) {
1028 LLtdecr(12);
1029 break;
1030 }
1031 else if (LL_11 & 1) goto L_5;}
1032 case /*  C_PERSISTENT  */ 12 : ;
1033 LLtdecr(12);
1034 LL_SAFE(C_PERSISTENT);
1035 # line 490 "LLgen.g"
1036 {       t |= PERSISTENT; }
1037 LLread();
1038 }
1039 }
1040 LLsdecr(1);
1041 LL5_productions(
1042 # line 492 "LLgen.g"
1043 &p1);
1044 LLtdecr(28);
1045 LL_SCANDONE(']');
1046 # line 493 "LLgen.g"
1047 {
1048                                 mkterm(p1,t,ln,pres);
1049                         }
1050 LLread();
1051 break;
1052 case /*  C_IDENT  */ 2 : ;
1053 case /*  C_LITERAL  */ 4 : ;
1054 case /*  C_ERRONEOUS  */ 21 : ;
1055 LLsincr(5);
1056 goto L_6;
1057 L_6 : {switch(LLcsymb) {
1058 default:
1059 break;
1060 case /*  C_ERRONEOUS  */ 21 : ;
1061 LL_SAFE(C_ERRONEOUS);
1062 # line 497 "LLgen.g"
1063 {
1064 #ifdef NON_CORRECTING
1065                                         erroneous = 1;
1066 #endif
1067                                 }
1068 LLread();
1069 }
1070 }
1071 goto L_8; /* so that the label is used for certain */
1072 L_8: ;
1073 switch(LLcsymb) {
1074 case /*  C_IDENT  */ 2 : ;
1075 goto L_9;
1076 L_9: ;
1077 LLsdecr(5);
1078 LLtincr(6);
1079 LL_SSCANDONE(C_IDENT);
1080 # line 505 "LLgen.g"
1081 {       pe = search(UNKNOWN,lextoken.t_string,BOTH);
1082                                 *pres = *pe;
1083 #ifdef NON_CORRECTING
1084                                 if (erroneous) {
1085                                         if (g_gettype(pres) != TERMINAL){
1086                                                 warning(linecount,
1087                                                         "Erroneous only allowed on terminal");
1088                                                 erroneous = 0;
1089                                         }
1090                                         else
1091                                                 pres->g_erroneous = 1;
1092                                 }
1093 #endif
1094
1095                         }
1096 LLread();
1097 goto L_10;
1098 L_10 : {switch(LLcsymb) {
1099 case /*  C_IDENT  */ 2 : ;
1100 case /*  C_NUMBER  */ 3 : ;
1101 case /*  C_LITERAL  */ 4 : ;
1102 case /*  C_ACTION  */ 7 : ;
1103 case /*  C_SUBSTART  */ 20 : ;
1104 case /*  C_ERRONEOUS  */ 21 : ;
1105 case /* ';' */ 24 : ;
1106 case /* '|' */ 26 : ;
1107 case /* '[' */ 27 : ;
1108 case /* ']' */ 28 : ;
1109 case /* '?' */ 29 : ;
1110 case /* '*' */ 30 : ;
1111 case /* '+' */ 31 : ;
1112 LLtdecr(6);
1113 break;
1114 default:{int LL_12=LLnext(262);
1115 ;if (!LL_12) {
1116 LLtdecr(6);
1117 break;
1118 }
1119 else if (LL_12 & 1) goto L_10;}
1120 case /*  C_PARAMS  */ 6 : ;
1121 LLtdecr(6);
1122 LL_SAFE(C_PARAMS);
1123 # line 520 "LLgen.g"
1124 {       if (lextoken.t_num > 15) {
1125                                         error(linecount,"Too many parameters");
1126                                 } else  g_setnpar(pres,lextoken.t_num);
1127                                 if (g_gettype(pres) == TERMINAL) {
1128                                         error(linecount,
1129                                                 "Terminal with parameters");
1130                                 }
1131                         }
1132 LLread();
1133 }
1134 }
1135 break;
1136 default: if (LLskip()) goto L_8;
1137 goto L_9;
1138 case /*  C_LITERAL  */ 4 : ;
1139 LLsdecr(5);
1140 LL_SAFE(C_LITERAL);
1141 # line 529 "LLgen.g"
1142 {       pe = search(LITERAL,lextoken.t_string,BOTH);
1143                                 *pres = *pe;
1144 #ifdef NON_CORRECTING
1145                                 if (erroneous)
1146                                         pres->g_erroneous = 1;
1147 #endif
1148                         }
1149 LLread();
1150 break;
1151 }
1152 break;
1153 default:
1154 LLtincr(7);
1155 # line 537 "LLgen.g"
1156 {       g_settype(pres,ACTION);
1157                                 pres->g_lineno = linecount;
1158 #ifdef NON_CORRECTING
1159                                 g_setsubparse(pres, (p_start) 0);
1160 #endif
1161                         }
1162 goto L_11;
1163 L_11 : {switch(LLcsymb) {
1164 default:
1165 break;
1166 case /*  C_SUBSTART  */ 20 : ;
1167 LLtincr(23);
1168 LLtincr(24);
1169 LL_SAFE(C_SUBSTART);
1170 # line 546 "LLgen.g"
1171 {
1172 #ifdef NON_CORRECTING
1173                                 nsubstarts++;
1174 #endif
1175                         }
1176 LL_NOSCANDONE(C_IDENT);
1177 # line 553 "LLgen.g"
1178 {
1179 #ifdef NON_CORRECTING
1180                                 register p_gram temp;
1181                                 register p_start subp;
1182
1183                                 temp = search(NONTERM,lextoken.t_string,BOTH);
1184                                 subp = (p_start) alloc (sizeof(t_start));
1185
1186                                 subp->ff_nont = g_getcont(temp);
1187                                 subp->ff_name = (string) 0;
1188                                 subp->ff_next = (p_start) 0;
1189                                 g_setsubparse(pres, subp);
1190 #endif
1191                         }
1192 LLread();
1193 for (;;) {
1194 goto L_12;
1195 L_12 : {switch(LLcsymb) {
1196 case /* ';' */ 24 : ;
1197 break;
1198 default:{int LL_13=LLnext(44);
1199 ;if (!LL_13) {
1200 break;
1201 }
1202 else if (LL_13 & 1) goto L_12;}
1203 case /* ',' */ 23 : ;
1204 LL_SAFE(',');
1205 LL_NOSCANDONE(C_IDENT);
1206 # line 569 "LLgen.g"
1207 {
1208 #ifdef NON_CORRECTING
1209                                 register p_gram temp;
1210                                 register p_start ff;
1211
1212                                 temp = search(NONTERM,lextoken.t_string,BOTH);
1213
1214                                 ff = g_getsubparse(pres);
1215                                 while (ff) {
1216                                         if (ff->ff_nont == g_getcont(temp)) {
1217                                                 warning(linecount, "\"%s\" used twice in %%substart", lextoken.t_string);
1218                                                 break;
1219                                         }
1220                                         ff = ff->ff_next;
1221
1222                                 }
1223
1224                                 ff = (p_start) alloc(sizeof(t_start));
1225                                 ff->ff_nont = g_getcont(temp);
1226                                 ff->ff_name = (string) 0;
1227                                 ff->ff_next = g_getsubparse(pres);
1228                                 g_setsubparse(pres, ff);
1229 #endif
1230                         }
1231 LLread();
1232 continue;
1233 }
1234 }
1235 LLtdecr(23);
1236 break;
1237 }
1238 LLtdecr(24);
1239 LL_SSCANDONE(';');
1240 LLread();
1241 }
1242 }
1243 LLtdecr(7);
1244 LL_SCANDONE(C_ACTION);
1245 LLread();
1246 break;
1247 }
1248 }
1249 static
1250 #if LL_ANSI_C
1251 void
1252 #endif
1253 LL8_repeats(
1254 #if LL_ANSI_C
1255 # line 600 "LLgen.g"
1256 int *kind ,int *cnt)  
1257 #else
1258 # line 600 "LLgen.g"
1259  kind,cnt) int *kind; int *cnt; 
1260 #endif
1261 {
1262 # line 600 "LLgen.g"
1263         int t1 = 0; 
1264 switch(LLcsymb) {
1265 default:
1266 LL_SAFE('?');
1267 # line 602 "LLgen.g"
1268 {       *kind = OPT; }
1269 LLread();
1270 break;
1271 case /* '*' */ 30 : ;
1272 case /* '+' */ 31 : ;
1273 LLtincr(3);
1274 switch(LLcsymb) {
1275 default:
1276 LL_SAFE('*');
1277 # line 603 "LLgen.g"
1278 {       *kind = STAR; }
1279 break;
1280 case /* '+' */ 31 : ;
1281 LL_SAFE('+');
1282 # line 604 "LLgen.g"
1283 {       *kind = PLUS; }
1284 break;
1285 }
1286 LLread();
1287 goto L_7;
1288 L_7 : {switch(LLcsymb) {
1289 case /*  C_IDENT  */ 2 : ;
1290 case /*  C_LITERAL  */ 4 : ;
1291 case /*  C_ACTION  */ 7 : ;
1292 case /*  C_SUBSTART  */ 20 : ;
1293 case /*  C_ERRONEOUS  */ 21 : ;
1294 case /* ';' */ 24 : ;
1295 case /* '|' */ 26 : ;
1296 case /* '[' */ 27 : ;
1297 case /* ']' */ 28 : ;
1298 LLtdecr(3);
1299 break;
1300 default:{int LL_14=LLnext(259);
1301 ;if (!LL_14) {
1302 LLtdecr(3);
1303 break;
1304 }
1305 else if (LL_14 & 1) goto L_7;}
1306 case /*  C_NUMBER  */ 3 : ;
1307 LLtdecr(3);
1308 LL9_number(
1309 # line 606 "LLgen.g"
1310 &t1);
1311 LLread();
1312 }
1313 }
1314 # line 607 "LLgen.g"
1315 {       if (t1 == 1) {
1316                                         t1 = 0;
1317                                         if (*kind == STAR) *kind = OPT;
1318                                         if (*kind == PLUS) *kind = FIXED;
1319                                 }
1320                         }
1321 break;
1322 case /*  C_NUMBER  */ 3 : ;
1323 LL9_number(
1324 # line 613 "LLgen.g"
1325 &t1);
1326 LLread();
1327 break;
1328 }
1329 # line 614 "LLgen.g"
1330 {       *cnt = t1; }
1331 }
1332 static
1333 #if LL_ANSI_C
1334 void
1335 #endif
1336 LL9_number(
1337 #if LL_ANSI_C
1338 # line 617 "LLgen.g"
1339 int *t)  
1340 #else
1341 # line 617 "LLgen.g"
1342  t) int *t; 
1343 #endif
1344 {
1345 LL_SAFE(C_NUMBER);
1346 # line 619 "LLgen.g"
1347 {       *t = lextoken.t_num;
1348                                 if (*t <= 0 || *t >= 8192) {
1349                                         error(linecount,"Illegal number");
1350                                 }
1351                         }
1352 }
1353 static
1354 #if LL_ANSI_C
1355 void
1356 #endif
1357 LL4_firsts(
1358 #if LL_ANSI_C
1359 void
1360 #endif
1361 ) {
1362 # line 626 "LLgen.g"
1363         register string p; 
1364 LLtincr(23);
1365 LLtincr(2);
1366 LLtincr(24);
1367 LL_SAFE(C_FIRST);
1368 LL_NOSCANDONE(C_IDENT);
1369 # line 628 "LLgen.g"
1370 {       p = store(lextoken.t_string); }
1371 LLtdecr(23);
1372 LL_NOSCANDONE(',');
1373 LLtdecr(2);
1374 LL_NOSCANDONE(C_IDENT);
1375 LLtdecr(24);
1376 LL_NOSCANDONE(';');
1377 # line 630 "LLgen.g"
1378 {       /*
1379                                  * Store this %first in the list belonging
1380                                  * to this input file
1381                                  */
1382                                 p_gram temp;
1383                                 register p_first ff;
1384
1385                                 temp = search(NONTERM,lextoken.t_string,BOTH);
1386                                 ff = (p_first) alloc(sizeof(t_first));
1387                                 ff->ff_nont = g_getcont(temp);
1388                                 ff->ff_name = p;
1389                                 ff->ff_next = pfile->f_firsts;
1390                                 pfile->f_firsts = ff;
1391                         }
1392 }
1393
1394 # line 645 "LLgen.g"
1395
1396
1397 STATIC p_gram
1398 copyrule(p,length) register p_gram p; {
1399         /*
1400          * Returns a pointer to a grammar rule that was created in
1401          * p. The space pointed to by p can now be reused
1402          */
1403         register p_gram t;
1404         p_gram rule;
1405
1406         t = (p_gram) alloc((unsigned) length * sizeof(t_gram));
1407         rule = t;
1408         while (length--) {
1409                 *t++ = *p++;
1410         }
1411         return rule;
1412 }
1413