X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/cf44a9aea745a5b70acb38160249a3f9a8918680..2e047461253970124582c3b9dca7322fd675e921:/data/bison.simple diff --git a/data/bison.simple b/data/bison.simple index d52c2e09..8b5eda87 100644 --- a/data/bison.simple +++ b/data/bison.simple @@ -6,8 +6,7 @@ m4_divert(-1) -*- C -*- m4_define([b4_sint_type], [m4_if(m4_eval([$1 <= 127]), [1], [signed char], m4_eval([$1 <= 32767]), [1], [signed short], - m4_eval([$1 <= 2147483647]), [1], [signed int], - [m4_fatal([no signed int type for $1])])]) + [signed int])]) # b4_uint_type(MAX) @@ -16,8 +15,37 @@ m4_define([b4_sint_type], m4_define([b4_uint_type], [m4_if(m4_eval([$1 <= 255]), [1], [unsigned char], m4_eval([$1 <= 65535]), [1], [unsigned short], - m4_eval([$1 <= 4294967295]), [1], [unsigned int], - [m4_fatal([no unsigned int type for $1])])]) + [unsigned int])]) + + +# b4_lhs_value([TYPE]) +# -------------------- +# Expansion of $$. +m4_define([b4_lhs_value], +[yyval[]m4_ifval([$1], [.$1])]) + + +# b4_rhs_value(RULE-LENGTH, NUM, [TYPE]) +# -------------------------------------- +# Expansion of $NUM, where the current rule has RULE-LENGTH +# symbols on RHS. +m4_define([b4_rhs_value], +[yyvsp@<:@m4_eval([$2 - $1])@:>@m4_ifval([$3], [.$3])]) + + +# b4_lhs_location() +# ----------------- +# Expansion of @$. +m4_define([b4_lhs_location], +[yyloc]) + + +# b4_rhs_location(RULE-LENGTH, NUM) +# --------------------------------- +# Expansion of @NUM, where the current rule has RULE-LENGTH symbols +# on RHS. +m4_define([b4_rhs_location], +[yylsp@<:@m4_eval([$2 - $1])@:>@]) m4_define_default([b4_input_suffix], [.y]) @@ -40,19 +68,43 @@ m4_define_default([b4_header_guard], [[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]], [_])]) -# b4_token_defines(TOKEN-NAME, TOKEN-NUMBER) -# ------------------------------------------ +# b4_token_define(TOKEN-NAME, TOKEN-NUMBER) +# ----------------------------------------- # Output the definition of this token as #define. m4_define([b4_token_define], [#define $1 $2 ]) +# b4_token_enum(TOKEN-NAME, TOKEN-NUMBER) +# --------------------------------------- +# Output the definition of this token as an enum. +m4_define([b4_token_enum], +[$1 = $2]) + + # b4_token_defines(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER) # ------------------------------------------------------- -# Output the definition of the tokens as #define. +# Output the definition of the tokens (if there are) as enums and #define. m4_define([b4_token_defines], -[m4_map([b4_token_define], [$@])]) +[m4_if([$@], [[]], [], +[/* Tokens. */ +#ifndef YYTOKENTYPE +# if defined (__STDC__) || defined (__cplusplus) + /* Put the tokens into the symbol table, so that GDB and other debuggers + know about them. */ + enum yytokentype { +m4_map_sep([ b4_token_enum], [, +], + [$@]) + }; +# endif + /* POSIX requires `int' for tokens in interfaces. */ +# define YYTOKENTYPE int +#endif /* !YYTOKENTYPE */ +m4_map([b4_token_define], [$@]) +]) +]) m4_divert(0)dnl @@ -86,8 +138,8 @@ m4_divert(0)dnl /* This is the parser code that is written into each bison parser when the %semantic_parser declaration is not specified in the grammar. - It was written by Richard Stallman by simplifying the hairy parser - used when %semantic_parser is specified. */ + It was written by Richard Stallman by simplifying the original so + called ``semantic'' parser. */ /* All symbols defined below should begin with yy or YY, to avoid infringing on user name space. This should be done even for local @@ -120,8 +172,10 @@ m4_if(b4_prefix[], [yy], [], #endif ]) -/* Copy the user declarations. */ -b4_prologue +/* Copy the first part of user declarations. */ +b4_pre_prologue + +b4_token_defines(b4_tokens) /* Enabling traces. */ #ifndef YYDEBUG @@ -142,6 +196,7 @@ m4_ifdef([b4_stype_line], ])dnl typedef b4_stype yystype; # define YYSTYPE yystype +# define YYSTYPE_IS_TRIVIAL 1 #endif #ifndef YYLTYPE @@ -153,8 +208,12 @@ typedef struct yyltype int last_column; } yyltype; # define YYLTYPE b4_ltype +# define YYLTYPE_IS_TRIVIAL 1 #endif +/* Copy the second part of user declarations. */ +b4_post_prologue + /* Line __line__ of __file__. */ #line __oline__ "__ofile__" @@ -231,7 +290,7 @@ union yyalloc { \ register YYSIZE_T yyi; \ for (yyi = 0; yyi < (Count); yyi++) \ - (To)[yyi] = (From)[yyi]; \ + (To)[[yyi]] = (From)[[yyi]]; \ } \ while (0) # endif @@ -255,9 +314,6 @@ union yyalloc #endif -/* Tokens. */ -b4_token_defines(b4_tokens) - /* YYFINAL -- State number of the termination state. */ #define YYFINAL b4_final #define YYFLAG b4_flag @@ -276,12 +332,11 @@ b4_token_defines(b4_tokens) #define YYUNDEFTOK b4_undef_token_number #define YYMAXUTOK b4_user_token_number_max -typedef b4_uint_type(b4_token_number_max) yy_token_number_type; #define YYTRANSLATE(X) \ ((unsigned)(X) <= YYMAXUTOK ? yytranslate[[X]] : YYUNDEFTOK) /* YYTRANSLATE[[YYLEX]] -- Bison symbol number corresponding to YYLEX. */ -static const yy_token_number_type yytranslate[[]] = +static const b4_uint_type(b4_translate_max) yytranslate[[]] = { b4_translate }; @@ -289,26 +344,25 @@ static const yy_token_number_type yytranslate[[]] = #if YYDEBUG /* YYPRHS[[YYN]] -- Index of the first RHS symbol of rule number YYN in YYRHS. */ -static const short yyprhs[[]] = +static const b4_uint_type(b4_prhs_max) yyprhs[[]] = { b4_prhs }; /* YYRHS -- A `-1'-separated list of the rules' RHS. */ -typedef b4_sint_type(b4_rhs_number_max) yyrhs_t; -static const yyrhs_t yyrhs[[]] = +static const b4_sint_type(b4_rhs_max) yyrhs[[]] = { b4_rhs }; /* YYRLINE[[YYN]] -- source line where rule number YYN was defined. */ -static const short yyrline[[]] = +static const b4_uint_type(b4_rline_max) yyrline[[]] = { b4_rline }; #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[[]] = @@ -317,27 +371,28 @@ 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 }; /* YYR1[[YYN]] -- Symbol number of symbol that rule YYN derives. */ -static const yy_token_number_type yyr1[[]] = +static const b4_uint_type(b4_r1_max) yyr1[[]] = { b4_r1 }; /* YYR2[[YYN]] -- Number of symbols composing right hand side of rule YYN. */ -static const short yyr2[[]] = +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 @@ -375,6 +430,14 @@ static const short yycheck[[]] = b4_check }; +#if YYDEBUG +/* 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 +}; +#endif #if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__) # define YYSIZE_T __SIZE_TYPE__ @@ -430,16 +493,14 @@ while (0) #define YYERRCODE 256 /* YYLLOC_DEFAULT -- Compute the default location (before the actions - are run). - - When YYLLOC_DEFAULT is run, CURRENT is set the location of the - first token. By default, to implement support for ranges, extend - its range to the last symbol. */ + are run). */ #ifndef YYLLOC_DEFAULT -# define YYLLOC_DEFAULT(Current, Rhs, N) \ - Current.last_line = Rhs[[N]].last_line; \ - Current.last_column = Rhs[[N]].last_column; +# define YYLLOC_DEFAULT(Current, Rhs, N) \ + Current.first_line = Rhs[[1]].first_line; \ + Current.first_column = Rhs[[1]].first_column; \ + Current.last_line = Rhs[[N]].last_line; \ + Current.last_column = Rhs[[N]].last_column; #endif /* YYLEX -- calling `yylex' with the right arguments. */ @@ -921,9 +982,7 @@ yyreduce: yyval = yyvsp[1-yylen]; #if YYLSP_NEEDED - /* Similarly for the default location. Let the user run additional - commands if for instance locations are ranges. */ - yyloc = yylsp[1-yylen]; + /* Default location. */ YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen); #endif @@ -1070,71 +1129,61 @@ 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; + 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;