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);
126 if (cinc >= cache_size)
129 cache = realloc(cache, cache_size);
130 if (cache == 0) no_space();
140 FILE *f = input_file;
144 if (saw_eof || (c = getc(f)) == EOF)
146 if (line) { free(line); line = 0; }
152 if (line == 0 || linesize != (LINESIZE + 1))
154 if (line) free(line);
155 linesize = LINESIZE + 1;
156 line = malloc(linesize);
157 if (line == 0) no_space();
165 if (c == '\n') { cptr = line; return; }
168 linesize += LINESIZE;
169 line = realloc(line, linesize);
170 if (line == 0) no_space();
189 if (line == 0) return (0);
191 while (*s != '\n') ++s;
192 p = malloc(s - line + 1);
193 if (p == 0) no_space();
197 while ((*t++ = *s++) != '\n') continue;
207 int st_lineno = lineno;
208 char *st_line = dup_line();
209 char *st_cptr = st_line + (cptr - line);
214 if (*s == '*' && s[1] == '/')
224 unterminated_comment(st_lineno, st_line, st_cptr);
252 if (line == 0) return (EOF);
278 else if (s[1] == '/')
281 if (line == 0) return (EOF);
309 if (isupper(c)) c = tolower(c);
312 else if (isdigit(c) || c == '_' || c == '.' || c == '$')
320 if (strcmp(cache, "token") == 0 || strcmp(cache, "term") == 0)
322 if (strcmp(cache, "type") == 0)
324 if (strcmp(cache, "left") == 0)
326 if (strcmp(cache, "right") == 0)
328 if (strcmp(cache, "nonassoc") == 0 || strcmp(cache, "binary") == 0)
330 if (strcmp(cache, "start") == 0)
332 if (strcmp(cache, "union") == 0)
334 if (strcmp(cache, "ident") == 0)
336 if (strcmp(cache, "expect") == 0)
344 if (c == '%' || c == '\\')
355 syntax_error(lineno, line, t_cptr);
365 FILE *f = output_file;
368 if (c == EOF) unexpected_EOF();
369 if (c != '"') syntax_error(lineno, line, cptr);
371 fprintf(f, "#ident \"");
397 int need_newline = 0;
398 int t_lineno = lineno;
399 char *t_line = dup_line();
400 char *t_cptr = t_line + (cptr - line - 2);
406 unterminated_text(t_lineno, t_line, t_cptr);
408 if (!lflag) fprintf(f, line_format, lineno, input_file_name);
420 unterminated_text(t_lineno, t_line, t_cptr);
425 int s_lineno = lineno;
426 char *s_line = dup_line();
427 char *s_cptr = s_line + (cptr - line - 1);
442 unterminated_string(s_lineno, s_line, s_cptr);
451 unterminated_string(s_lineno, s_line, s_cptr);
464 while ((c = *++cptr) != '\n')
466 if (c == '*' && cptr[1] == '/')
476 int c_lineno = lineno;
477 char *c_line = dup_line();
478 char *c_cptr = c_line + (cptr - line - 1);
486 if (c == '*' && *cptr == '/')
497 unterminated_comment(c_lineno, c_line, c_cptr);
508 if (need_newline) putc('\n', f);
529 int u_lineno = lineno;
530 char *u_line = dup_line();
531 char *u_cptr = u_line + (cptr - line - 6);
533 if (unionized) over_unionized(cptr - 6);
537 fprintf(text_file, line_format, lineno, input_file_name);
539 fprintf(text_file, "typedef union");
540 if (dflag) fprintf(union_file, "typedef union");
546 if (dflag) putc(c, union_file);
552 if (line == 0) unterminated_union(u_lineno, u_line, u_cptr);
562 fprintf(text_file, " YYSTYPE;\n");
571 int s_lineno = lineno;
572 char *s_line = dup_line();
573 char *s_cptr = s_line + (cptr - line - 1);
580 if (dflag) putc(c, union_file);
587 unterminated_string(s_lineno, s_line, s_cptr);
592 if (dflag) putc(c, union_file);
597 unterminated_string(s_lineno, s_line, s_cptr);
607 putc('*', text_file);
608 if (dflag) putc('*', union_file);
609 while ((c = *++cptr) != '\n')
611 if (c == '*' && cptr[1] == '/')
613 fprintf(text_file, "* ");
614 if (dflag) fprintf(union_file, "* ");
619 if (dflag) putc(c, union_file);
622 fprintf(text_file, "*/\n");
623 if (dflag) fprintf(union_file, "*/\n");
628 int c_lineno = lineno;
629 char *c_line = dup_line();
630 char *c_cptr = c_line + (cptr - line - 1);
632 putc('*', text_file);
633 if (dflag) putc('*', union_file);
639 if (dflag) putc(c, union_file);
640 if (c == '*' && *cptr == '/')
642 putc('/', text_file);
643 if (dflag) putc('/', union_file);
652 unterminated_comment(c_lineno, c_line, c_cptr);
667 if (c >= '0' && c <= '9')
669 if (c >= 'A' && c <= 'F')
670 return (c - 'A' + 10);
671 if (c >= 'a' && c <= 'f')
672 return (c - 'a' + 10);
685 int s_lineno = lineno;
686 char *s_line = dup_line();
687 char *s_cptr = s_line + (cptr - line);
694 if (c == quote) break;
695 if (c == '\n') unterminated_string(s_lineno, s_line, s_cptr);
698 char *c_cptr = cptr - 1;
705 if (line == 0) unterminated_string(s_lineno, s_line, s_cptr);
708 case '0': case '1': case '2': case '3':
709 case '4': case '5': case '6': case '7':
714 n = (n << 3) + (c - '0');
718 n = (n << 3) + (c - '0');
722 if (n > UCHAR_MAX) illegal_character(c_cptr);
729 if (n < 0 || n >= 16)
730 illegal_character(c_cptr);
735 if (i < 0 || i >= 16) break;
738 if (n > UCHAR_MAX) illegal_character(c_cptr);
743 case 'a': c = 7; break;
744 case 'b': c = '\b'; break;
745 case 'f': c = '\f'; break;
746 case 'n': c = '\n'; break;
747 case 'r': c = '\r'; break;
748 case 't': c = '\t'; break;
749 case 'v': c = '\v'; break;
758 if (s == 0) no_space();
760 for (i = 0; i < n; ++i)
769 for (i = 0; i < n; ++i)
771 c = ((unsigned char *)s)[i];
772 if (c == '\\' || c == cache[0])
784 case 7: cachec('a'); break;
785 case '\b': cachec('b'); break;
786 case '\f': cachec('f'); break;
787 case '\n': cachec('n'); break;
788 case '\r': cachec('r'); break;
789 case '\t': cachec('t'); break;
790 case '\v': cachec('v'); break;
792 cachec(((c >> 6) & 7) + '0');
793 cachec(((c >> 3) & 7) + '0');
794 cachec((c & 7) + '0');
808 if (n == 1 && bp->value == UNDEFINED)
809 bp->value = *(unsigned char *)s;
817 is_reserved(char *name)
821 if (strcmp(name, ".") == 0 ||
822 strcmp(name, "$accept") == 0 ||
823 strcmp(name, "$end") == 0)
826 if (name[0] == '$' && name[1] == '$' && isdigit(name[2]))
829 while (isdigit(*s)) ++s;
830 if (*s == NUL) return (1);
843 for (c = *cptr; IS_IDENT(c); c = *++cptr)
847 if (is_reserved(cache)) used_reserved(cache);
849 return (lookup(cache));
860 for (c = *cptr; isdigit(c); c = *++cptr)
861 n = 10*n + (c - '0');
873 int t_lineno = lineno;
874 char *t_line = dup_line();
875 char *t_cptr = t_line + (cptr - line);
879 if (c == EOF) unexpected_EOF();
880 if (!isalpha(c) && c != '_' && c != '$')
881 illegal_tag(t_lineno, t_line, t_cptr);
884 do { cachec(c); c = *++cptr; } while (IS_IDENT(c));
888 if (c == EOF) unexpected_EOF();
890 illegal_tag(t_lineno, t_line, t_cptr);
893 for (i = 0; i < ntags; ++i)
895 if (strcmp(cache, tag_table[i]) == 0)
896 return (tag_table[i]);
902 tag_table = (char **)
903 (tag_table ? realloc(tag_table, tagmax*sizeof(char *))
904 : malloc(tagmax*sizeof(char *)));
905 if (tag_table == 0) no_space();
909 if (s == 0) no_space();
911 tag_table[ntags] = s;
919 declare_tokens(int assoc)
926 if (assoc != TOKEN) ++prec;
929 if (c == EOF) unexpected_EOF();
934 if (c == EOF) unexpected_EOF();
939 if (isalpha(c) || c == '_' || c == '.' || c == '$')
941 else if (c == '\'' || c == '"')
946 if (bp == goal) tokenized_start(bp->name);
951 if (bp->tag && tag != bp->tag)
952 retyped_warning(bp->name);
958 if (bp->prec && prec != bp->prec)
959 reprec_warning(bp->name);
965 if (c == EOF) unexpected_EOF();
969 value = get_number();
970 if (bp->value != UNDEFINED && value != bp->value)
971 revalued_warning(bp->name);
974 if (c == EOF) unexpected_EOF();
981 * %expect requires special handling
982 * as it really isn't part of the yacc
983 * grammar only a flag for yacc proper.
986 declare_expect(int assoc)
990 if (assoc != EXPECT) ++prec;
993 * Stay away from nextc - doesn't
994 * detect EOL and will read to EOF.
997 if (c == EOF) unexpected_EOF();
1003 SRexpect = get_number();
1007 * Looking for number before EOL.
1008 * Spaces, tabs, and numbers are ok,
1009 * words, punc., etc. are syntax errors.
1011 else if (c == '\n' || isalpha(c) || !isspace(c))
1013 syntax_error(lineno, line, cptr);
1018 if (c == EOF) unexpected_EOF();
1032 if (c == EOF) unexpected_EOF();
1033 if (c != '<') syntax_error(lineno, line, cptr);
1039 if (isalpha(c) || c == '_' || c == '.' || c == '$')
1041 else if (c == '\'' || c == '"')
1046 if (bp->tag && tag != bp->tag)
1047 retyped_warning(bp->name);
1060 if (c == EOF) unexpected_EOF();
1061 if (!isalpha(c) && c != '_' && c != '.' && c != '$')
1062 syntax_error(lineno, line, cptr);
1064 if (bp->class == TERM)
1065 terminal_start(bp->name);
1066 if (goal && goal != bp)
1067 restarted_warning();
1073 read_declarations(void)
1078 cache = malloc(cache_size);
1079 if (cache == 0) no_space();
1084 if (c == EOF) unexpected_EOF();
1085 if (c != '%') syntax_error(lineno, line, cptr);
1086 switch (k = keyword())
1127 initialize_grammar(void)
1131 pitem = malloc(maxitems*sizeof(bucket *));
1132 if (pitem == 0) no_space();
1140 plhs = malloc(maxrules*sizeof(bucket *));
1141 if (plhs == 0) no_space();
1145 rprec = malloc(maxrules*sizeof(short));
1146 if (rprec == 0) no_space();
1150 rassoc = malloc(maxrules*sizeof(char));
1151 if (rassoc == 0) no_space();
1162 pitem = realloc(pitem, maxitems*sizeof(bucket *));
1163 if (pitem == 0) no_space();
1171 plhs = realloc(plhs, maxrules*sizeof(bucket *));
1172 if (plhs == 0) no_space();
1173 rprec = realloc(rprec, maxrules*sizeof(short));
1174 if (rprec == 0) no_space();
1175 rassoc = realloc(rassoc, maxrules*sizeof(char));
1176 if (rassoc == 0) no_space();
1181 advance_to_start(void)
1191 if (c != '%') break;
1207 syntax_error(lineno, line, s_cptr);
1212 if (!isalpha(c) && c != '_' && c != '.' && c != '_')
1213 syntax_error(lineno, line, cptr);
1217 if (bp->class == TERM)
1218 terminal_start(bp->name);
1224 if (c == EOF) unexpected_EOF();
1225 if (c != ':') syntax_error(lineno, line, cptr);
1226 start_rule(bp, s_lineno);
1232 start_rule(bucket *bp, int s_lineno)
1234 if (bp->class == TERM)
1235 terminal_lhs(s_lineno);
1236 bp->class = NONTERM;
1237 if (nrules >= maxrules)
1240 rprec[nrules] = UNDEFINED;
1241 rassoc[nrules] = TOKEN;
1250 if (!last_was_action && plhs[nrules]->tag)
1252 for (i = nitems - 1; pitem[i]; --i) continue;
1253 if (pitem[i+1] == 0 || pitem[i+1]->tag != plhs[nrules]->tag)
1254 default_action_warning();
1257 last_was_action = 0;
1258 if (nitems >= maxitems) expand_items();
1266 insert_empty_rule(void)
1271 sprintf(cache, "$$%d", ++gensym);
1272 bp = make_bucket(cache);
1273 last_symbol->next = bp;
1275 bp->tag = plhs[nrules]->tag;
1276 bp->class = NONTERM;
1278 if ((nitems += 2) > maxitems)
1280 bpp = pitem + nitems - 1;
1282 while ((bpp[0] = bpp[-1])) --bpp;
1284 if (++nrules >= maxrules)
1286 plhs[nrules] = plhs[nrules-1];
1287 plhs[nrules-1] = bp;
1288 rprec[nrules] = rprec[nrules-1];
1289 rprec[nrules-1] = 0;
1290 rassoc[nrules] = rassoc[nrules-1];
1291 rassoc[nrules-1] = TOKEN;
1300 int s_lineno = lineno;
1303 if (c == '\'' || c == '"')
1312 start_rule(bp, s_lineno);
1317 if (last_was_action)
1318 insert_empty_rule();
1319 last_was_action = 0;
1321 if (++nitems > maxitems)
1323 pitem[nitems-1] = bp;
1335 FILE *f = action_file;
1336 int a_lineno = lineno;
1337 char *a_line = dup_line();
1338 char *a_cptr = a_line + (cptr - line);
1340 if (last_was_action)
1341 insert_empty_rule();
1342 last_was_action = 1;
1344 fprintf(f, "case %d:\n", nrules - 2);
1346 fprintf(f, line_format, lineno, input_file_name);
1347 if (*cptr == '=') ++cptr;
1350 for (i = nitems - 1; pitem[i]; --i) ++n;
1359 int d_lineno = lineno;
1360 char *d_line = dup_line();
1361 char *d_cptr = d_line + (cptr - line);
1368 fprintf(f, "yyval.%s", tag);
1373 else if (isdigit(c))
1376 if (i > n) dollar_warning(d_lineno, i);
1377 fprintf(f, "yyvsp[%d].%s", i - n, tag);
1381 else if (c == '-' && isdigit(cptr[1]))
1384 i = -get_number() - n;
1385 fprintf(f, "yyvsp[%d].%s", i, tag);
1390 dollar_error(d_lineno, d_line, d_cptr);
1392 else if (cptr[1] == '$')
1396 tag = plhs[nrules]->tag;
1397 if (tag == 0) untyped_lhs();
1398 fprintf(f, "yyval.%s", tag);
1401 fprintf(f, "yyval");
1405 else if (isdigit(cptr[1]))
1411 if (i <= 0 || i > n)
1413 tag = pitem[nitems + i - n - 1]->tag;
1414 if (tag == 0) untyped_rhs(i, pitem[nitems + i - n - 1]->name);
1415 fprintf(f, "yyvsp[%d].%s", i - n, tag);
1420 dollar_warning(lineno, i);
1421 fprintf(f, "yyvsp[%d]", i - n);
1425 else if (cptr[1] == '-')
1431 fprintf(f, "yyvsp[%d]", -i - n);
1435 if (isalpha(c) || c == '_' || c == '$')
1441 } while (isalnum(c) || c == '_' || c == '$');
1451 if (line) goto loop;
1452 unterminated_action(a_lineno, a_line, a_cptr);
1455 if (depth > 0) goto loop;
1456 fprintf(f, "\nbreak;\n");
1464 if (--depth > 0) goto loop;
1465 fprintf(f, "\nbreak;\n");
1471 int s_lineno = lineno;
1472 char *s_line = dup_line();
1473 char *s_cptr = s_line + (cptr - line - 1);
1486 unterminated_string(s_lineno, s_line, s_cptr);
1495 unterminated_string(s_lineno, s_line, s_cptr);
1506 while ((c = *++cptr) != '\n')
1508 if (c == '*' && cptr[1] == '/')
1518 int c_lineno = lineno;
1519 char *c_line = dup_line();
1520 char *c_cptr = c_line + (cptr - line - 1);
1528 if (c == '*' && *cptr == '/')
1539 unterminated_comment(c_lineno, c_line, c_cptr);
1558 if (c == '%' || c == '\\')
1566 else if ((c == 'p' || c == 'P') &&
1567 ((c = cptr[2]) == 'r' || c == 'R') &&
1568 ((c = cptr[3]) == 'e' || c == 'E') &&
1569 ((c = cptr[4]) == 'c' || c == 'C') &&
1570 ((c = cptr[5], !IS_IDENT(c))))
1573 syntax_error(lineno, line, cptr);
1576 if (isalpha(c) || c == '_' || c == '.' || c == '$')
1578 else if (c == '\'' || c == '"')
1582 syntax_error(lineno, line, cptr);
1586 if (rprec[nrules] != UNDEFINED && bp->prec != rprec[nrules])
1589 rprec[nrules] = bp->prec;
1590 rassoc[nrules] = bp->assoc;
1600 initialize_grammar();
1606 if (c == EOF) break;
1607 if (isalpha(c) || c == '_' || c == '.' || c == '$' || c == '\'' ||
1610 else if (c == '{' || c == '=')
1615 start_rule(plhs[nrules-1], 0);
1620 if (mark_symbol()) break;
1623 syntax_error(lineno, line, cptr);
1634 if (tag_table == 0) return;
1636 for (i = 0; i < ntags; ++i)
1638 assert(tag_table[i]);
1651 name_pool_size = 13; /* 13 == sizeof("$end") + sizeof("$accept") */
1652 for (bp = first_symbol; bp; bp = bp->next)
1653 name_pool_size += strlen(bp->name) + 1;
1654 name_pool = malloc(name_pool_size);
1655 if (name_pool == 0) no_space();
1657 strcpy(name_pool, "$accept");
1658 strcpy(name_pool+8, "$end");
1660 for (bp = first_symbol; bp; bp = bp->next)
1664 while ((*t++ = *s++)) continue;
1676 if (goal->class == UNKNOWN)
1677 undefined_goal(goal->name);
1679 for (bp = first_symbol; bp; bp = bp->next)
1681 if (bp->class == UNKNOWN)
1683 undefined_symbol_warning(bp->name);
1699 for (bp = first_symbol; bp; bp = bp->next)
1702 if (bp->class == TERM) ++ntokens;
1704 start_symbol = ntokens;
1705 nvars = nsyms - ntokens;
1707 symbol_name = malloc(nsyms*sizeof(char *));
1708 if (symbol_name == 0) no_space();
1709 symbol_value = malloc(nsyms*sizeof(short));
1710 if (symbol_value == 0) no_space();
1711 symbol_prec = malloc(nsyms*sizeof(short));
1712 if (symbol_prec == 0) no_space();
1713 symbol_assoc = malloc(nsyms);
1714 if (symbol_assoc == 0) no_space();
1716 v = malloc(nsyms*sizeof(bucket *));
1717 if (v == 0) no_space();
1720 v[start_symbol] = 0;
1723 j = start_symbol + 1;
1724 for (bp = first_symbol; bp; bp = bp->next)
1726 if (bp->class == TERM)
1731 assert(i == ntokens && j == nsyms);
1733 for (i = 1; i < ntokens; ++i)
1736 goal->index = start_symbol + 1;
1737 k = start_symbol + 2;
1747 for (i = start_symbol + 1; i < nsyms; ++i)
1757 for (i = 1; i < ntokens; ++i)
1762 for (j = k++; j > 0 && symbol_value[j-1] > n; --j)
1763 symbol_value[j] = symbol_value[j-1];
1764 symbol_value[j] = n;
1768 if (v[1]->value == UNDEFINED)
1773 for (i = 2; i < ntokens; ++i)
1775 if (v[i]->value == UNDEFINED)
1777 while (j < k && n == symbol_value[j])
1779 while (++j < k && n == symbol_value[j]) continue;
1787 symbol_name[0] = name_pool + 8;
1788 symbol_value[0] = 0;
1790 symbol_assoc[0] = TOKEN;
1791 for (i = 1; i < ntokens; ++i)
1793 symbol_name[i] = v[i]->name;
1794 symbol_value[i] = v[i]->value;
1795 symbol_prec[i] = v[i]->prec;
1796 symbol_assoc[i] = v[i]->assoc;
1798 symbol_name[start_symbol] = name_pool;
1799 symbol_value[start_symbol] = -1;
1800 symbol_prec[start_symbol] = 0;
1801 symbol_assoc[start_symbol] = TOKEN;
1802 for (++i; i < nsyms; ++i)
1805 symbol_name[k] = v[i]->name;
1806 symbol_value[k] = v[i]->value;
1807 symbol_prec[k] = v[i]->prec;
1808 symbol_assoc[k] = v[i]->assoc;
1821 ritem = malloc(nitems*sizeof(short));
1822 if (ritem == 0) no_space();
1823 rlhs = malloc(nrules*sizeof(short));
1824 if (rlhs == 0) no_space();
1825 rrhs = malloc((nrules+1)*sizeof(short));
1826 if (rrhs == 0) no_space();
1827 rprec = realloc(rprec, nrules*sizeof(short));
1828 if (rprec == 0) no_space();
1829 rassoc = realloc(rassoc, nrules);
1830 if (rassoc == 0) no_space();
1833 ritem[1] = goal->index;
1838 rlhs[2] = start_symbol;
1844 for (i = 3; i < nrules; ++i)
1846 rlhs[i] = plhs[i]->index;
1852 ritem[j] = pitem[j]->index;
1853 if (pitem[j]->class == TERM)
1855 preced = pitem[j]->prec;
1856 assoc = pitem[j]->assoc;
1862 if (rprec[i] == UNDEFINED)
1880 FILE *f = verbose_file;
1886 for (i = 2; i < nrules; ++i)
1888 if (rlhs[i] != rlhs[i-1])
1890 if (i != 2) fprintf(f, "\n");
1891 fprintf(f, "%4d %s :", i - 2, symbol_name[rlhs[i]]);
1892 spacing = strlen(symbol_name[rlhs[i]]) + 1;
1896 fprintf(f, "%4d ", i - 2);
1898 while (--j >= 0) putc(' ', f);
1902 while (ritem[k] >= 0)
1904 fprintf(f, " %s", symbol_name[ritem[k]]);
1916 write_section(banner);
1917 create_symbol_table();
1918 read_declarations();
1920 free_symbol_table();