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
39 static char sccsid[] = "@(#)reader.c 5.7 (Berkeley) 1/20/91";
43 #include <sys/cdefs.h>
44 __FBSDID("$FreeBSD$");
51 /* The line size must be a positive integer. One hundred was chosen */
52 /* because few lines in Yacc input grammars exceed 100 characters. */
53 /* Note that if a line exceeds LINESIZE characters, the line buffer */
54 /* will be expanded to accomodate it. */
64 char saw_eof, unionized;
82 static const char line_format[] = "#line %d \"%s\"\n";
84 static void add_symbol(void);
85 static void advance_to_start(void);
86 static void cachec(int);
87 static void check_symbols(void);
88 static void copy_action(void);
89 static void copy_ident(void);
90 static void copy_text(void);
91 static void copy_union(void);
92 static void declare_expect(int);
93 static void declare_start(void);
94 static void declare_tokens(int);
95 static void declare_types(void);
96 static char *dup_line(void);
97 static void end_rule(void);
98 static void expand_items(void);
99 static void expand_rules(void);
100 static void free_tags(void);
101 static void get_line(void);
102 static bucket *get_literal(void);
103 static bucket *get_name(void);
104 static int get_number(void);
105 static char *get_tag(void);
106 static int hexval(int);
107 static void initialize_grammar(void);
108 static void insert_empty_rule(void);
109 static int is_reserved(char *);
110 static int keyword(void);
111 static int mark_symbol(void);
112 static int nextc(void);
113 static void pack_grammar(void);
114 static void pack_names(void);
115 static void pack_symbols(void);
116 static void print_grammar(void);
117 static void read_declarations(void);
118 static void read_grammar(void);
119 static void skip_comment(void);
120 static void start_rule(bucket *, int);
127 if (cinc >= cache_size)
130 cache = REALLOC(cache, cache_size);
131 if (cache == 0) no_space();
141 FILE *f = input_file;
145 if (saw_eof || (c = getc(f)) == EOF)
147 if (line) { FREE(line); line = 0; }
153 if (line == 0 || linesize != (LINESIZE + 1))
155 if (line) FREE(line);
156 linesize = LINESIZE + 1;
157 line = MALLOC(linesize);
158 if (line == 0) no_space();
166 if (c == '\n') { cptr = line; return; }
169 linesize += LINESIZE;
170 line = REALLOC(line, linesize);
171 if (line == 0) no_space();
190 if (line == 0) return (0);
192 while (*s != '\n') ++s;
193 p = MALLOC(s - line + 1);
194 if (p == 0) no_space();
198 while ((*t++ = *s++) != '\n') continue;
208 int st_lineno = lineno;
209 char *st_line = dup_line();
210 char *st_cptr = st_line + (cptr - line);
215 if (*s == '*' && s[1] == '/')
225 unterminated_comment(st_lineno, st_line, st_cptr);
253 if (line == 0) return (EOF);
279 else if (s[1] == '/')
282 if (line == 0) return (EOF);
310 if (isupper(c)) c = tolower(c);
313 else if (isdigit(c) || c == '_' || c == '.' || c == '$')
321 if (strcmp(cache, "token") == 0 || strcmp(cache, "term") == 0)
323 if (strcmp(cache, "type") == 0)
325 if (strcmp(cache, "left") == 0)
327 if (strcmp(cache, "right") == 0)
329 if (strcmp(cache, "nonassoc") == 0 || strcmp(cache, "binary") == 0)
331 if (strcmp(cache, "start") == 0)
333 if (strcmp(cache, "union") == 0)
335 if (strcmp(cache, "ident") == 0)
337 if (strcmp(cache, "expect") == 0)
345 if (c == '%' || c == '\\')
356 syntax_error(lineno, line, t_cptr);
366 FILE *f = output_file;
369 if (c == EOF) unexpected_EOF();
370 if (c != '"') syntax_error(lineno, line, cptr);
372 fprintf(f, "#ident \"");
398 int need_newline = 0;
399 int t_lineno = lineno;
400 char *t_line = dup_line();
401 char *t_cptr = t_line + (cptr - line - 2);
407 unterminated_text(t_lineno, t_line, t_cptr);
409 if (!lflag) fprintf(f, line_format, lineno, input_file_name);
421 unterminated_text(t_lineno, t_line, t_cptr);
426 int s_lineno = lineno;
427 char *s_line = dup_line();
428 char *s_cptr = s_line + (cptr - line - 1);
443 unterminated_string(s_lineno, s_line, s_cptr);
452 unterminated_string(s_lineno, s_line, s_cptr);
465 while ((c = *++cptr) != '\n')
467 if (c == '*' && cptr[1] == '/')
477 int c_lineno = lineno;
478 char *c_line = dup_line();
479 char *c_cptr = c_line + (cptr - line - 1);
487 if (c == '*' && *cptr == '/')
498 unterminated_comment(c_lineno, c_line, c_cptr);
509 if (need_newline) putc('\n', f);
530 int u_lineno = lineno;
531 char *u_line = dup_line();
532 char *u_cptr = u_line + (cptr - line - 6);
534 if (unionized) over_unionized(cptr - 6);
538 fprintf(text_file, line_format, lineno, input_file_name);
540 fprintf(text_file, "typedef union");
541 if (dflag) fprintf(union_file, "typedef union");
547 if (dflag) putc(c, union_file);
553 if (line == 0) unterminated_union(u_lineno, u_line, u_cptr);
563 fprintf(text_file, " YYSTYPE;\n");
572 int s_lineno = lineno;
573 char *s_line = dup_line();
574 char *s_cptr = s_line + (cptr - line - 1);
581 if (dflag) putc(c, union_file);
588 unterminated_string(s_lineno, s_line, s_cptr);
593 if (dflag) putc(c, union_file);
598 unterminated_string(s_lineno, s_line, s_cptr);
608 putc('*', text_file);
609 if (dflag) putc('*', union_file);
610 while ((c = *++cptr) != '\n')
612 if (c == '*' && cptr[1] == '/')
614 fprintf(text_file, "* ");
615 if (dflag) fprintf(union_file, "* ");
620 if (dflag) putc(c, union_file);
623 fprintf(text_file, "*/\n");
624 if (dflag) fprintf(union_file, "*/\n");
629 int c_lineno = lineno;
630 char *c_line = dup_line();
631 char *c_cptr = c_line + (cptr - line - 1);
633 putc('*', text_file);
634 if (dflag) putc('*', union_file);
640 if (dflag) putc(c, union_file);
641 if (c == '*' && *cptr == '/')
643 putc('/', text_file);
644 if (dflag) putc('/', union_file);
653 unterminated_comment(c_lineno, c_line, c_cptr);
669 if (c >= '0' && c <= '9')
671 if (c >= 'A' && c <= 'F')
672 return (c - 'A' + 10);
673 if (c >= 'a' && c <= 'f')
674 return (c - 'a' + 10);
687 int s_lineno = lineno;
688 char *s_line = dup_line();
689 char *s_cptr = s_line + (cptr - line);
696 if (c == quote) break;
697 if (c == '\n') unterminated_string(s_lineno, s_line, s_cptr);
700 char *c_cptr = cptr - 1;
707 if (line == 0) unterminated_string(s_lineno, s_line, s_cptr);
710 case '0': case '1': case '2': case '3':
711 case '4': case '5': case '6': case '7':
716 n = (n << 3) + (c - '0');
720 n = (n << 3) + (c - '0');
724 if (n > UCHAR_MAX) illegal_character(c_cptr);
731 if (n < 0 || n >= 16)
732 illegal_character(c_cptr);
737 if (i < 0 || i >= 16) break;
740 if (n > UCHAR_MAX) illegal_character(c_cptr);
745 case 'a': c = 7; break;
746 case 'b': c = '\b'; break;
747 case 'f': c = '\f'; break;
748 case 'n': c = '\n'; break;
749 case 'r': c = '\r'; break;
750 case 't': c = '\t'; break;
751 case 'v': c = '\v'; break;
760 if (s == 0) no_space();
762 for (i = 0; i < n; ++i)
771 for (i = 0; i < n; ++i)
773 c = ((unsigned char *)s)[i];
774 if (c == '\\' || c == cache[0])
786 case 7: cachec('a'); break;
787 case '\b': cachec('b'); break;
788 case '\f': cachec('f'); break;
789 case '\n': cachec('n'); break;
790 case '\r': cachec('r'); break;
791 case '\t': cachec('t'); break;
792 case '\v': cachec('v'); break;
794 cachec(((c >> 6) & 7) + '0');
795 cachec(((c >> 3) & 7) + '0');
796 cachec((c & 7) + '0');
810 if (n == 1 && bp->value == UNDEFINED)
811 bp->value = *(unsigned char *)s;
824 if (strcmp(name, ".") == 0 ||
825 strcmp(name, "$accept") == 0 ||
826 strcmp(name, "$end") == 0)
829 if (name[0] == '$' && name[1] == '$' && isdigit(name[2]))
832 while (isdigit(*s)) ++s;
833 if (*s == NUL) return (1);
846 for (c = *cptr; IS_IDENT(c); c = *++cptr)
850 if (is_reserved(cache)) used_reserved(cache);
852 return (lookup(cache));
863 for (c = *cptr; isdigit(c); c = *++cptr)
864 n = 10*n + (c - '0');
876 int t_lineno = lineno;
877 char *t_line = dup_line();
878 char *t_cptr = t_line + (cptr - line);
882 if (c == EOF) unexpected_EOF();
883 if (!isalpha(c) && c != '_' && c != '$')
884 illegal_tag(t_lineno, t_line, t_cptr);
887 do { cachec(c); c = *++cptr; } while (IS_IDENT(c));
891 if (c == EOF) unexpected_EOF();
893 illegal_tag(t_lineno, t_line, t_cptr);
896 for (i = 0; i < ntags; ++i)
898 if (strcmp(cache, tag_table[i]) == 0)
899 return (tag_table[i]);
905 tag_table = (char **)
906 (tag_table ? REALLOC(tag_table, tagmax*sizeof(char *))
907 : MALLOC(tagmax*sizeof(char *)));
908 if (tag_table == 0) no_space();
912 if (s == 0) no_space();
914 tag_table[ntags] = s;
922 declare_tokens(assoc)
930 if (assoc != TOKEN) ++prec;
933 if (c == EOF) unexpected_EOF();
938 if (c == EOF) unexpected_EOF();
943 if (isalpha(c) || c == '_' || c == '.' || c == '$')
945 else if (c == '\'' || c == '"')
950 if (bp == goal) tokenized_start(bp->name);
955 if (bp->tag && tag != bp->tag)
956 retyped_warning(bp->name);
962 if (bp->prec && prec != bp->prec)
963 reprec_warning(bp->name);
969 if (c == EOF) unexpected_EOF();
973 value = get_number();
974 if (bp->value != UNDEFINED && value != bp->value)
975 revalued_warning(bp->name);
978 if (c == EOF) unexpected_EOF();
985 * %expect requires special handling
986 * as it really isn't part of the yacc
987 * grammar only a flag for yacc proper.
990 declare_expect(assoc)
995 if (assoc != EXPECT) ++prec;
998 * Stay away from nextc - doesn't
999 * detect EOL and will read to EOF.
1002 if (c == EOF) unexpected_EOF();
1008 SRexpect = get_number();
1012 * Looking for number before EOL.
1013 * Spaces, tabs, and numbers are ok,
1014 * words, punc., etc. are syntax errors.
1016 else if (c == '\n' || isalpha(c) || !isspace(c))
1018 syntax_error(lineno, line, cptr);
1023 if (c == EOF) unexpected_EOF();
1037 if (c == EOF) unexpected_EOF();
1038 if (c != '<') syntax_error(lineno, line, cptr);
1044 if (isalpha(c) || c == '_' || c == '.' || c == '$')
1046 else if (c == '\'' || c == '"')
1051 if (bp->tag && tag != bp->tag)
1052 retyped_warning(bp->name);
1065 if (c == EOF) unexpected_EOF();
1066 if (!isalpha(c) && c != '_' && c != '.' && c != '$')
1067 syntax_error(lineno, line, cptr);
1069 if (bp->class == TERM)
1070 terminal_start(bp->name);
1071 if (goal && goal != bp)
1072 restarted_warning();
1083 cache = MALLOC(cache_size);
1084 if (cache == 0) no_space();
1089 if (c == EOF) unexpected_EOF();
1090 if (c != '%') syntax_error(lineno, line, cptr);
1091 switch (k = keyword())
1132 initialize_grammar()
1136 pitem = (bucket **) MALLOC(maxitems*sizeof(bucket *));
1137 if (pitem == 0) no_space();
1145 plhs = (bucket **) MALLOC(maxrules*sizeof(bucket *));
1146 if (plhs == 0) no_space();
1150 rprec = (short *) MALLOC(maxrules*sizeof(short));
1151 if (rprec == 0) no_space();
1155 rassoc = (char *) MALLOC(maxrules*sizeof(char));
1156 if (rassoc == 0) no_space();
1167 pitem = (bucket **) REALLOC(pitem, maxitems*sizeof(bucket *));
1168 if (pitem == 0) no_space();
1176 plhs = (bucket **) REALLOC(plhs, maxrules*sizeof(bucket *));
1177 if (plhs == 0) no_space();
1178 rprec = (short *) REALLOC(rprec, maxrules*sizeof(short));
1179 if (rprec == 0) no_space();
1180 rassoc = (char *) REALLOC(rassoc, maxrules*sizeof(char));
1181 if (rassoc == 0) no_space();
1196 if (c != '%') break;
1212 syntax_error(lineno, line, s_cptr);
1217 if (!isalpha(c) && c != '_' && c != '.' && c != '_')
1218 syntax_error(lineno, line, cptr);
1222 if (bp->class == TERM)
1223 terminal_start(bp->name);
1229 if (c == EOF) unexpected_EOF();
1230 if (c != ':') syntax_error(lineno, line, cptr);
1231 start_rule(bp, s_lineno);
1237 start_rule(bp, s_lineno)
1241 if (bp->class == TERM)
1242 terminal_lhs(s_lineno);
1243 bp->class = NONTERM;
1244 if (nrules >= maxrules)
1247 rprec[nrules] = UNDEFINED;
1248 rassoc[nrules] = TOKEN;
1257 if (!last_was_action && plhs[nrules]->tag)
1259 for (i = nitems - 1; pitem[i]; --i) continue;
1260 if (pitem[i+1] == 0 || pitem[i+1]->tag != plhs[nrules]->tag)
1261 default_action_warning();
1264 last_was_action = 0;
1265 if (nitems >= maxitems) expand_items();
1278 sprintf(cache, "$$%d", ++gensym);
1279 bp = make_bucket(cache);
1280 last_symbol->next = bp;
1282 bp->tag = plhs[nrules]->tag;
1283 bp->class = NONTERM;
1285 if ((nitems += 2) > maxitems)
1287 bpp = pitem + nitems - 1;
1289 while ((bpp[0] = bpp[-1])) --bpp;
1291 if (++nrules >= maxrules)
1293 plhs[nrules] = plhs[nrules-1];
1294 plhs[nrules-1] = bp;
1295 rprec[nrules] = rprec[nrules-1];
1296 rprec[nrules-1] = 0;
1297 rassoc[nrules] = rassoc[nrules-1];
1298 rassoc[nrules-1] = TOKEN;
1307 int s_lineno = lineno;
1310 if (c == '\'' || c == '"')
1319 start_rule(bp, s_lineno);
1324 if (last_was_action)
1325 insert_empty_rule();
1326 last_was_action = 0;
1328 if (++nitems > maxitems)
1330 pitem[nitems-1] = bp;
1342 FILE *f = action_file;
1343 int a_lineno = lineno;
1344 char *a_line = dup_line();
1345 char *a_cptr = a_line + (cptr - line);
1347 if (last_was_action)
1348 insert_empty_rule();
1349 last_was_action = 1;
1351 fprintf(f, "case %d:\n", nrules - 2);
1353 fprintf(f, line_format, lineno, input_file_name);
1354 if (*cptr == '=') ++cptr;
1357 for (i = nitems - 1; pitem[i]; --i) ++n;
1366 int d_lineno = lineno;
1367 char *d_line = dup_line();
1368 char *d_cptr = d_line + (cptr - line);
1375 fprintf(f, "yyval.%s", tag);
1380 else if (isdigit(c))
1383 if (i > n) dollar_warning(d_lineno, i);
1384 fprintf(f, "yyvsp[%d].%s", i - n, tag);
1388 else if (c == '-' && isdigit(cptr[1]))
1391 i = -get_number() - n;
1392 fprintf(f, "yyvsp[%d].%s", i, tag);
1397 dollar_error(d_lineno, d_line, d_cptr);
1399 else if (cptr[1] == '$')
1403 tag = plhs[nrules]->tag;
1404 if (tag == 0) untyped_lhs();
1405 fprintf(f, "yyval.%s", tag);
1408 fprintf(f, "yyval");
1412 else if (isdigit(cptr[1]))
1418 if (i <= 0 || i > n)
1420 tag = pitem[nitems + i - n - 1]->tag;
1421 if (tag == 0) untyped_rhs(i, pitem[nitems + i - n - 1]->name);
1422 fprintf(f, "yyvsp[%d].%s", i - n, tag);
1427 dollar_warning(lineno, i);
1428 fprintf(f, "yyvsp[%d]", i - n);
1432 else if (cptr[1] == '-')
1438 fprintf(f, "yyvsp[%d]", -i - n);
1442 if (isalpha(c) || c == '_' || c == '$')
1448 } while (isalnum(c) || c == '_' || c == '$');
1458 if (line) goto loop;
1459 unterminated_action(a_lineno, a_line, a_cptr);
1462 if (depth > 0) goto loop;
1463 fprintf(f, "\nbreak;\n");
1471 if (--depth > 0) goto loop;
1472 fprintf(f, "\nbreak;\n");
1478 int s_lineno = lineno;
1479 char *s_line = dup_line();
1480 char *s_cptr = s_line + (cptr - line - 1);
1493 unterminated_string(s_lineno, s_line, s_cptr);
1502 unterminated_string(s_lineno, s_line, s_cptr);
1513 while ((c = *++cptr) != '\n')
1515 if (c == '*' && cptr[1] == '/')
1525 int c_lineno = lineno;
1526 char *c_line = dup_line();
1527 char *c_cptr = c_line + (cptr - line - 1);
1535 if (c == '*' && *cptr == '/')
1546 unterminated_comment(c_lineno, c_line, c_cptr);
1565 if (c == '%' || c == '\\')
1573 else if ((c == 'p' || c == 'P') &&
1574 ((c = cptr[2]) == 'r' || c == 'R') &&
1575 ((c = cptr[3]) == 'e' || c == 'E') &&
1576 ((c = cptr[4]) == 'c' || c == 'C') &&
1577 ((c = cptr[5], !IS_IDENT(c))))
1580 syntax_error(lineno, line, cptr);
1583 if (isalpha(c) || c == '_' || c == '.' || c == '$')
1585 else if (c == '\'' || c == '"')
1589 syntax_error(lineno, line, cptr);
1593 if (rprec[nrules] != UNDEFINED && bp->prec != rprec[nrules])
1596 rprec[nrules] = bp->prec;
1597 rassoc[nrules] = bp->assoc;
1607 initialize_grammar();
1613 if (c == EOF) break;
1614 if (isalpha(c) || c == '_' || c == '.' || c == '$' || c == '\'' ||
1617 else if (c == '{' || c == '=')
1622 start_rule(plhs[nrules-1], 0);
1627 if (mark_symbol()) break;
1630 syntax_error(lineno, line, cptr);
1641 if (tag_table == 0) return;
1643 for (i = 0; i < ntags; ++i)
1645 assert(tag_table[i]);
1658 name_pool_size = 13; /* 13 == sizeof("$end") + sizeof("$accept") */
1659 for (bp = first_symbol; bp; bp = bp->next)
1660 name_pool_size += strlen(bp->name) + 1;
1661 name_pool = MALLOC(name_pool_size);
1662 if (name_pool == 0) no_space();
1664 strcpy(name_pool, "$accept");
1665 strcpy(name_pool+8, "$end");
1667 for (bp = first_symbol; bp; bp = bp->next)
1671 while ((*t++ = *s++)) continue;
1683 if (goal->class == UNKNOWN)
1684 undefined_goal(goal->name);
1686 for (bp = first_symbol; bp; bp = bp->next)
1688 if (bp->class == UNKNOWN)
1690 undefined_symbol_warning(bp->name);
1706 for (bp = first_symbol; bp; bp = bp->next)
1709 if (bp->class == TERM) ++ntokens;
1711 start_symbol = ntokens;
1712 nvars = nsyms - ntokens;
1714 symbol_name = (char **) MALLOC(nsyms*sizeof(char *));
1715 if (symbol_name == 0) no_space();
1716 symbol_value = (short *) MALLOC(nsyms*sizeof(short));
1717 if (symbol_value == 0) no_space();
1718 symbol_prec = (short *) MALLOC(nsyms*sizeof(short));
1719 if (symbol_prec == 0) no_space();
1720 symbol_assoc = MALLOC(nsyms);
1721 if (symbol_assoc == 0) no_space();
1723 v = (bucket **) MALLOC(nsyms*sizeof(bucket *));
1724 if (v == 0) no_space();
1727 v[start_symbol] = 0;
1730 j = start_symbol + 1;
1731 for (bp = first_symbol; bp; bp = bp->next)
1733 if (bp->class == TERM)
1738 assert(i == ntokens && j == nsyms);
1740 for (i = 1; i < ntokens; ++i)
1743 goal->index = start_symbol + 1;
1744 k = start_symbol + 2;
1754 for (i = start_symbol + 1; i < nsyms; ++i)
1764 for (i = 1; i < ntokens; ++i)
1769 for (j = k++; j > 0 && symbol_value[j-1] > n; --j)
1770 symbol_value[j] = symbol_value[j-1];
1771 symbol_value[j] = n;
1775 if (v[1]->value == UNDEFINED)
1780 for (i = 2; i < ntokens; ++i)
1782 if (v[i]->value == UNDEFINED)
1784 while (j < k && n == symbol_value[j])
1786 while (++j < k && n == symbol_value[j]) continue;
1794 symbol_name[0] = name_pool + 8;
1795 symbol_value[0] = 0;
1797 symbol_assoc[0] = TOKEN;
1798 for (i = 1; i < ntokens; ++i)
1800 symbol_name[i] = v[i]->name;
1801 symbol_value[i] = v[i]->value;
1802 symbol_prec[i] = v[i]->prec;
1803 symbol_assoc[i] = v[i]->assoc;
1805 symbol_name[start_symbol] = name_pool;
1806 symbol_value[start_symbol] = -1;
1807 symbol_prec[start_symbol] = 0;
1808 symbol_assoc[start_symbol] = TOKEN;
1809 for (++i; i < nsyms; ++i)
1812 symbol_name[k] = v[i]->name;
1813 symbol_value[k] = v[i]->value;
1814 symbol_prec[k] = v[i]->prec;
1815 symbol_assoc[k] = v[i]->assoc;
1828 ritem = (short *) MALLOC(nitems*sizeof(short));
1829 if (ritem == 0) no_space();
1830 rlhs = (short *) MALLOC(nrules*sizeof(short));
1831 if (rlhs == 0) no_space();
1832 rrhs = (short *) MALLOC((nrules+1)*sizeof(short));
1833 if (rrhs == 0) no_space();
1834 rprec = (short *) REALLOC(rprec, nrules*sizeof(short));
1835 if (rprec == 0) no_space();
1836 rassoc = REALLOC(rassoc, nrules);
1837 if (rassoc == 0) no_space();
1840 ritem[1] = goal->index;
1845 rlhs[2] = start_symbol;
1851 for (i = 3; i < nrules; ++i)
1853 rlhs[i] = plhs[i]->index;
1859 ritem[j] = pitem[j]->index;
1860 if (pitem[j]->class == TERM)
1862 preced = pitem[j]->prec;
1863 assoc = pitem[j]->assoc;
1869 if (rprec[i] == UNDEFINED)
1887 FILE *f = verbose_file;
1893 for (i = 2; i < nrules; ++i)
1895 if (rlhs[i] != rlhs[i-1])
1897 if (i != 2) fprintf(f, "\n");
1898 fprintf(f, "%4d %s :", i - 2, symbol_name[rlhs[i]]);
1899 spacing = strlen(symbol_name[rlhs[i]]) + 1;
1903 fprintf(f, "%4d ", i - 2);
1905 while (--j >= 0) putc(' ', f);
1909 while (ritem[k] >= 0)
1911 fprintf(f, " %s", symbol_name[ritem[k]]);
1923 write_section(banner);
1924 create_symbol_table();
1925 read_declarations();
1927 free_symbol_table();