X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/652a871c294ff727099daa57c494eaca9da6c1d3..eeeb962b:/src/reader.c?ds=inline diff --git a/src/reader.c b/src/reader.c index b7795dee..ac160aed 100644 --- a/src/reader.c +++ b/src/reader.c @@ -36,13 +36,11 @@ #include "conflicts.h" #include "muscle_tab.h" -/* Number of slots allocated (but not necessarily used yet) in `rline' */ -static int rline_allocated; - typedef struct symbol_list { struct symbol_list *next; bucket *sym; + int line; bucket *ruleprec; } symbol_list; @@ -66,6 +64,19 @@ static int lastprec; static bucket *errtoken; static bucket *undeftoken; + + +static symbol_list * +symbol_list_new (bucket *sym) +{ + symbol_list *res = XMALLOC (symbol_list, 1); + res->next = NULL; + res->sym = sym; + res->line = lineno; + res->ruleprec = NULL; + return res; +} + /*===================\ @@ -123,7 +134,7 @@ read_signed_integer (FILE *stream) `--------------------------------------------------------------*/ static char * -get_type_name (int n, symbol_list * rule) +get_type_name (int n, symbol_list *rule) { int i; symbol_list *rp; @@ -568,7 +579,8 @@ parse_token_decl (symbol_class what_is, symbol_class what_is_not) else { complain (_("`%s' is invalid in %s"), - token_buffer, (what_is == token_sym) ? "%token" : "%nterm"); + token_buffer, + (what_is == token_sym) ? "%token" : "%nterm"); skip_to_char ('%'); } } @@ -962,6 +974,16 @@ parse_skel_decl (void) /* Complete with parse_dquoted_param () on the CVS branch 1.29. */ } +/*---------------------------------------. +| Parse what comes after %skeleton_path. | +`---------------------------------------*/ + +void +parse_include_decl (void) +{ + /* Complete with parse_dquoted_param () on the CVS branch 1.29. */ +} + /*----------------------------------------------------------------. | Read from finput until `%%' is seen. Discard the `%%'. Handle | | any `%' declarations, and copy the contents of any `%{ ... %}' | @@ -1036,16 +1058,20 @@ read_declarations (void) parse_skel_decl (); break; + case tok_include: + parse_include_decl (); + break; + case tok_noop: break; case tok_stropt: case tok_intopt: case tok_obsolete: - case tok_illegal: abort (); break; + case tok_illegal: default: complain (_("unrecognized: %s"), token_buffer); skip_to_char ('%'); @@ -1251,20 +1277,6 @@ copy_guard (symbol_list *rule, int stack_offset) } -static void -record_rule_line (void) -{ - /* Record each rule's source line number in rline table. */ - - if (nrules >= rline_allocated) - { - rline_allocated = nrules * 2; - rline = XREALLOC (rline, short, rline_allocated); - } - rline[nrules] = lineno; -} - - /*-------------------------------------------------------------------. | Generate a dummy symbol, a nonterminal, whose name cannot conflict | | with the user's names. | @@ -1407,10 +1419,7 @@ readgram (void) nrules++; nitems++; - record_rule_line (); - - p = XCALLOC (symbol_list, 1); - p->sym = lhs; + p = symbol_list_new (lhs); crule1 = p1; if (p1) @@ -1472,36 +1481,35 @@ readgram (void) non-terminal. */ if (action_flag) { - bucket *sdummy; - /* Since the action was written out with this rule's number, we must give the new rule this number by inserting the new rule before it. */ /* Make a dummy nonterminal, a gensym. */ - sdummy = gensym (); + bucket *sdummy = gensym (); - /* Make a new rule, whose body is empty, - before the current one, so that the action - just read can belong to it. */ + /* Make a new rule, whose body is empty, before the + current one, so that the action just read can + belong to it. */ nrules++; nitems++; - record_rule_line (); - p = XCALLOC (symbol_list, 1); + p = symbol_list_new (sdummy); + /* Attach its lineno to that of the host rule. */ + p->line = crule->line; if (crule1) crule1->next = p; else grammar = p; - p->sym = sdummy; - crule1 = XCALLOC (symbol_list, 1); - p->next = crule1; + /* End of the rule. */ + crule1 = symbol_list_new (NULL); crule1->next = crule; + p->next = crule1; + /* Insert the dummy generated by that rule into this rule. */ nitems++; - p = XCALLOC (symbol_list, 1); - p->sym = sdummy; + p = symbol_list_new (sdummy); p1->next = p; p1 = p; @@ -1511,8 +1519,7 @@ readgram (void) if (t == tok_identifier) { nitems++; - p = XCALLOC (symbol_list, 1); - p->sym = symval; + p = symbol_list_new (symval); p1->next = p; p1 = p; } @@ -1526,7 +1533,7 @@ readgram (void) } /* end of read rhs of rule */ /* Put an empty link in the list to mark the end of this rule */ - p = XCALLOC (symbol_list, 1); + p = symbol_list_new (NULL); p1->next = p; p1 = p; @@ -1919,8 +1926,6 @@ packgram (void) int ruleno; symbol_list *p; - bucket *ruleprec; - ritem = XCALLOC (short, nitems + 1); rule_table = XCALLOC (rule_t, nrules) - 1; @@ -1930,9 +1935,10 @@ packgram (void) p = grammar; while (p) { + bucket *ruleprec = p->ruleprec; rule_table[ruleno].lhs = p->sym->value; rule_table[ruleno].rhs = itemno; - ruleprec = p->ruleprec; + rule_table[ruleno].line = p->line; p = p->next; while (p && p->sym) @@ -1986,8 +1992,6 @@ reader (void) nvars = 0; nrules = 0; nitems = 0; - rline_allocated = 10; - rline = XCALLOC (short, rline_allocated); typed = 0; lastprec = 0;