2 * Copyright (c) 1989 The Regents of the University of California.
5 * This code is derived from software contributed to Berkeley by
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * $FreeBSD: src/usr.bin/yacc/reader.c,v 1.8.2.1 2001/10/05 03:00:44 obrien Exp $
37 * $DragonFly: src/usr.bin/yacc/reader.c,v 1.4 2004/04/07 20:43:24 cpressey Exp $
39 * @(#)reader.c 5.7 (Berkeley) 1/20/91
46 /* The line size must be a positive integer. One hundred was chosen */
47 /* because few lines in Yacc input grammars exceed 100 characters. */
48 /* Note that if a line exceeds LINESIZE characters, the line buffer */
49 /* will be expanded to accomodate it. */
59 char saw_eof, unionized;
77 static const char line_format[] = "#line %d \"%s\"\n";
79 static void add_symbol(void);
80 static void advance_to_start(void);
81 static void cachec(int);
82 static void check_symbols(void);
83 static void copy_action(void);
84 static void copy_ident(void);
85 static void copy_text(void);
86 static void copy_union(void);
87 static void declare_start(void);
88 static void declare_tokens(int);
89 static void declare_types(void);
90 static char *dup_line(void);
91 static void end_rule(void);
92 static void expand_items(void);
93 static void expand_rules(void);
94 static void free_tags(void);
95 static void get_line(void);
96 static bucket *get_literal(void);
97 static bucket *get_name(void);
98 static int get_number(void);
99 static char *get_tag(void);
100 static int hexval(int);
101 static void initialize_grammar(void);
102 static void insert_empty_rule(void);
103 static int is_reserved(char *);
104 static int keyword(void);
105 static int mark_symbol(void);
106 static int nextc(void);
107 static void pack_grammar(void);
108 static void pack_names(void);
109 static void pack_symbols(void);
110 static void print_grammar(void);
111 static void read_declarations(void);
112 static void read_grammar(void);
113 static void skip_comment(void);
114 static void start_rule(bucket *, int);
120 if (cinc >= cache_size)
123 cache = REALLOC(cache, cache_size);
124 if (cache == 0) no_space();
134 FILE *f = input_file;
138 if (saw_eof || (c = getc(f)) == EOF)
140 if (line) { FREE(line); line = 0; }
146 if (line == 0 || linesize != (LINESIZE + 1))
148 if (line) FREE(line);
149 linesize = LINESIZE + 1;
150 line = MALLOC(linesize);
151 if (line == 0) no_space();
159 if (c == '\n') { cptr = line; return; }
162 linesize += LINESIZE;
163 line = REALLOC(line, linesize);
164 if (line == 0) no_space();
183 if (line == 0) return (0);
185 while (*s != '\n') ++s;
186 p = MALLOC(s - line + 1);
187 if (p == 0) no_space();
191 while ((*t++ = *s++) != '\n') continue;
201 int st_lineno = lineno;
202 char *st_line = dup_line();
203 char *st_cptr = st_line + (cptr - line);
208 if (*s == '*' && s[1] == '/')
218 unterminated_comment(st_lineno, st_line, st_cptr);
246 if (line == 0) return (EOF);
272 else if (s[1] == '/')
275 if (line == 0) return (EOF);
303 if (isupper(c)) c = tolower(c);
306 else if (isdigit(c) || c == '_' || c == '.' || c == '$')
314 if (strcmp(cache, "token") == 0 || strcmp(cache, "term") == 0)
316 if (strcmp(cache, "type") == 0)
318 if (strcmp(cache, "left") == 0)
320 if (strcmp(cache, "right") == 0)
322 if (strcmp(cache, "nonassoc") == 0 || strcmp(cache, "binary") == 0)
324 if (strcmp(cache, "start") == 0)
326 if (strcmp(cache, "union") == 0)
328 if (strcmp(cache, "ident") == 0)
330 if (strcmp(cache, "expect") == 0)
338 if (c == '%' || c == '\\')
349 syntax_error(lineno, line, t_cptr);
359 FILE *f = output_file;
362 if (c == EOF) unexpected_EOF();
363 if (c != '"') syntax_error(lineno, line, cptr);
365 fprintf(f, "#ident \"");
391 int need_newline = 0;
392 int t_lineno = lineno;
393 char *t_line = dup_line();
394 char *t_cptr = t_line + (cptr - line - 2);
400 unterminated_text(t_lineno, t_line, t_cptr);
402 if (!lflag) fprintf(f, line_format, lineno, input_file_name);
414 unterminated_text(t_lineno, t_line, t_cptr);
419 int s_lineno = lineno;
420 char *s_line = dup_line();
421 char *s_cptr = s_line + (cptr - line - 1);
436 unterminated_string(s_lineno, s_line, s_cptr);
445 unterminated_string(s_lineno, s_line, s_cptr);
458 while ((c = *++cptr) != '\n')
460 if (c == '*' && cptr[1] == '/')
470 int c_lineno = lineno;
471 char *c_line = dup_line();
472 char *c_cptr = c_line + (cptr - line - 1);
480 if (c == '*' && *cptr == '/')
491 unterminated_comment(c_lineno, c_line, c_cptr);
502 if (need_newline) putc('\n', f);
523 int u_lineno = lineno;
524 char *u_line = dup_line();
525 char *u_cptr = u_line + (cptr - line - 6);
527 if (unionized) over_unionized(cptr - 6);
531 fprintf(text_file, line_format, lineno, input_file_name);
533 fprintf(text_file, "typedef union");
534 if (dflag) fprintf(union_file, "typedef union");
540 if (dflag) putc(c, union_file);
546 if (line == 0) unterminated_union(u_lineno, u_line, u_cptr);
556 fprintf(text_file, " YYSTYPE;\n");
565 int s_lineno = lineno;
566 char *s_line = dup_line();
567 char *s_cptr = s_line + (cptr - line - 1);
574 if (dflag) putc(c, union_file);
581 unterminated_string(s_lineno, s_line, s_cptr);
586 if (dflag) putc(c, union_file);
591 unterminated_string(s_lineno, s_line, s_cptr);
601 putc('*', text_file);
602 if (dflag) putc('*', union_file);
603 while ((c = *++cptr) != '\n')
605 if (c == '*' && cptr[1] == '/')
607 fprintf(text_file, "* ");
608 if (dflag) fprintf(union_file, "* ");
613 if (dflag) putc(c, union_file);
616 fprintf(text_file, "*/\n");
617 if (dflag) fprintf(union_file, "*/\n");
622 int c_lineno = lineno;
623 char *c_line = dup_line();
624 char *c_cptr = c_line + (cptr - line - 1);
626 putc('*', text_file);
627 if (dflag) putc('*', union_file);
633 if (dflag) putc(c, union_file);
634 if (c == '*' && *cptr == '/')
636 putc('/', text_file);
637 if (dflag) putc('/', union_file);
646 unterminated_comment(c_lineno, c_line, c_cptr);
661 if (c >= '0' && c <= '9')
663 if (c >= 'A' && c <= 'F')
664 return (c - 'A' + 10);
665 if (c >= 'a' && c <= 'f')
666 return (c - 'a' + 10);
679 int s_lineno = lineno;
680 char *s_line = dup_line();
681 char *s_cptr = s_line + (cptr - line);
688 if (c == quote) break;
689 if (c == '\n') unterminated_string(s_lineno, s_line, s_cptr);
692 char *c_cptr = cptr - 1;
699 if (line == 0) unterminated_string(s_lineno, s_line, s_cptr);
702 case '0': case '1': case '2': case '3':
703 case '4': case '5': case '6': case '7':
708 n = (n << 3) + (c - '0');
712 n = (n << 3) + (c - '0');
716 if (n > MAXCHAR) illegal_character(c_cptr);
723 if (n < 0 || n >= 16)
724 illegal_character(c_cptr);
729 if (i < 0 || i >= 16) break;
732 if (n > MAXCHAR) illegal_character(c_cptr);
737 case 'a': c = 7; break;
738 case 'b': c = '\b'; break;
739 case 'f': c = '\f'; break;
740 case 'n': c = '\n'; break;
741 case 'r': c = '\r'; break;
742 case 't': c = '\t'; break;
743 case 'v': c = '\v'; break;
752 if (s == 0) no_space();
754 for (i = 0; i < n; ++i)
763 for (i = 0; i < n; ++i)
765 c = ((unsigned char *)s)[i];
766 if (c == '\\' || c == cache[0])
778 case 7: cachec('a'); break;
779 case '\b': cachec('b'); break;
780 case '\f': cachec('f'); break;
781 case '\n': cachec('n'); break;
782 case '\r': cachec('r'); break;
783 case '\t': cachec('t'); break;
784 case '\v': cachec('v'); break;
786 cachec(((c >> 6) & 7) + '0');
787 cachec(((c >> 3) & 7) + '0');
788 cachec((c & 7) + '0');
802 if (n == 1 && bp->value == UNDEFINED)
803 bp->value = *(unsigned char *)s;
811 is_reserved(char *name)
815 if (strcmp(name, ".") == 0 ||
816 strcmp(name, "$accept") == 0 ||
817 strcmp(name, "$end") == 0)
820 if (name[0] == '$' && name[1] == '$' && isdigit(name[2]))
823 while (isdigit(*s)) ++s;
824 if (*s == NUL) return (1);
837 for (c = *cptr; IS_IDENT(c); c = *++cptr)
841 if (is_reserved(cache)) used_reserved(cache);
843 return (lookup(cache));
854 for (c = *cptr; isdigit(c); c = *++cptr)
855 n = 10*n + (c - '0');
867 int t_lineno = lineno;
868 char *t_line = dup_line();
869 char *t_cptr = t_line + (cptr - line);
873 if (c == EOF) unexpected_EOF();
874 if (!isalpha(c) && c != '_' && c != '$')
875 illegal_tag(t_lineno, t_line, t_cptr);
878 do { cachec(c); c = *++cptr; } while (IS_IDENT(c));
882 if (c == EOF) unexpected_EOF();
884 illegal_tag(t_lineno, t_line, t_cptr);
887 for (i = 0; i < ntags; ++i)
889 if (strcmp(cache, tag_table[i]) == 0)
890 return (tag_table[i]);
896 tag_table = (char **)
897 (tag_table ? REALLOC(tag_table, tagmax*sizeof(char *))
898 : MALLOC(tagmax*sizeof(char *)));
899 if (tag_table == 0) no_space();
903 if (s == 0) no_space();
905 tag_table[ntags] = s;
913 declare_tokens(int assoc)
920 if (assoc != TOKEN) ++prec;
923 if (c == EOF) unexpected_EOF();
928 if (c == EOF) unexpected_EOF();
933 if (isalpha(c) || c == '_' || c == '.' || c == '$')
935 else if (c == '\'' || c == '"')
940 if (bp == goal) tokenized_start(bp->name);
945 if (bp->tag && tag != bp->tag)
946 retyped_warning(bp->name);
952 if (bp->prec && prec != bp->prec)
953 reprec_warning(bp->name);
959 if (c == EOF) unexpected_EOF();
963 value = get_number();
964 if (bp->value != UNDEFINED && value != bp->value)
965 revalued_warning(bp->name);
968 if (c == EOF) unexpected_EOF();
975 * %expect requires special handling
976 * as it really isn't part of the yacc
977 * grammar only a flag for yacc proper.
980 declare_expect(int assoc)
984 if (assoc != EXPECT) ++prec;
987 * Stay away from nextc - doesn't
988 * detect EOL and will read to EOF.
991 if (c == EOF) unexpected_EOF();
997 SRexpect = get_number();
1001 * Looking for number before EOL.
1002 * Spaces, tabs, and numbers are ok,
1003 * words, punc., etc. are syntax errors.
1005 else if (c == '\n' || isalpha(c) || !isspace(c))
1007 syntax_error(lineno, line, cptr);
1012 if (c == EOF) unexpected_EOF();
1026 if (c == EOF) unexpected_EOF();
1027 if (c != '<') syntax_error(lineno, line, cptr);
1033 if (isalpha(c) || c == '_' || c == '.' || c == '$')
1035 else if (c == '\'' || c == '"')
1040 if (bp->tag && tag != bp->tag)
1041 retyped_warning(bp->name);
1054 if (c == EOF) unexpected_EOF();
1055 if (!isalpha(c) && c != '_' && c != '.' && c != '$')
1056 syntax_error(lineno, line, cptr);
1058 if (bp->class == TERM)
1059 terminal_start(bp->name);
1060 if (goal && goal != bp)
1061 restarted_warning();
1067 read_declarations(void)
1072 cache = MALLOC(cache_size);
1073 if (cache == 0) no_space();
1078 if (c == EOF) unexpected_EOF();
1079 if (c != '%') syntax_error(lineno, line, cptr);
1080 switch (k = keyword())
1121 initialize_grammar(void)
1125 pitem = (bucket **) MALLOC(maxitems*sizeof(bucket *));
1126 if (pitem == 0) no_space();
1134 plhs = (bucket **) MALLOC(maxrules*sizeof(bucket *));
1135 if (plhs == 0) no_space();
1139 rprec = (short *) MALLOC(maxrules*sizeof(short));
1140 if (rprec == 0) no_space();
1144 rassoc = (char *) MALLOC(maxrules*sizeof(char));
1145 if (rassoc == 0) no_space();
1156 pitem = (bucket **) REALLOC(pitem, maxitems*sizeof(bucket *));
1157 if (pitem == 0) no_space();
1165 plhs = (bucket **) REALLOC(plhs, maxrules*sizeof(bucket *));
1166 if (plhs == 0) no_space();
1167 rprec = (short *) REALLOC(rprec, maxrules*sizeof(short));
1168 if (rprec == 0) no_space();
1169 rassoc = (char *) REALLOC(rassoc, maxrules*sizeof(char));
1170 if (rassoc == 0) no_space();
1175 advance_to_start(void)
1185 if (c != '%') break;
1201 syntax_error(lineno, line, s_cptr);
1206 if (!isalpha(c) && c != '_' && c != '.' && c != '_')
1207 syntax_error(lineno, line, cptr);
1211 if (bp->class == TERM)
1212 terminal_start(bp->name);
1218 if (c == EOF) unexpected_EOF();
1219 if (c != ':') syntax_error(lineno, line, cptr);
1220 start_rule(bp, s_lineno);
1226 start_rule(bucket *bp, int s_lineno)
1228 if (bp->class == TERM)
1229 terminal_lhs(s_lineno);
1230 bp->class = NONTERM;
1231 if (nrules >= maxrules)
1234 rprec[nrules] = UNDEFINED;
1235 rassoc[nrules] = TOKEN;
1244 if (!last_was_action && plhs[nrules]->tag)
1246 for (i = nitems - 1; pitem[i]; --i) continue;
1247 if (pitem[i+1] == 0 || pitem[i+1]->tag != plhs[nrules]->tag)
1248 default_action_warning();
1251 last_was_action = 0;
1252 if (nitems >= maxitems) expand_items();
1260 insert_empty_rule(void)
1265 sprintf(cache, "$$%d", ++gensym);
1266 bp = make_bucket(cache);
1267 last_symbol->next = bp;
1269 bp->tag = plhs[nrules]->tag;
1270 bp->class = NONTERM;
1272 if ((nitems += 2) > maxitems)
1274 bpp = pitem + nitems - 1;
1276 while ((bpp[0] = bpp[-1])) --bpp;
1278 if (++nrules >= maxrules)
1280 plhs[nrules] = plhs[nrules-1];
1281 plhs[nrules-1] = bp;
1282 rprec[nrules] = rprec[nrules-1];
1283 rprec[nrules-1] = 0;
1284 rassoc[nrules] = rassoc[nrules-1];
1285 rassoc[nrules-1] = TOKEN;
1294 int s_lineno = lineno;
1297 if (c == '\'' || c == '"')
1306 start_rule(bp, s_lineno);
1311 if (last_was_action)
1312 insert_empty_rule();
1313 last_was_action = 0;
1315 if (++nitems > maxitems)
1317 pitem[nitems-1] = bp;
1329 FILE *f = action_file;
1330 int a_lineno = lineno;
1331 char *a_line = dup_line();
1332 char *a_cptr = a_line + (cptr - line);
1334 if (last_was_action)
1335 insert_empty_rule();
1336 last_was_action = 1;
1338 fprintf(f, "case %d:\n", nrules - 2);
1340 fprintf(f, line_format, lineno, input_file_name);
1341 if (*cptr == '=') ++cptr;
1344 for (i = nitems - 1; pitem[i]; --i) ++n;
1353 int d_lineno = lineno;
1354 char *d_line = dup_line();
1355 char *d_cptr = d_line + (cptr - line);
1362 fprintf(f, "yyval.%s", tag);
1367 else if (isdigit(c))
1370 if (i > n) dollar_warning(d_lineno, i);
1371 fprintf(f, "yyvsp[%d].%s", i - n, tag);
1375 else if (c == '-' && isdigit(cptr[1]))
1378 i = -get_number() - n;
1379 fprintf(f, "yyvsp[%d].%s", i, tag);
1384 dollar_error(d_lineno, d_line, d_cptr);
1386 else if (cptr[1] == '$')
1390 tag = plhs[nrules]->tag;
1391 if (tag == 0) untyped_lhs();
1392 fprintf(f, "yyval.%s", tag);
1395 fprintf(f, "yyval");
1399 else if (isdigit(cptr[1]))
1405 if (i <= 0 || i > n)
1407 tag = pitem[nitems + i - n - 1]->tag;
1408 if (tag == 0) untyped_rhs(i, pitem[nitems + i - n - 1]->name);
1409 fprintf(f, "yyvsp[%d].%s", i - n, tag);
1414 dollar_warning(lineno, i);
1415 fprintf(f, "yyvsp[%d]", i - n);
1419 else if (cptr[1] == '-')
1425 fprintf(f, "yyvsp[%d]", -i - n);
1429 if (isalpha(c) || c == '_' || c == '$')
1435 } while (isalnum(c) || c == '_' || c == '$');
1445 if (line) goto loop;
1446 unterminated_action(a_lineno, a_line, a_cptr);
1449 if (depth > 0) goto loop;
1450 fprintf(f, "\nbreak;\n");
1458 if (--depth > 0) goto loop;
1459 fprintf(f, "\nbreak;\n");
1465 int s_lineno = lineno;
1466 char *s_line = dup_line();
1467 char *s_cptr = s_line + (cptr - line - 1);
1480 unterminated_string(s_lineno, s_line, s_cptr);
1489 unterminated_string(s_lineno, s_line, s_cptr);
1500 while ((c = *++cptr) != '\n')
1502 if (c == '*' && cptr[1] == '/')
1512 int c_lineno = lineno;
1513 char *c_line = dup_line();
1514 char *c_cptr = c_line + (cptr - line - 1);
1522 if (c == '*' && *cptr == '/')
1533 unterminated_comment(c_lineno, c_line, c_cptr);
1552 if (c == '%' || c == '\\')
1560 else if ((c == 'p' || c == 'P') &&
1561 ((c = cptr[2]) == 'r' || c == 'R') &&
1562 ((c = cptr[3]) == 'e' || c == 'E') &&
1563 ((c = cptr[4]) == 'c' || c == 'C') &&
1564 ((c = cptr[5], !IS_IDENT(c))))
1567 syntax_error(lineno, line, cptr);
1570 if (isalpha(c) || c == '_' || c == '.' || c == '$')
1572 else if (c == '\'' || c == '"')
1576 syntax_error(lineno, line, cptr);
1580 if (rprec[nrules] != UNDEFINED && bp->prec != rprec[nrules])
1583 rprec[nrules] = bp->prec;
1584 rassoc[nrules] = bp->assoc;
1594 initialize_grammar();
1600 if (c == EOF) break;
1601 if (isalpha(c) || c == '_' || c == '.' || c == '$' || c == '\'' ||
1604 else if (c == '{' || c == '=')
1609 start_rule(plhs[nrules-1], 0);
1614 if (mark_symbol()) break;
1617 syntax_error(lineno, line, cptr);
1628 if (tag_table == 0) return;
1630 for (i = 0; i < ntags; ++i)
1632 assert(tag_table[i]);
1645 name_pool_size = 13; /* 13 == sizeof("$end") + sizeof("$accept") */
1646 for (bp = first_symbol; bp; bp = bp->next)
1647 name_pool_size += strlen(bp->name) + 1;
1648 name_pool = MALLOC(name_pool_size);
1649 if (name_pool == 0) no_space();
1651 strcpy(name_pool, "$accept");
1652 strcpy(name_pool+8, "$end");
1654 for (bp = first_symbol; bp; bp = bp->next)
1658 while ((*t++ = *s++)) continue;
1670 if (goal->class == UNKNOWN)
1671 undefined_goal(goal->name);
1673 for (bp = first_symbol; bp; bp = bp->next)
1675 if (bp->class == UNKNOWN)
1677 undefined_symbol_warning(bp->name);
1693 for (bp = first_symbol; bp; bp = bp->next)
1696 if (bp->class == TERM) ++ntokens;
1698 start_symbol = ntokens;
1699 nvars = nsyms - ntokens;
1701 symbol_name = (char **) MALLOC(nsyms*sizeof(char *));
1702 if (symbol_name == 0) no_space();
1703 symbol_value = (short *) MALLOC(nsyms*sizeof(short));
1704 if (symbol_value == 0) no_space();
1705 symbol_prec = (short *) MALLOC(nsyms*sizeof(short));
1706 if (symbol_prec == 0) no_space();
1707 symbol_assoc = MALLOC(nsyms);
1708 if (symbol_assoc == 0) no_space();
1710 v = (bucket **) MALLOC(nsyms*sizeof(bucket *));
1711 if (v == 0) no_space();
1714 v[start_symbol] = 0;
1717 j = start_symbol + 1;
1718 for (bp = first_symbol; bp; bp = bp->next)
1720 if (bp->class == TERM)
1725 assert(i == ntokens && j == nsyms);
1727 for (i = 1; i < ntokens; ++i)
1730 goal->index = start_symbol + 1;
1731 k = start_symbol + 2;
1741 for (i = start_symbol + 1; i < nsyms; ++i)
1751 for (i = 1; i < ntokens; ++i)
1756 for (j = k++; j > 0 && symbol_value[j-1] > n; --j)
1757 symbol_value[j] = symbol_value[j-1];
1758 symbol_value[j] = n;
1762 if (v[1]->value == UNDEFINED)
1767 for (i = 2; i < ntokens; ++i)
1769 if (v[i]->value == UNDEFINED)
1771 while (j < k && n == symbol_value[j])
1773 while (++j < k && n == symbol_value[j]) continue;
1781 symbol_name[0] = name_pool + 8;
1782 symbol_value[0] = 0;
1784 symbol_assoc[0] = TOKEN;
1785 for (i = 1; i < ntokens; ++i)
1787 symbol_name[i] = v[i]->name;
1788 symbol_value[i] = v[i]->value;
1789 symbol_prec[i] = v[i]->prec;
1790 symbol_assoc[i] = v[i]->assoc;
1792 symbol_name[start_symbol] = name_pool;
1793 symbol_value[start_symbol] = -1;
1794 symbol_prec[start_symbol] = 0;
1795 symbol_assoc[start_symbol] = TOKEN;
1796 for (++i; i < nsyms; ++i)
1799 symbol_name[k] = v[i]->name;
1800 symbol_value[k] = v[i]->value;
1801 symbol_prec[k] = v[i]->prec;
1802 symbol_assoc[k] = v[i]->assoc;
1815 ritem = (short *) MALLOC(nitems*sizeof(short));
1816 if (ritem == 0) no_space();
1817 rlhs = (short *) MALLOC(nrules*sizeof(short));
1818 if (rlhs == 0) no_space();
1819 rrhs = (short *) MALLOC((nrules+1)*sizeof(short));
1820 if (rrhs == 0) no_space();
1821 rprec = (short *) REALLOC(rprec, nrules*sizeof(short));
1822 if (rprec == 0) no_space();
1823 rassoc = REALLOC(rassoc, nrules);
1824 if (rassoc == 0) no_space();
1827 ritem[1] = goal->index;
1832 rlhs[2] = start_symbol;
1838 for (i = 3; i < nrules; ++i)
1840 rlhs[i] = plhs[i]->index;
1846 ritem[j] = pitem[j]->index;
1847 if (pitem[j]->class == TERM)
1849 prec = pitem[j]->prec;
1850 assoc = pitem[j]->assoc;
1856 if (rprec[i] == UNDEFINED)
1874 FILE *f = verbose_file;
1879 for (i = 2; i < nrules; ++i)
1881 if (rlhs[i] != rlhs[i-1])
1883 if (i != 2) fprintf(f, "\n");
1884 fprintf(f, "%4d %s :", i - 2, symbol_name[rlhs[i]]);
1885 spacing = strlen(symbol_name[rlhs[i]]) + 1;
1889 fprintf(f, "%4d ", i - 2);
1891 while (--j >= 0) putc(' ', f);
1895 while (ritem[k] >= 0)
1897 fprintf(f, " %s", symbol_name[ritem[k]]);
1909 write_section(banner);
1910 create_symbol_table();
1911 read_declarations();
1913 free_symbol_table();