X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/cf44a9aea745a5b70acb38160249a3f9a8918680..83ccf991a6b09a2f93e97dab936f6d3574e27d68:/data/bison.simple diff --git a/data/bison.simple b/data/bison.simple index d52c2e09..1c153a0a 100644 --- a/data/bison.simple +++ b/data/bison.simple @@ -20,6 +20,36 @@ m4_define([b4_uint_type], [m4_fatal([no unsigned int type for $1])])]) +# 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]) m4_define_default([b4_output_parser_suffix], @@ -40,19 +70,39 @@ 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], +[enum $1 = $2]) + + # b4_token_defines(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER) # ------------------------------------------------------- # Output the definition of the tokens as #define. m4_define([b4_token_defines], -[m4_map([b4_token_define], [$@])]) +[#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], [, +], + [$@]) + }; + /* POSIX requires `int' for tokens in interfaces. */ +# define YYTOKENTYPE int +# endif +#endif +m4_map([b4_token_define], [$@])]) m4_divert(0)dnl @@ -86,8 +136,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 +170,8 @@ m4_if(b4_prefix[], [yy], [], #endif ]) -/* Copy the user declarations. */ -b4_prologue +/* Copy the first part of user declarations. */ +b4_pre_prologue /* Enabling traces. */ #ifndef YYDEBUG @@ -142,6 +192,7 @@ m4_ifdef([b4_stype_line], ])dnl typedef b4_stype yystype; # define YYSTYPE yystype +# define YYSTYPE_IS_TRIVIAL 1 #endif #ifndef YYLTYPE @@ -153,8 +204,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 +286,7 @@ union yyalloc { \ register YYSIZE_T yyi; \ for (yyi = 0; yyi < (Count); yyi++) \ - (To)[yyi] = (From)[yyi]; \ + (To)[[yyi]] = (From)[[yyi]]; \ } \ while (0) # endif @@ -430,16 +485,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 +974,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