X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/17ee7397a87c4c4ccd45f956e0b88b824a3689f9..2cbd078f5153288a39cbf046231a3870df8170cb:/src/reader.c diff --git a/src/reader.c b/src/reader.c index e90cd2d7..561b7419 100644 --- a/src/reader.c +++ b/src/reader.c @@ -1,6 +1,7 @@ /* Input parser for Bison - Copyright (C) 1984, 1986, 1989, 1992, 1998, 2000, 2001, 2002 - Free Software Foundation, Inc. + + Copyright (C) 1984, 1986, 1989, 1992, 1998, 2000, 2001, 2002, 2003, + 2005 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -16,8 +17,8 @@ You should have received a copy of the GNU General Public License along with Bison; see the file COPYING. If not, write to - the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. */ #include "system.h" @@ -35,25 +36,28 @@ #include "symtab.h" static symbol_list *grammar = NULL; -static int start_flag = 0; +static bool start_flag = false; merger_list *merge_functions; -/* Nonzero if %union has been seen. */ -int typed = 0; +/* Has %union been seen? */ +bool typed = false; + +/* Should rules have a default precedence? */ +bool default_prec = true; /*-----------------------. | Set the start symbol. | `-----------------------*/ void -grammar_start_symbol_set (symbol *s, location loc) +grammar_start_symbol_set (symbol *sym, location loc) { if (start_flag) complain_at (loc, _("multiple %s declarations"), "%start"); else { - start_flag = 1; - startsymbol = s; + start_flag = true; + startsymbol = sym; startsymbol_location = loc; } } @@ -70,36 +74,13 @@ prologue_augment (const char *prologue, location loc) struct obstack *oout = !typed ? &pre_prologue_obstack : &post_prologue_obstack; - obstack_fgrow1 (oout, "]b4_syncline([[%d]], [[", loc.start.line); + obstack_fgrow1 (oout, "]b4_syncline(%d, [[", loc.start.line); MUSCLE_OBSTACK_SGROW (oout, quotearg_style (c_quoting_style, loc.start.file)); obstack_sgrow (oout, "]])[\n"); obstack_sgrow (oout, prologue); } - - - -/*----------------------. -| Handle the epilogue. | -`----------------------*/ - -void -epilogue_augment (const char *epilogue, location loc) -{ - char *extension = NULL; - obstack_fgrow1 (&muscle_obstack, "]b4_syncline([[%d]], [[", loc.start.line); - MUSCLE_OBSTACK_SGROW (&muscle_obstack, - quotearg_style (c_quoting_style, loc.start.file)); - obstack_sgrow (&muscle_obstack, "]])[\n"); - obstack_sgrow (&muscle_obstack, epilogue); - obstack_1grow (&muscle_obstack, 0); - extension = obstack_finish (&muscle_obstack); - muscle_grow ("epilogue", extension, ""); - obstack_free (&muscle_obstack, extension); -} - - /*-------------------------------------------------------------------. @@ -127,7 +108,7 @@ get_merge_function (uniqstr name, uniqstr type, location loc) break; if (syms->next == NULL) { - syms->next = XMALLOC (merger_list, 1); + syms->next = xmalloc (sizeof syms->next[0]); syms->next->name = uniqstr_new (name); syms->next->type = uniqstr_new (type); syms->next->next = NULL; @@ -180,7 +161,7 @@ free_merger_functions (void) /* The (currently) last symbol of GRAMMAR. */ symbol_list *grammar_end = NULL; -/* Append S to the GRAMMAR. */ +/* Append SYM to the grammar. */ void grammar_symbol_append (symbol *sym, location loc) { @@ -212,7 +193,7 @@ grammar_rule_begin (symbol *lhs, location loc) { startsymbol = lhs; startsymbol_location = loc; - start_flag = 1; + start_flag = true; } /* Start a new rule and record its lhs. */ @@ -406,8 +387,8 @@ packgram (void) rule_number ruleno = 0; symbol_list *p = grammar; - ritem = XCALLOC (item_number, nritems); - rules = XCALLOC (rule, nrules); + ritem = xnmalloc (nritems, sizeof *ritem); + rules = xnmalloc (nrules, sizeof *rules); while (p) { @@ -416,12 +397,14 @@ packgram (void) rules[ruleno].number = ruleno; rules[ruleno].lhs = p->sym; rules[ruleno].rhs = ritem + itemno; + rules[ruleno].prec = NULL; + rules[ruleno].dprec = p->dprec; + rules[ruleno].merger = p->merger; + rules[ruleno].precsym = NULL; rules[ruleno].location = p->location; rules[ruleno].useful = true; rules[ruleno].action = p->action; rules[ruleno].action_location = p->action_location; - rules[ruleno].dprec = p->dprec; - rules[ruleno].merger = p->merger; p = p->next; while (p && p->sym) @@ -431,7 +414,7 @@ packgram (void) ritem[itemno++] = symbol_number_as_item_number (p->sym->number); /* A rule gets by default the precedence and associativity of the last token in it. */ - if (p->sym->class == token_sym) + if (p->sym->class == token_sym && default_prec) rules[ruleno].prec = p->sym; if (p) p = p->next;