# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+m4_include(b4_pkgdatadir/[c-like.m4])
# b4_tocpp(STRING)
# ----------------
## Identification. ##
## ---------------- ##
-# b4_comment(TEXT)
-# ----------------
-m4_define([b4_comment], [/* m4_bpatsubst([$1], [
-], [
- ]) */])
+# b4_comment_(TEXT, OPEN, CONTINUE, END)
+# -------------------------------------
+# Put TEXT in comment. Avoid trailing spaces: don't indent empty lines.
+# Avoid adding indentation to the first line, as the indentation comes
+# from OPEN. That's why we don't patsubst([$1], [^\(.\)], [ \1]).
+#
+# Prefix all the output lines with PREFIX.
+m4_define([b4_comment_], [$2[]m4_bpatsubst([$1], [
+\(.\)], [
+$3\1])$4])
+
+
+# b4_c_comment(TEXT, [PREFIX])
+# ----------------------------
+# Put TEXT in comment. Avoid trailing spaces: don't indent empty lines.
+# Avoid adding indentation to the first line, as the indentation comes
+# from "/*". That's why we don't patsubst([$1], [^\(.\)], [ \1]).
+#
+# Prefix all the output lines with PREFIX.
+m4_define([b4_c_comment],
+[b4_comment_([$1], [$2/* ], [$2 ], [$2 */])])
+
+
+# b4_comment(TEXT, [PREFIX])
+# --------------------------
+# By default, C comments.
+m4_define([b4_comment], [b4_c_comment($@)])
+
# b4_identification
# -----------------
m4_popdef([$1])dnl
])])
-# b4_parse_param_use
-# ------------------
-# `YYUSE' all the parse-params.
+# b4_parse_param_use([VAL], [LOC])
+# --------------------------------
+# `YYUSE' VAL, LOC if locations are enabled, and all the parse-params.
m4_define([b4_parse_param_use],
-[b4_parse_param_for([Decl], [Formal], [ YYUSE (Formal);
+[m4_ifvaln([$1], [ YYUSE([$1]);])dnl
+b4_locations_if([m4_ifvaln([$2], [ YYUSE ([$2]);])])dnl
+b4_parse_param_for([Decl], [Formal], [ YYUSE (Formal);
])dnl
])
m4_eval([0 <= $1]), [1], [unsigned int],
- [int])])
+ [int])])
# b4_int_type_for(NAME)
# Return a null pointer constant.
m4_define([b4_null], [YY_NULL])
+# b4_integral_parser_table_define(TABLE-NAME, CONTENT, COMMENT)
+# -------------------------------------------------------------
+# Define "yy<TABLE-NAME>" which contents is CONTENT.
+m4_define([b4_integral_parser_table_define],
+[m4_ifvaln([$3], [b4_c_comment([$3], [ ])])dnl
+static const b4_int_type_for([$2]) yy$1[[]] =
+{
+ $2
+};dnl
+])
## ------------------------- ##
## Assigning token numbers. ##
## ------------------------- ##
-# b4_token_define(TOKEN-NAME, TOKEN-NUMBER)
-# -----------------------------------------
+# b4_token_define(TOKEN-NUM)
+# --------------------------
# Output the definition of this token as #define.
m4_define([b4_token_define],
-[#define $1 $2
-])
-
+[b4_token_format([#define %s %s], [$1])])
-# b4_token_defines(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
-# -------------------------------------------------------
-# Output the definition of the tokens (if there are) as #defines.
+# b4_token_defines
+# ----------------
+# Output the definition of the tokens.
m4_define([b4_token_defines],
-[m4_if([$#$1], [1], [],
-[/* Tokens. */
-m4_map([b4_token_define], [$@])])
-])
+[b4_any_token_visible_if([/* Tokens. */
+m4_join([
+], b4_symbol_map([b4_token_define]))
+])])
-# b4_token_enum(TOKEN-NAME, TOKEN-NUMBER)
-# ---------------------------------------
+# b4_token_enum(TOKEN-NUM)
+# ------------------------
# Output the definition of this token as an enum.
m4_define([b4_token_enum],
-[$1 = $2])
+[b4_token_format([%s = %s], [$1])])
-# b4_token_enums(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
-# -----------------------------------------------------
+# b4_token_enums
+# --------------
# Output the definition of the tokens (if there are) as enums.
m4_define([b4_token_enums],
-[m4_if([$#$1], [1], [],
-[[/* Tokens. */
+[b4_any_token_visible_if([[/* Tokens. */
#ifndef ]b4_api_PREFIX[TOKENTYPE
# define ]b4_api_PREFIX[TOKENTYPE
- /* Put the tokens into the symbol table, so that GDB and other debuggers
- know about them. */
- enum ]b4_api_prefix[tokentype {
-]m4_map_sep([ b4_token_enum], [,
-],
- [$@])[
- };
+ /* Put the tokens into the symbol table, so that GDB and other debuggers
+ know about them. */
+ enum ]b4_api_prefix[tokentype
+ {
+ ]m4_join([,
+ ],
+ b4_symbol_map([b4_token_enum]))[
+ };
#endif
]])])
-# b4_token_enums_defines(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
-# -------------------------------------------------------------
-# Output the definition of the tokens (if there are any) as enums and, if POSIX
-# Yacc is enabled, as #defines.
+# b4_token_enums_defines
+# ----------------------
+# Output the definition of the tokens (if there are any) as enums and,
+# if POSIX Yacc is enabled, as #defines.
m4_define([b4_token_enums_defines],
-[b4_token_enums($@)b4_yacc_if([b4_token_defines($@)], [])
-])
+[b4_token_enums[]b4_yacc_if([b4_token_defines])])
+
+
+## ----------------- ##
+## Semantic Values. ##
+## ----------------- ##
+
+
+# b4_symbol_value(VAL, [TYPE])
+# ----------------------------
+# Given a semantic value VAL ($$, $1 etc.), extract its value of type
+# TYPE if TYPE is given, otherwise just return VAL. The result can be
+# used safetly, it is put in parens to avoid nasty precedence issues.
+# TYPE is *not* put in braces, provide some if needed.
+m4_define([b4_symbol_value],
+[($1[]m4_ifval([$2], [.$2]))])
m4_define([b4_c_ansi_formals],
[m4_if([$#], [0], [void],
[$#$1], [1], [void],
- [m4_map_sep([b4_c_ansi_formal], [, ], [$@])])])
+ [m4_map_sep([b4_c_ansi_formal], [, ], [$@])])])
m4_define([b4_c_ansi_formal],
[$1])
# Output the K&R argument declarations.
m4_define([b4_c_knr_formal_decls],
[m4_map_sep([b4_c_knr_formal_decl],
- [
+ [
],
- [$@])])
+ [$@])])
m4_define([b4_c_knr_formal_decl],
[ $1;])
# -----------------------------------------------------------
# Declare the function NAME.
m4_define([b4_c_function_decl],
-[#if defined __STDC__ || defined __cplusplus
+[#if b4_c_modern
b4_c_ansi_function_decl($@)
#else
$2 $1 ();
m4_define([b4_case],
[ case $1:
$2
+b4_syncline([@oline@], [@ofile@])
break;])
-# b4_dollar_dollar_(NAME, FIELD, DEFAULT-FIELD)
-# ---------------------------------------------
-# If FIELD (or DEFAULT-FIELD) is non-null, read it in pointer NAME,
-# otherwise just dereference.
-m4_define([b4_dollar_dollar_],
-[m4_if([$2], [[]],
- [m4_ifval([$3], [($1->$3)],
- [(*$1)])],
- [($1->$2)])])
-
-# b4_dollar_pushdef(VALUE, DEFAULT-FIELD, LOCATION)
-# b4_dollar_popdef
-# -------------------------------------------------
-# Define b4_dollar_dollar for VALUE and DEFAULT-FIELD,
-# and b4_at_dollar for LOCATION.
-m4_define([b4_dollar_pushdef],
-[m4_pushdef([b4_dollar_dollar],
- [b4_dollar_dollar_([$1], m4_dquote($][1), [$2])])dnl
-m4_pushdef([b4_at_dollar], [(*yylocationp)])dnl
-])
-m4_define([b4_dollar_popdef],
-[m4_popdef([b4_at_dollar])dnl
-m4_popdef([b4_dollar_dollar])dnl
-])
-
-# b4_symbol_actions(FILENAME, LINENO,
-# SYMBOL-TAG, SYMBOL-NUM,
-# SYMBOL-ACTION, SYMBOL-TYPENAME)
-# -------------------------------------------------
-# Issue the code for a symbol action (e.g., %printer).
-#
-# Define b4_dollar_dollar([TYPE-NAME]), and b4_at_dollar, which are
-# invoked where $<TYPE-NAME>$ and @$ were specified by the user.
-m4_define([b4_symbol_actions],
-[b4_dollar_pushdef([yyvaluep], [$6], [(*yylocationp)])dnl
- case $4: /* $3 */
-b4_syncline([$2], [$1])
- $5;
+# b4_predicate_case(LABEL, CONDITIONS)
+# ------------------------------------
+m4_define([b4_predicate_case],
+[ case $1:
+ if (! ($2)) YYERROR;
b4_syncline([@oline@], [@ofile@])
- break;
-b4_dollar_popdef[]dnl
-])
+ break;])
# b4_yydestruct_generate(FUNCTION-DECLARATOR)
b4_locations_if( [, [[YYLTYPE *yylocationp], [yylocationp]]])[]dnl
m4_ifset([b4_parse_param], [, b4_parse_param]))[
{
- YYUSE (yyvaluep);
-]b4_locations_if([ YYUSE (yylocationp);
-])dnl
-b4_parse_param_use[]dnl
-[
- if (!yymsg)
+]b4_parse_param_use([yyvaluep], [yylocationp])dnl
+[ if (!yymsg)
yymsg = "Deleting";
YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
switch (yytype)
{
-]m4_map([b4_symbol_actions], m4_defn([b4_symbol_destructors]))[
- default:
- break;
+]b4_symbol_foreach([b4_symbol_destructor])dnl
+[ default:
+ break;
}
}]dnl
])
/*ARGSUSED*/
]$1([yy_symbol_value_print],
[static void],
- [[FILE *yyoutput], [yyoutput]],
- [[int yytype], [yytype]],
- [[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl
+ [[FILE *yyoutput], [yyoutput]],
+ [[int yytype], [yytype]],
+ [[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl
b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl
m4_ifset([b4_parse_param], [, b4_parse_param]))[
{
FILE *yyo = yyoutput;
- YYUSE (yyo);
- if (!yyvaluep)
- return;
-]b4_locations_if([ YYUSE (yylocationp);
-])dnl
-b4_parse_param_use[]dnl
-[# ifdef YYPRINT
+]b4_parse_param_use([yyo], [yylocationp])dnl
+[ if (!yyvaluep)
+ return;]
+dnl glr.c does not feature yytoknum.
+m4_if(b4_skeleton, ["yacc.c"],
+[[# ifdef YYPRINT
if (yytype < YYNTOKENS)
YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
-# else
- YYUSE (yyoutput);
# endif
- switch (yytype)
+]])dnl
+[ switch (yytype)
{
-]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl
+]b4_symbol_foreach([b4_symbol_printer])dnl
[ default:
- break;
+ break;
}
}
]$1([yy_symbol_print],
[static void],
- [[FILE *yyoutput], [yyoutput]],
- [[int yytype], [yytype]],
- [[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl
+ [[FILE *yyoutput], [yyoutput]],
+ [[int yytype], [yytype]],
+ [[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl
b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl
m4_ifset([b4_parse_param], [, b4_parse_param]))[
{
[m4_if(b4_tag_seen_flag, 0,
[[typedef int ]b4_api_PREFIX[STYPE;
# define ]b4_api_PREFIX[STYPE_IS_TRIVIAL 1]])])[
-# define ]b4_api_prefix[stype ]b4_api_PREFIX[STYPE /* obsolescent; will be withdrawn */
# define ]b4_api_PREFIX[STYPE_IS_DECLARED 1
#endif]b4_locations_if([[
int last_line;
int last_column;
} ]b4_api_PREFIX[LTYPE;
-# define ]b4_api_prefix[ltype ]b4_api_PREFIX[LTYPE /* obsolescent; will be withdrawn */
# define ]b4_api_PREFIX[LTYPE_IS_DECLARED 1
# define ]b4_api_PREFIX[LTYPE_IS_TRIVIAL 1
#endif]])
[[/* Enabling traces. */
]m4_if(b4_api_prefix, [yy],
[[#ifndef YYDEBUG
-# define YYDEBUG ]b4_debug_flag[
+# define YYDEBUG ]b4_parse_trace_if([1], [0])[
#endif]],
[[#ifndef ]b4_api_PREFIX[DEBUG
# if defined YYDEBUG
-# if YYDEBUG
+#if YYDEBUG
# define ]b4_api_PREFIX[DEBUG 1
# else
# define ]b4_api_PREFIX[DEBUG 0
# endif
# else /* ! defined YYDEBUG */
-# define ]b4_api_PREFIX[DEBUG ]b4_debug_flag[
+# define ]b4_api_PREFIX[DEBUG ]b4_parse_trace_if([1], [0])[
# endif /* ! defined ]b4_api_PREFIX[DEBUG */
#endif /* ! defined ]b4_api_PREFIX[DEBUG */]])[]dnl
])