# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
# 02111-1307 USA
+
+
+## ---------------- ##
+## Default values. ##
+## ---------------- ##
+
+# Stack parameters.
+m4_define_default([b4_stack_depth_max], [10000])
+m4_define_default([b4_stack_depth_init], [200])
+
+# Location type.
+m4_define_default([b4_location_type], [yyltype])
+
+
+## ------------------------ ##
+## Pure/impure interfaces. ##
+## ------------------------ ##
+
+
+# b4_pure_if(IF-TRUE, IF-FALSE)
+# -----------------------------
+# Expand IF-TRUE, if %pure-parser and %parse-param, IF-FALSE otherwise.
+m4_define([b4_Pure_if],
+[b4_pure_if([m4_ifset([b4_parse_param],
+ [$1], [$2])],
+ [$2])])
+
+
+# b4_yyerror_args
+# ---------------
+# Arguments passed to yyerror: user args plus yylloc.
+m4_define([b4_yyerror_args],
+[b4_Pure_if([b4_location_if([&yylloc, ])])dnl
+m4_ifset([b4_parse_param], [b4_c_args(b4_parse_param), ])])
+
+
+# b4_lex_param
+# ------------
+# Accumule in b4_lex_param all the yylex arguments.
+# b4_lex_param arrives quoted twice, but we want to keep only one level.
+m4_define([b4_lex_param],
+m4_dquote(b4_pure_if([[[[YYSTYPE *]], [[&yylval]]][]dnl
+b4_location_if([, [[YYLTYPE *], [&yylloc]]])])dnl
+m4_ifdef([b4_lex_param], [, ]b4_lex_param)))
+
+
+
+## ------------ ##
+## Data Types. ##
+## ------------ ##
+
+# b4_int_type(MIN, MAX)
+# ---------------------
+# Return the smallest int type able to handle numbers ranging from
+# MIN to MAX (included). We overwrite the version from c.m4 which relies
+# on "signed char" which is not portable to old K&R compilers.
+m4_define([b4_int_type],
+[m4_if(b4_ints_in($@, [0], [255]), [1], [unsigned char],
+ b4_ints_in($@, [-128], [127]), [1], [yysigned_char],
+
+ b4_ints_in($@, [0], [65535]), [1], [unsigned short],
+ b4_ints_in($@, [-32768], [32767]), [1], [short],
+
+ m4_eval([0 <= $1]), [1], [unsigned int],
+
+ [int])])
+
+
+## ----------------- ##
+## Semantic Values. ##
+## ----------------- ##
+
+
# b4_lhs_value([TYPE])
# --------------------
# Expansion of $<TYPE>$.
# Expansion of $<TYPE>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])])
+[yyvsp@{m4_eval([$2 - $1])@}m4_ifval([$3], [.$3])])
## Locations. ##
## ----------- ##
-# b4_location_if(IF-TRUE, IF-FALSE)
-# ---------------------------------
-# Expand IF-TRUE, if locations are used, IF-FALSE otherwise.
-m4_define([b4_location_if],
-[m4_if(b4_locations_flag, [1],
- [$1],
- [$2])])
-
-
# b4_lhs_location()
# -----------------
# Expansion of @$.
# Expansion of @NUM, where the current rule has RULE-LENGTH symbols
# on RHS.
m4_define([b4_rhs_location],
-[yylsp@<:@m4_eval([$2 - $1])@:>@])
-
-
-
-## -------------- ##
-## %pure-parser. ##
-## -------------- ##
-
-# b4_pure_if(IF-TRUE, IF-FALSE)
-# -----------------------------
-# Expand IF-TRUE, if %pure-parser, IF-FALSE otherwise.
-m4_define([b4_pure_if],
-[m4_if(b4_pure, [1],
- [$1],
- [$2])])
-
-
-## ------------------- ##
-## Output file names. ##
-## ------------------- ##
-
-m4_define_default([b4_input_suffix], [.y])
-
-m4_define_default([b4_output_parser_suffix],
-[m4_translit(b4_input_suffix, [yY], [cC])])
-
-m4_define_default([b4_output_parser_name],
-[b4_output_prefix[]b4_output_infix[]b4_output_parser_suffix[]])
-
-
-m4_define_default([b4_output_header_suffix],
-[m4_translit(b4_input_suffix, [yY], [hH])])
-
-m4_define_default([b4_output_header_name],
-[b4_output_prefix[]b4_output_infix[]b4_output_header_suffix[]])
-
-m4_define_default([b4_header_guard],
- [m4_bpatsubst(m4_toupper([BISON_]b4_output_header_name),
- [[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]], [_])])
+[yylsp@{m4_eval([$2 - $1])@}])
## Defining symbol actions, e.g., printers and destructors. ##
## --------------------------------------------------------- ##
-# b4_symbol_actions(FILENAME, LINENO,
-# SYMBOL-TAG, SYMBOL-NUM,
-# SYMBOL-ACTION, SYMBOL-TYPENAME)
-# -------------------------------------------------
-m4_define([b4_symbol_actions],
-[m4_pushdef([b4_dollar_dollar], [yyvalue.$6])dnl
-m4_pushdef([b4_at_dollar], [yylocation])dnl
- case $4: /* $3 */
-#line $2 "$1"
- $5;
-#line __oline__ "__ofile__"
- break;
-m4_popdef([b4_at_dollar])dnl
-m4_popdef([b4_dollar_dollar])dnl
-])
-
-
-
+# We do want M4 expansion after # for CPP macros.
+m4_changecom()
m4_divert(0)dnl
-#output "b4_output_parser_name"
+@output @output_parser_name@
b4_copyright([Skeleton parser for Yacc-like parsing with Bison],
[1984, 1989, 1990, 2000, 2001, 2002])
define necessary library symbols; they are noted "INFRINGES ON
USER NAME SPACE" below. */
-/* Identify Bison output. */
-#define YYBISON 1
-
-/* Pure parsers. */
-#define YYPURE b4_pure
-
-/* Using locations. */
-#define YYLSP_NEEDED b4_locations_flag
-
+b4_identification
m4_if(b4_prefix[], [yy], [],
[/* If NAME_PREFIX is specified substitute the variables and functions
names. */
#ifndef YYSTYPE
m4_ifdef([b4_stype],
-[#line b4_stype_line "b4_filename"
+[b4_syncline([b4_stype_line], [b4_filename])
typedef union b4_stype yystype;
/* Line __line__ of __file__. */
-#line __oline__ "__ofile__"],
+b4_syncline([@oline@], [@ofile@])],
[typedef int yystype;])
# define YYSTYPE yystype
# define YYSTYPE_IS_TRIVIAL 1
int last_line;
int last_column;
} yyltype;
-# define YYLTYPE b4_ltype
+# define YYLTYPE b4_location_type
# define YYLTYPE_IS_TRIVIAL 1
#endif
b4_post_prologue
/* Line __line__ of __file__. */
-#line __oline__ "__ofile__"
+b4_syncline([@oline@], [@ofile@])
#if ! defined (yyoverflow) || YYERROR_VERBOSE
#endif
+#if defined (__STDC__) || defined (__cplusplus)
+ typedef signed char yysigned_char;
+#else
+ typedef short yysigned_char;
+#endif
+
/* YYFINAL -- State number of the termination state. */
#define YYFINAL b4_final_state_number
+/* YYLAST -- Last index in YYTABLE. */
#define YYLAST b4_last
/* YYNTOKENS -- Number of terminals. */
/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
#define YYUNDEFTOK b4_undef_token_number
-#define YYMAXUTOK b4_user_token_number_max
+#define YYMAXUTOK b4_user_token_number_max[
-#define YYTRANSLATE(X) \
- ((unsigned)(X) <= YYMAXUTOK ? yytranslate[[X]] : YYUNDEFTOK)
+#define YYTRANSLATE(YYX) \
+ ((YYX <= 0) ? YYEOF : \
+ (unsigned)(YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
-/* YYTRANSLATE[[YYLEX]] -- Bison symbol number corresponding to YYLEX. */
-static const b4_int_type_for([b4_translate]) yytranslate[[]] =
+/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
+static const ]b4_int_type_for([b4_translate])[ yytranslate[] =
{
- b4_translate
+ ]b4_translate
};
#if YYDEBUG
#endif
#define yyerrok (yyerrstatus = 0)
-#define yyclearin (yychar = YYEMPTY)
+#define yyclearin (yytoken = YYEMPTY)
#define YYEMPTY -2
#define YYEOF 0
#define YYBACKUP(Token, Value) \
do \
- if (yychar == YYEMPTY && yylen == 1) \
+ if (yytoken == YYEMPTY && yylen == 1) \
{ \
yychar = (Token); \
yylval = (Value); \
- yychar1 = YYTRANSLATE (yychar); \
+ yytoken = YYTRANSLATE (yychar); \
YYPOPSTACK; \
goto yybackup; \
} \
else \
{ \
- yyerror ("syntax error: cannot back up"); \
+ yyerror (b4_yyerror_args"syntax error: cannot back up"); \
YYERROR; \
} \
while (0)
/* YYLEX -- calling `yylex' with the right arguments. */
-b4_pure_if(
-[#ifdef YYLEX_PARAM
-# define YYLEX yylex (&yylval[]b4_location_if([, &yylloc]), YYLEX_PARAM)
+#ifdef YYLEX_PARAM
+# define YYLEX yylex (b4_pure_if([&yylval[]b4_location_if([, &yylloc]), ])YYLEX_PARAM)
#else
-# define YYLEX yylex (&yylval[]b4_location_if([, &yylloc]))
-#endif],
-[#define YYLEX yylex ()])
+# define YYLEX b4_c_function_call([yylex], [int], b4_lex_param)
+#endif
/* Enable debugging if requested. */
#if YYDEBUG
/* YYINITDEPTH -- initial size of the parser's stacks. */
#ifndef YYINITDEPTH
-# define YYINITDEPTH b4_initdepth
+# define YYINITDEPTH b4_stack_depth_init
#endif
/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
#endif
#ifndef YYMAXDEPTH
-# define YYMAXDEPTH b4_maxdepth
+# define YYMAXDEPTH b4_stack_depth_max
#endif
\f
| Print this symbol on YYOUT. |
`-----------------------------*/
-b4_c_function([yysymprint],
- [static void],
- [[FILE*], [yyout]],
- [[int], [yytype]],
- [[YYSTYPE], [yyvalue]]b4_location_if([,
- [[YYLTYPE], [yylocation]]]))
+b4_c_function_def([yysymprint],
+ [static void],
+ [[FILE *yyout], [yyout]],
+ [[int yytype], [yytype]],
+ [[YYSTYPE yyvalue], [yyvalue]]b4_location_if([,
+ [[YYLTYPE yylocation], [yylocation]]]))
{
/* Pacify ``unused variable'' warnings. */
(void) yyvalue;
}
#endif /* YYDEBUG. */
-
-/*-----------------------------------------------.
-| Release the memory associated to this symbol. |
-`-----------------------------------------------*/
-
-b4_c_function([yydestruct],
- [static void],
- [[int], [yytype]],
- [[YYSTYPE], [yyvalue]]b4_location_if([,
- [[YYLTYPE], [yylocation]]]))
-{
- /* Pacify ``unused variable'' warnings. */
- (void) yyvalue;
-b4_location_if([ (void) yylocation;
-])dnl
-
- switch (yytype)
- {
-m4_map([b4_symbol_actions], m4_defn([b4_symbol_destructors]))dnl
- default:
- break;
- }
-}
-
+b4_yydestruct_generate([b4_c_function_def])
\f
-/* The user can define YYPARSE_PARAM as the name of an argument to be passed
- into yyparse. The argument should have type void *.
- It should actually point to an object.
- Grammar actions can access the variable by casting it
- to the proper pointer type. */
+/* Prevent warnings from -Wmissing-prototypes. */
#ifdef YYPARSE_PARAM
# if defined (__STDC__) || defined (__cplusplus)
-# define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
-# define YYPARSE_PARAM_DECL
-# else
-# define YYPARSE_PARAM_ARG YYPARSE_PARAM
-# define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
-# endif
-#else /* !YYPARSE_PARAM */
-# define YYPARSE_PARAM_ARG
-# define YYPARSE_PARAM_DECL
-#endif /* !YYPARSE_PARAM */
-
-/* Prevent warning if -Wstrict-prototypes. */
-#ifdef __GNUC__
-# ifdef YYPARSE_PARAM
-int yyparse (void *);
+int yyparse (void *YYPARSE_PARAM);
# else
-int yyparse (void);
+int yyparse ();
# endif
+#else /* ! YYPARSE_PARAM */
+b4_c_function_decl([yyparse], [int], b4_parse_param)
#endif
+
m4_divert_push([KILL])# ======================== M4 code.
# b4_declare_parser_variables
# ---------------------------
# Declare the variables that are global, or local to YYPARSE if
-# pure-parser
+# pure-parser.
m4_define([b4_declare_parser_variables],
[/* The lookahead symbol. */
int yychar;
b4_pure_if([],
[b4_declare_parser_variables])
-int
-yyparse (YYPARSE_PARAM_ARG)
- YYPARSE_PARAM_DECL
+
+/*----------.
+| yyparse. |
+`----------*/
+
+#ifdef YYPARSE_PARAM
+# if defined (__STDC__) || defined (__cplusplus)
+int yyparse (void *YYPARSE_PARAM)
+# else
+int yyparse (YYPARSE_PARAM)
+ void *YYPARSE_PARAM;
+# endif
+#else /* ! YYPARSE_PARAM */
+b4_c_function_def([yyparse], [int], b4_parse_param)
+#endif
{[
]b4_pure_if([b4_declare_parser_variables])[
register int yystate;
/* Number of tokens to shift before error messages enabled. */
int yyerrstatus;
/* Lookahead token as an internal (translated) token number. */
- int yychar1 = 0;
+ int yytoken = 0;
/* Three stacks and their tools:
`yyss': related to states,
yystate = 0;
yyerrstatus = 0;
yynerrs = 0;
- yychar = YYEMPTY; /* Cause a token to be read. */
+ yychar = yytoken = YYEMPTY; /* Cause a token to be read. */
/* Initialize stack pointers.
Waste one element of value and location stack
yysetstate:
*yyssp = yystate;
- if (yyssp >= yyss + yystacksize - 1)
+ if (yyss + yystacksize - 1 <= yyssp)
{
/* Get the current used size of the three stacks, in elements. */
YYSIZE_T yysize = yyssp - yyss + 1;
goto yyoverflowlab;
# else
/* Extend the stack our own way. */
- if (yystacksize >= YYMAXDEPTH)
+ if (YYMAXDEPTH <= yystacksize)
goto yyoverflowlab;
yystacksize *= 2;
- if (yystacksize > YYMAXDEPTH)
+ if (YYMAXDEPTH < yystacksize)
yystacksize = YYMAXDEPTH;
{
YYDPRINTF ((stderr, "Stack size increased to %lu\n",
(unsigned long int) yystacksize));
- if (yyssp >= yyss + yystacksize - 1)
+ if (yyss + yystacksize - 1 <= yyssp)
YYABORT;
}
/* Not known => get a lookahead token if don't already have one. */
- /* yychar is either YYEMPTY or YYEOF
- or a valid token in external form. */
-
- if (yychar == YYEMPTY)
+ /* YYTOKEN is either YYEMPTY or YYEOF or a valid token. */
+ if (yytoken == YYEMPTY)
{
YYDPRINTF ((stderr, "Reading a token: "));
yychar = YYLEX;
+ yytoken = YYTRANSLATE (yychar);
}
- /* Convert token to internal form (in yychar1) for indexing tables with. */
-
- if (yychar <= 0) /* This means end of input. */
+ if (yytoken == YYEOF)
{
- yychar1 = 0;
- yychar = YYEOF; /* Don't call YYLEX any more. */
-
YYDPRINTF ((stderr, "Now at end of input.\n"));
}
else
{
- yychar1 = YYTRANSLATE (yychar);
-
/* We have to keep this `#if YYDEBUG', since we use variables
which are defined only if `YYDEBUG' is set. */
YYDPRINTF ((stderr, "Next token is "));
- YYDSYMPRINT ((stderr, yychar1, yylval]b4_location_if([, yyloc])[));
+ YYDSYMPRINT ((stderr, yytoken, yylval]b4_location_if([, yyloc])[));
YYDPRINTF ((stderr, "\n"));
}
- /* Set YYN to the action to take in STATE on seeing token YYCHAR1.
- Result YYN means
- - YYN < 0: Reduce on rule -YYN.
- - YYN = 0: Error.
- - YYN > 0: Shift to state YYN. */
- yyn += yychar1;
- if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yychar1)
- /* Defaulted action (reduction). */
- yyn = -yydefact[yystate];
- else if (yytable[yyn] != YYTABLE_NINF)
- yyn = yytable[yyn];
- else
- yyn = 0;
-
- if (yyn < 0)
+ /* If the proper action on seeing token YYTOKEN is to reduce or to
+ detect an error, take that action. */
+ yyn += yytoken;
+ if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
+ goto yydefault;
+ yyn = yytable[yyn];
+ if (yyn <= 0)
{
+ if (yyn == 0 || yyn == YYTABLE_NINF)
+ goto yyerrlab;
yyn = -yyn;
goto yyreduce;
}
- else if (yyn == 0)
- goto yyerrlab;
if (yyn == YYFINAL)
YYACCEPT;
/* Shift the lookahead token. */
YYDPRINTF ((stderr, "Shifting token %d (%s), ",
- yychar, yytname[yychar1]));
+ yytoken, yytname[yytoken]));
/* Discard the token being shifted unless it is eof. */
- if (yychar != YYEOF)
- yychar = YYEMPTY;
+ if (yytoken != YYEOF)
+ yytoken = YYEMPTY;
*++yyvsp = yylval;
]b4_location_if([ *++yylsp = yylloc;])[
yyn - 1, yyrline[yyn]);
/* Print the symbols being reduced, and their result. */
- for (yyi = yyprhs[yyn]; yyrhs[yyi] >= 0; yyi++)
+ for (yyi = yyprhs[yyn]; 0 <= yyrhs[yyi]; yyi++)
YYFPRINTF (stderr, "%s ", yytname[yyrhs[yyi]]);
YYFPRINTF (stderr, " -> %s\n", yytname[yyr1[yyn]]);
}
}
/* Line __line__ of __file__. */
-#line __oline__ "__ofile__"
+b4_syncline([@oline@], [@ofile@])
\f
[ yyvsp -= yylen;
yyssp -= yylen;
yycount++;
}
}
- yyerror (yymsg);
+ yyerror (]b4_yyerror_args[yymsg);
YYSTACK_FREE (yymsg);
}
else
- yyerror ("parse error; also virtual memory exhausted");
+ yyerror (]b4_yyerror_args["parse error; also virtual memory exhausted");
}
else
#endif /* YYERROR_VERBOSE */
- yyerror ("parse error");
+ yyerror (]b4_yyerror_args["parse error");
}
goto yyerrlab1;
error, discard it. */
/* Return failure if at end of input. */
- if (yychar == YYEOF)
+ if (yytoken == YYEOF)
{
/* Pop the error token. */
YYPOPSTACK;
/* Pop the rest of the stack. */
- while (yyssp > yyss)
+ while (yyss < yyssp)
{
YYDPRINTF ((stderr, "Error: popping "));
YYDSYMPRINT ((stderr,
}
YYDPRINTF ((stderr, "Discarding token %d (%s).\n",
- yychar, yytname[yychar1]));
- yydestruct (yychar1, yylval]b4_location_if([, yylloc])[);
- yychar = YYEMPTY;
+ yytoken, yytname[yytoken]));
+ yydestruct (yytoken, yylval]b4_location_if([, yylloc])[);
+ yytoken = YYEMPTY;
}
/* Else will try to reuse lookahead token after shifting the error
| yyoverflowlab -- parser overflow comes here. |
`----------------------------------------------*/
yyoverflowlab:
- yyerror ("parser stack overflow");
+ yyerror (]b4_yyerror_args["parser stack overflow");
yyresult = 2;
/* Fall through. */
#endif
b4_epilogue
m4_if(b4_defines_flag, 0, [],
-[#output "b4_output_header_name"
+[@output @output_header_name@
b4_copyright([Skeleton parser for Yacc-like parsing with Bison],
[1984, 1989, 1990, 2000, 2001, 2002])
This special exception was added by the Free Software Foundation
in version 1.24 of Bison. */
-#ifndef b4_header_guard
-# define b4_header_guard
-
b4_token_defines(b4_tokens)
#ifndef YYSTYPE
m4_ifdef([b4_stype],
-[#line b4_stype_line "b4_filename"
+[b4_syncline([b4_stype_line], [b4_filename])
typedef union b4_stype yystype;
/* Line __line__ of __file__. */
-#line __oline__ "__ofile__"],
+b4_syncline([@oline@], [@ofile@])],
[typedef int yystype;])
# define YYSTYPE yystype
+# define YYSTYPE_IS_TRIVIAL 1
#endif
b4_pure_if([],
m4_if(b4_pure, [0],
[extern YYLTYPE b4_prefix[]lloc;])
])
-#endif /* not b4_header_guard */
])