X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/73521d9ff8d6562af639101b2a0f78b6ec556e62..6175ffe3211dad578ce6585584c4eb85cf891830:/src/parse-gram.c diff --git a/src/parse-gram.c b/src/parse-gram.c index 0af6caf5..c69b294c 100644 --- a/src/parse-gram.c +++ b/src/parse-gram.c @@ -1,7 +1,7 @@ -/* A Bison parser, made by GNU Bison 1.75e. */ +/* A Bison parser, made by GNU Bison 1.875b. */ /* Skeleton parser for Yacc-like parsing with Bison, - Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002 Free Software Foundation, Inc. + Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -157,7 +157,7 @@ /* Copy the first part of user declarations. */ -#line 31 "parse-gram.y" +#line 32 "parse-gram.y" #include "system.h" @@ -212,7 +212,7 @@ int current_prec = 0; #endif #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED) -#line 74 "parse-gram.y" +#line 75 "parse-gram.y" typedef union YYSTYPE { symbol *symbol; symbol_list *list; @@ -221,8 +221,8 @@ typedef union YYSTYPE { assoc assoc; uniqstr uniqstr; } YYSTYPE; -/* Line 192 of yacc.c. */ -#line 225 "parse-gram.c" +/* Line 191 of yacc.c. */ +#line 226 "parse-gram.c" # define yystype YYSTYPE /* obsolescent; will be withdrawn */ # define YYSTYPE_IS_DECLARED 1 # define YYSTYPE_IS_TRIVIAL 1 @@ -245,8 +245,8 @@ typedef struct YYLTYPE /* Copy the second part of user declarations. */ -/* Line 215 of yacc.c. */ -#line 249 "parse-gram.c" +/* Line 214 of yacc.c. */ +#line 250 "parse-gram.c" #if ! defined (yyoverflow) || YYERROR_VERBOSE @@ -442,14 +442,14 @@ static const yysigned_char yyrhs[] = /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const unsigned short yyrline[] = { - 0, 160, 160, 168, 170, 174, 175, 176, 177, 178, - 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, - 189, 190, 191, 192, 193, 194, 198, 199, 200, 204, - 210, 217, 227, 227, 232, 232, 237, 247, 262, 263, - 264, 268, 269, 275, 276, 281, 285, 290, 296, 302, - 313, 314, 323, 324, 330, 331, 336, 340, 344, 344, - 348, 349, 354, 355, 357, 359, 361, 363, 368, 369, - 373, 379, 388, 395, 397 + 0, 161, 161, 169, 171, 175, 176, 177, 178, 179, + 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, + 190, 191, 192, 193, 194, 195, 199, 200, 201, 205, + 211, 218, 228, 228, 233, 233, 238, 248, 263, 264, + 265, 269, 270, 276, 277, 282, 286, 291, 297, 303, + 314, 315, 324, 325, 331, 332, 337, 341, 345, 345, + 349, 350, 355, 356, 358, 360, 362, 364, 369, 370, + 374, 380, 389, 396, 398 }; #endif @@ -654,7 +654,14 @@ static const unsigned char yystos[] = #define YYACCEPT goto yyacceptlab #define YYABORT goto yyabortlab -#define YYERROR goto yyerrlab1 +#define YYERROR do \ + { \ + yylerrsp = yylsp; \ + *++yylerrsp = yyloc; \ + goto yyerrlab1; \ + } \ + while (0) + /* Like YYERROR except do call yyerror. This remains here temporarily to ease the transition to the new meaning of YYERROR, for GCC. @@ -776,9 +783,9 @@ yy_reduce_print (yyrule) #endif { int yyi; - unsigned int yylineno = yyrline[yyrule]; + unsigned int yylno = yyrline[yyrule]; YYFPRINTF (stderr, "Reducing stack by rule %d (line %u), ", - yyrule - 1, yylineno); + yyrule - 1, yylno); /* Print the symbols being reduced, and their result. */ for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++) YYFPRINTF (stderr, "%s ", yytname [yyrhs[yyi]]); @@ -1032,6 +1039,7 @@ YYLTYPE yylloc; YYLTYPE yylsa[YYINITDEPTH]; YYLTYPE *yyls = yylsa; YYLTYPE *yylsp; + YYLTYPE *yylerrsp; #define YYPOPSTACK (yyvsp--, yyssp--, yylsp--) @@ -1248,109 +1256,109 @@ yyreduce: switch (yyn) { case 6: -#line 175 "parse-gram.y" +#line 176 "parse-gram.y" { prologue_augment (yyvsp[0].chars, yylsp[0]); } break; case 7: -#line 176 "parse-gram.y" +#line 177 "parse-gram.y" { debug_flag = 1; } break; case 8: -#line 177 "parse-gram.y" +#line 178 "parse-gram.y" { muscle_insert (yyvsp[-1].chars, yyvsp[0].chars); } break; case 9: -#line 178 "parse-gram.y" +#line 179 "parse-gram.y" { defines_flag = 1; } break; case 10: -#line 179 "parse-gram.y" +#line 180 "parse-gram.y" { error_verbose = 1; } break; case 11: -#line 180 "parse-gram.y" +#line 181 "parse-gram.y" { expected_conflicts = yyvsp[0].integer; } break; case 12: -#line 181 "parse-gram.y" +#line 182 "parse-gram.y" { spec_file_prefix = yyvsp[0].chars; } break; case 13: -#line 182 "parse-gram.y" +#line 183 "parse-gram.y" { glr_parser = 1; } break; case 14: -#line 183 "parse-gram.y" +#line 184 "parse-gram.y" { add_param ("lex_param", yyvsp[0].chars, yylsp[0]); } break; case 15: -#line 184 "parse-gram.y" +#line 185 "parse-gram.y" { locations_flag = 1; } break; case 16: -#line 185 "parse-gram.y" +#line 186 "parse-gram.y" { spec_name_prefix = yyvsp[0].chars; } break; case 17: -#line 186 "parse-gram.y" +#line 187 "parse-gram.y" { no_lines_flag = 1; } break; case 18: -#line 187 "parse-gram.y" +#line 188 "parse-gram.y" { spec_outfile = yyvsp[0].chars; } break; case 19: -#line 188 "parse-gram.y" +#line 189 "parse-gram.y" { add_param ("parse_param", yyvsp[0].chars, yylsp[0]); } break; case 20: -#line 189 "parse-gram.y" +#line 190 "parse-gram.y" { pure_parser = 1; } break; case 21: -#line 190 "parse-gram.y" +#line 191 "parse-gram.y" { skeleton = yyvsp[0].chars; } break; case 22: -#line 191 "parse-gram.y" +#line 192 "parse-gram.y" { token_table_flag = 1; } break; case 23: -#line 192 "parse-gram.y" - { report_flag = 1; } +#line 193 "parse-gram.y" + { report_flag = report_states; } break; case 24: -#line 193 "parse-gram.y" +#line 194 "parse-gram.y" { yacc_flag = 1; } break; case 28: -#line 201 "parse-gram.y" +#line 202 "parse-gram.y" { grammar_start_symbol_set (yyvsp[0].symbol, yylsp[0]); } break; case 29: -#line 205 "parse-gram.y" +#line 206 "parse-gram.y" { typed = 1; MUSCLE_INSERT_INT ("stype_line", yylsp[0].start.line); @@ -1359,7 +1367,7 @@ yyreduce: break; case 30: -#line 211 "parse-gram.y" +#line 212 "parse-gram.y" { symbol_list *list; for (list = yyvsp[0].list; list; list = list->next) @@ -1369,7 +1377,7 @@ yyreduce: break; case 31: -#line 218 "parse-gram.y" +#line 219 "parse-gram.y" { symbol_list *list; for (list = yyvsp[0].list; list; list = list->next) @@ -1379,12 +1387,12 @@ yyreduce: break; case 32: -#line 227 "parse-gram.y" +#line 228 "parse-gram.y" { current_class = nterm_sym; } break; case 33: -#line 228 "parse-gram.y" +#line 229 "parse-gram.y" { current_class = unknown_sym; current_type = NULL; @@ -1392,12 +1400,12 @@ yyreduce: break; case 34: -#line 232 "parse-gram.y" +#line 233 "parse-gram.y" { current_class = token_sym; } break; case 35: -#line 233 "parse-gram.y" +#line 234 "parse-gram.y" { current_class = unknown_sym; current_type = NULL; @@ -1405,7 +1413,7 @@ yyreduce: break; case 36: -#line 238 "parse-gram.y" +#line 239 "parse-gram.y" { symbol_list *list; for (list = yyvsp[0].list; list; list = list->next) @@ -1415,7 +1423,7 @@ yyreduce: break; case 37: -#line 248 "parse-gram.y" +#line 249 "parse-gram.y" { symbol_list *list; ++current_prec; @@ -1430,49 +1438,49 @@ yyreduce: break; case 38: -#line 262 "parse-gram.y" +#line 263 "parse-gram.y" { yyval.assoc = left_assoc; } break; case 39: -#line 263 "parse-gram.y" +#line 264 "parse-gram.y" { yyval.assoc = right_assoc; } break; case 40: -#line 264 "parse-gram.y" +#line 265 "parse-gram.y" { yyval.assoc = non_assoc; } break; case 41: -#line 268 "parse-gram.y" +#line 269 "parse-gram.y" { current_type = NULL; } break; case 42: -#line 269 "parse-gram.y" +#line 270 "parse-gram.y" { current_type = yyvsp[0].uniqstr; } break; case 43: -#line 275 "parse-gram.y" +#line 276 "parse-gram.y" { yyval.list = symbol_list_new (yyvsp[0].symbol, yylsp[0]); } break; case 44: -#line 276 "parse-gram.y" +#line 277 "parse-gram.y" { yyval.list = symbol_list_prepend (yyvsp[-1].list, yyvsp[0].symbol, yylsp[0]); } break; case 45: -#line 282 "parse-gram.y" +#line 283 "parse-gram.y" { current_type = yyvsp[0].uniqstr; } break; case 46: -#line 286 "parse-gram.y" +#line 287 "parse-gram.y" { symbol_class_set (yyvsp[0].symbol, current_class, yylsp[0]); symbol_type_set (yyvsp[0].symbol, current_type, yylsp[0]); @@ -1480,7 +1488,7 @@ yyreduce: break; case 47: -#line 291 "parse-gram.y" +#line 292 "parse-gram.y" { symbol_class_set (yyvsp[-1].symbol, current_class, yylsp[-1]); symbol_type_set (yyvsp[-1].symbol, current_type, yylsp[-1]); @@ -1489,7 +1497,7 @@ yyreduce: break; case 48: -#line 297 "parse-gram.y" +#line 298 "parse-gram.y" { symbol_class_set (yyvsp[-1].symbol, current_class, yylsp[-1]); symbol_type_set (yyvsp[-1].symbol, current_type, yylsp[-1]); @@ -1498,7 +1506,7 @@ yyreduce: break; case 49: -#line 303 "parse-gram.y" +#line 304 "parse-gram.y" { symbol_class_set (yyvsp[-2].symbol, current_class, yylsp[-2]); symbol_type_set (yyvsp[-2].symbol, current_type, yylsp[-2]); @@ -1508,7 +1516,7 @@ yyreduce: break; case 55: -#line 332 "parse-gram.y" +#line 333 "parse-gram.y" { if (yacc_flag) complain_at (yyloc, _("POSIX forbids declarations in the grammar")); @@ -1516,74 +1524,74 @@ yyreduce: break; case 56: -#line 337 "parse-gram.y" +#line 338 "parse-gram.y" { yyerrok; } break; case 58: -#line 344 "parse-gram.y" +#line 345 "parse-gram.y" { current_lhs = yyvsp[0].symbol; current_lhs_location = yylsp[0]; } break; case 60: -#line 348 "parse-gram.y" +#line 349 "parse-gram.y" { grammar_rule_end (yylsp[0]); } break; case 61: -#line 349 "parse-gram.y" +#line 350 "parse-gram.y" { grammar_rule_end (yylsp[0]); } break; case 62: -#line 354 "parse-gram.y" +#line 355 "parse-gram.y" { grammar_rule_begin (current_lhs, current_lhs_location); } break; case 63: -#line 356 "parse-gram.y" +#line 357 "parse-gram.y" { grammar_current_rule_symbol_append (yyvsp[0].symbol, yylsp[0]); } break; case 64: -#line 358 "parse-gram.y" +#line 359 "parse-gram.y" { grammar_current_rule_action_append (yyvsp[0].chars, yylsp[0]); } break; case 65: -#line 360 "parse-gram.y" +#line 361 "parse-gram.y" { grammar_current_rule_prec_set (yyvsp[0].symbol, yylsp[0]); } break; case 66: -#line 362 "parse-gram.y" +#line 363 "parse-gram.y" { grammar_current_rule_dprec_set (yyvsp[0].integer, yylsp[0]); } break; case 67: -#line 364 "parse-gram.y" +#line 365 "parse-gram.y" { grammar_current_rule_merge_set (yyvsp[0].uniqstr, yylsp[0]); } break; case 68: -#line 368 "parse-gram.y" +#line 369 "parse-gram.y" { yyval.symbol = yyvsp[0].symbol; } break; case 69: -#line 369 "parse-gram.y" +#line 370 "parse-gram.y" { yyval.symbol = yyvsp[0].symbol; } break; case 70: -#line 374 "parse-gram.y" +#line 375 "parse-gram.y" { yyval.chars = yyvsp[0].chars; } break; case 71: -#line 380 "parse-gram.y" +#line 381 "parse-gram.y" { yyval.symbol = symbol_get (yyvsp[0].chars, yylsp[0]); symbol_class_set (yyval.symbol, token_sym, yylsp[0]); @@ -1591,7 +1599,7 @@ yyreduce: break; case 72: -#line 389 "parse-gram.y" +#line 390 "parse-gram.y" { yyval.chars = yyvsp[0].chars + 1; yyval.chars[strlen (yyval.chars) - 1] = '\0'; @@ -1599,7 +1607,7 @@ yyreduce: break; case 74: -#line 398 "parse-gram.y" +#line 399 "parse-gram.y" { epilogue_augment (yyvsp[0].chars, yylsp[0]); scanner_last_string_free (); @@ -1609,8 +1617,8 @@ yyreduce: } -/* Line 991 of yacc.c. */ -#line 1613 "parse-gram.c" +/* Line 999 of yacc.c. */ +#line 1622 "parse-gram.c" yyvsp -= yylen; yyssp -= yylen; @@ -1651,18 +1659,33 @@ yyerrlab: { YYSIZE_T yysize = 0; int yytype = YYTRANSLATE (yychar); + const char* yyprefix; char *yymsg; - int yyx, yycount; + int yyx; - yycount = 0; /* Start YYX at -YYN if negative to avoid negative indexes in YYCHECK. */ - for (yyx = yyn < 0 ? -yyn : 0; - yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++) + int yyxbegin = yyn < 0 ? -yyn : 0; + + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = YYLAST - yyn; + int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + int yycount = 0; + + yyprefix = ", expecting "; + for (yyx = yyxbegin; yyx < yyxend; ++yyx) if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) - yysize += yystrlen (yytname[yyx]) + 15, yycount++; - yysize += yystrlen ("syntax error, unexpected ") + 1; - yysize += yystrlen (yytname[yytype]); + { + yysize += yystrlen (yyprefix) + yystrlen (yytname [yyx]); + yycount += 1; + if (yycount == 5) + { + yysize = 0; + break; + } + } + yysize += (sizeof ("syntax error, unexpected ") + + yystrlen (yytname[yytype])); yymsg = (char *) YYSTACK_ALLOC (yysize); if (yymsg != 0) { @@ -1671,16 +1694,13 @@ yyerrlab: if (yycount < 5) { - yycount = 0; - for (yyx = yyn < 0 ? -yyn : 0; - yyx < (int) (sizeof (yytname) / sizeof (char *)); - yyx++) + yyprefix = ", expecting "; + for (yyx = yyxbegin; yyx < yyxend; ++yyx) if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) { - const char *yyq = ! yycount ? ", expecting " : " or "; - yyp = yystpcpy (yyp, yyq); + yyp = yystpcpy (yyp, yyprefix); yyp = yystpcpy (yyp, yytname[yyx]); - yycount++; + yyprefix = " or "; } } yyerror (yymsg); @@ -1694,6 +1714,8 @@ yyerrlab: yyerror ("syntax error"); } + yylerrsp = yylsp; + if (yyerrstatus == 3) { /* If just tried and failed to reuse lookahead token after an @@ -1717,6 +1739,7 @@ yyerrlab: YYDSYMPRINTF ("Error: discarding", yytoken, &yylval, &yylloc); yydestruct (yytoken, &yylval, &yylloc); yychar = YYEMPTY; + *++yylerrsp = yylloc; } /* Else will try to reuse lookahead token after shifting the error @@ -1762,7 +1785,8 @@ yyerrlab1: YYDPRINTF ((stderr, "Shifting error token, ")); *++yyvsp = yylval; - *++yylsp = yylloc; + YYLLOC_DEFAULT (yyloc, yylsp, (yylerrsp - yylsp)); + *++yylsp = yyloc; yystate = yyn; goto yynewstate; @@ -1801,7 +1825,7 @@ yyreturn: } -#line 404 "parse-gram.y" +#line 405 "parse-gram.y" @@ -1814,8 +1838,8 @@ static YYLTYPE lloc_default (YYLTYPE const *rhs, int n) { int i; - YYLTYPE r; - r.start = r.end = rhs[n].end; + YYLTYPE loc; + loc.start = loc.end = rhs[n].end; /* Ignore empty nonterminals the start of the the right-hand side. Do not bother to ignore them at the end of the right-hand side, @@ -1823,11 +1847,11 @@ lloc_default (YYLTYPE const *rhs, int n) for (i = 1; i <= n; i++) if (! equal_boundaries (rhs[i].start, rhs[i].end)) { - r.start = rhs[i].start; + loc.start = rhs[i].start; break; } - return r; + return loc; }