X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/c0c9ea051b0fadc4265d0b1a78c3a2ed0eca8fca..9280d3ef893b90b36c89fa7737512f2d640e41d9:/data/bison.simple diff --git a/data/bison.simple b/data/bison.simple index ad42a919..80314c0c 100644 --- a/data/bison.simple +++ b/data/bison.simple @@ -68,6 +68,10 @@ m4_define_default([b4_header_guard], [[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]], [_])]) +## ------------------------- ## +## Assigning token numbers. ## +## ------------------------- ## + # b4_token_define(TOKEN-NAME, TOKEN-NUMBER) # ----------------------------------------- # Output the definition of this token as #define. @@ -175,6 +179,8 @@ m4_if(b4_prefix[], [yy], [], /* Copy the first part of user declarations. */ b4_pre_prologue +b4_token_defines(b4_tokens) + /* Enabling traces. */ #ifndef YYDEBUG # define YYDEBUG b4_debug @@ -189,10 +195,12 @@ b4_pre_prologue #endif #ifndef YYSTYPE -m4_ifdef([b4_stype_line], +m4_ifdef([b4_stype], [#line b4_stype_line "b4_filename" -])dnl -typedef b4_stype yystype; +typedef union b4_stype yystype; +/* Line __line__ of __file__. */ +#line __oline__ "__ofile__"], +[typedef int yystype;]) # define YYSTYPE yystype # define YYSTYPE_IS_TRIVIAL 1 #endif @@ -312,8 +320,6 @@ union yyalloc #endif -b4_token_defines(b4_tokens) - /* YYFINAL -- State number of the termination state. */ #define YYFINAL b4_final #define YYFLAG b4_flag @@ -362,7 +368,7 @@ static const b4_uint_type(b4_rline_max) yyrline[[]] = }; #endif -#if (YYDEBUG) || YYERROR_VERBOSE +#if YYDEBUG || YYERROR_VERBOSE /* YYTNME[[SYMBOL-NUM]] -- String name of the symbol SYMBOL-NUM. First, the terminals, then, starting at YYNTOKENS, nonterminals. */ static const char *const yytname[[]] = @@ -371,7 +377,8 @@ static const char *const yytname[[]] = }; #endif -/* YYTOKNUM[[YYN]] -- Index in YYTNAME corresponding to YYLEX. */ +/* YYTOKNUM[[YYLEX-NUM]] -- Internal token number corresponding to + token YYLEX-NUM. */ static const short yytoknum[[]] = { b4_toknum @@ -389,9 +396,9 @@ static const b4_uint_type(b4_r2_max) yyr2[[]] = b4_r2 }; -/* YYDEFACT[[S]] -- default rule to reduce with in state S when YYTABLE - doesn't specify something else to do. Zero means the default is an - error. */ +/* YYDEFACT[[STATE-NAME]] -- Default rule to reduce with in state + STATE-NUM when YYTABLE doesn't specify something else to do. Zero + means the default is an error. */ static const short yydefact[[]] = { b4_defact @@ -429,6 +436,12 @@ static const short yycheck[[]] = b4_check }; +/* YYSTOS[[STATE-NUM]] -- The (internal number of the) accessing + symbol of state STATE-NUM. */ +static const b4_uint_type(b4_stos_max) yystos[[]] = +{ + b4_stos +}; #if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__) # define YYSIZE_T __SIZE_TYPE__ @@ -638,6 +651,7 @@ int yyparse (void *); int yyparse (void); # endif #endif +static void yydestructor (int symbol_type, YYSTYPE symbol_value); /* YY_DECL_VARIABLES -- depending whether we use a pure parser, variables are global, or local to YYPARSE. */ @@ -1112,6 +1126,7 @@ yyerrlab1: YYABORT; YYDPRINTF ((stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1])); + yydestructor (yychar1, yylval); yychar = YYEMPTY; } @@ -1120,71 +1135,62 @@ yyerrlab1: yyerrstatus = 3; /* Each real token shifted decrements this. */ - goto yyerrhandle; - + for (;;) + { + yyn = yypact[yystate]; + if (yyn != YYFLAG) + { + yyn += YYTERROR; + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) + { + yyn = yytable[yyn]; + if (0 < yyn) + break; + } + } -/*-------------------------------------------------------------------. -| yyerrdefault -- current state does not do anything special for the | -| error token. | -`-------------------------------------------------------------------*/ -yyerrdefault: -#if 0 - /* This is wrong; only states that explicitly want error tokens - should shift them. */ + /* Pop the current state because it cannot handle the error token. */ + if (yyssp == yyss) + YYABORT; - /* If its default is to accept any token, ok. Otherwise pop it. */ - yyn = yydefact[yystate]; - if (yyn) - goto yydefault; +#if YYDEBUG + if (yydebug) + { + if (yystos[yystate] < YYNTOKENS) + { + YYFPRINTF (stderr, "Error: popping token %d (%s", + yytoknum[yystos[yystate]], yytname[yystos[yystate]]); +# ifdef YYPRINT + YYPRINT (stderr, yytoknum[yystos[yystate]], *yyvsp); +# endif + YYFPRINTF (stderr, ")\n"); + } + else + { + YYFPRINTF (stderr, "Error: popping nonterminal (%s)\n", + yytname[yystos[yystate]]); + } + } #endif - -/*---------------------------------------------------------------. -| yyerrpop -- pop the current state because it cannot handle the | -| error token. | -`---------------------------------------------------------------*/ -yyerrpop: - if (yyssp == yyss) - YYABORT; - yyvsp--; - yystate = *--yyssp; + yydestructor (yystos[yystate], *yyvsp); + yyvsp--; + yystate = *--yyssp; #if YYLSP_NEEDED - yylsp--; + yylsp--; #endif #if YYDEBUG - if (yydebug) - { - short *yyssp1 = yyss - 1; - YYFPRINTF (stderr, "Error: state stack now"); - while (yyssp1 != yyssp) - YYFPRINTF (stderr, " %d", *++yyssp1); - YYFPRINTF (stderr, "\n"); - } + if (yydebug) + { + short *yyssp1 = yyss - 1; + YYFPRINTF (stderr, "Error: state stack now"); + while (yyssp1 != yyssp) + YYFPRINTF (stderr, " %d", *++yyssp1); + YYFPRINTF (stderr, "\n"); + } #endif - -/*--------------. -| yyerrhandle. | -`--------------*/ -yyerrhandle: - yyn = yypact[yystate]; - if (yyn == YYFLAG) - goto yyerrdefault; - - yyn += YYTERROR; - if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR) - goto yyerrdefault; - - yyn = yytable[yyn]; - if (yyn < 0) - { - if (yyn == YYFLAG) - goto yyerrpop; - yyn = -yyn; - goto yyreduce; } - else if (yyn == 0) - goto yyerrpop; if (yyn == YYFINAL) YYACCEPT; @@ -1230,6 +1236,39 @@ yyreturn: return yyresult; ]} +/* Release the memory associated to SYMBOL-NUMBER. */ +m4_divert_push([KILL])# M4 code. +# b4_eval +# ------- +# FIXME: This is really wrong, we no longer guarantee we don't evaluate +# the user's input. This demonstrates that decoding actions (BRACED_CODE) +# ought to be done when output, not when read. +m4_define([b4_eval], +[$*]) + +# b4_symbol_destructor(SYMBOL-NUMBER, DESTRUCTOR, TYPE-NAME) +# ---------------------------------------------------------- +m4_define([b4_symbol_destructor], +[m4_pushdef([b4_dollar_dollar], [symbol_value.$3])dnl + case $1: + b4_eval($2); + break; +m4_popdef([b4_dollar_dollar])]) + +m4_divert_pop([KILL])dnl# End of M4 code. +static void +yydestructor (int symbol_type, YYSTYPE symbol_value) +{ + switch (symbol_type) + { +m4_map([b4_symbol_destructor], m4_defn([b4_symbol_destructors]))dnl + default: + YYDPRINTF ((stderr, "yydestructor: unknown symbol type: %s\n", + yytname[[symbol_type]])); + break; + } +} + b4_epilogue m4_if(b4_defines_flag, 0, [], [#output "b4_output_header_name" @@ -1239,11 +1278,12 @@ m4_if(b4_defines_flag, 0, [], b4_token_defines(b4_tokens) #ifndef YYSTYPE -m4_ifdef([b4_stype_line], +m4_ifdef([b4_stype], [#line b4_stype_line "b4_filename" -])dnl -typedef b4_stype -yystype; +typedef union b4_stype yystype; +/* Line __line__ of __file__. */ +#line __oline__ "__ofile__"], +[typedef int yystype;]) # define YYSTYPE yystype #endif