-*- Autoconf -*-
# Language-independent M4 Macros for Bison.
-# Copyright (C) 2002, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
+# Copyright (C) 2002, 2004, 2005, 2006, 2007, 2008 Free Software Foundation,
+# Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
## Identification. ##
## ---------------- ##
-# b4_copyright(TITLE, YEARS)
-# --------------------------
+# b4_copyright(TITLE, [YEARS])
+# ----------------------------
+# If YEARS are not defined, use b4_copyright_years.
m4_define([b4_copyright],
[b4_comment([A Bison parser, made by GNU Bison b4_version.])
b4_comment([$1
-m4_text_wrap([Copyright (C) $2 Free Software Foundation, Inc.], [ ])
+]m4_dquote(m4_text_wrap([Copyright (C)
+]m4_ifval([$2], [[$2]], [m4_defn([b4_copyright_years])])[
+Free Software Foundation, Inc.]))[
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
m4_define([b4_cat],
[m4_syscmd([cat <<'_m4eof'
]m4_bpatsubst(m4_dquote($1), [_m4eof], [_m4@`eof])[@
-_m4eof])dnl
+_m4eof
+])dnl
m4_if(m4_sysval, [0], [], [m4_fatal([$0: cannot write to stdout])])])
# b4_error(KIND, FORMAT, [ARG1], [ARG2], ...)
[m4_eval([$3 <= $1 && $1 <= $4 && $3 <= $2 && $2 <= $4])])
+# b4_subtract(LHS, RHS)
+# ---------------------
+# Evaluate LHS - RHS if they are integer literals, otherwise expand
+# to (LHS) - (RHS).
+m4_define([b4_subtract],
+[m4_bmatch([$1$2], [^[0123456789]*$],
+ [m4_eval([$1 - $2])],
+ [($1) - ($2)])])
+
+# b4_args(ARG1, ...)
+# _b4_args(ARG1, ...)
+# -------------------
+# Join with comma, skipping empty arguments.
+# b4_args calls itself recursively until it sees the first non-empty
+# argument, then calls _b4_args which prepends each non-empty argument
+# with a comma.
+m4_define([b4_args],
+[m4_if([$#$1],
+ [1], [],
+ [m4_ifval([$1],
+ [$1[]_$0(m4_shift($@))],
+ [$0(m4_shift($@))])])])
+
+# _b4_args(ARGS1, ...)
+# --------------------
+m4_define([_b4_args],
+[m4_if([$#$1],
+ [1], [],
+ [m4_ifval([$1], [, $1])[]$0(m4_shift($@))])])
+
+
+
+
+# b4_tables_map(MACRO)
+# --------------------
+# Map MACRO on all the integral tables. MACRO is expected to have
+# the signature MACRO(TABLE-NAME, CONTENT, COMMENT).
+m4_define([b4_tables_map],
+[$1([pact], [b4_pact],
+ [[YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
+STATE-NUM.]])
+
+$1([defact], [b4_defact],
+ [[YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
+does not specify something else to do. Zero means the default is an
+error.]])
+
+$1([pgoto], [b4_pgoto], [[YYPGOTO[NTERM-NUM].]])
+
+$1([defgoto], [b4_defgoto], [[YYDEFGOTO[NTERM-NUM].]])
+
+$1([table], [b4_table],
+ [[YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
+positive, shift that token. If negative, reduce the rule which
+number is the opposite. If zero, do what YYDEFACT says.
+If YYTABLE_NINF, syntax error.]])
+
+$1([check], [b4_check])
+
+$1([stos], [b4_stos],
+ [[STOS_[STATE-NUM] -- The (internal number of the) accessing
+symbol of state STATE-NUM.]])
+
+$1([r1], [b4_r1],
+ [[YYR1[YYN] -- Symbol number of symbol that rule YYN derives.]])
+
+$1([r2], [b4_r2],
+ [[YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.]])
+])
+
+
+# b4_tables_declare
+# b4_tables_define
+# -----------------
+# Define/declare the (deterministic) parser tables.
+m4_define([b4_tables_declare],
+[b4_tables_map([b4_table_declare])])
+
+m4_define([b4_tables_define],
+[b4_tables_map([b4_table_define])])
+
+
## ------------------ ##
## Decoding options. ##
b4_define_flag_if([glr]) # Whether a GLR parser is requested.
b4_define_flag_if([locations]) # Whether locations are tracked.
b4_define_flag_if([nondeterministic]) # Whether conflicts should be handled.
-b4_define_flag_if([pure]) # Whether the interface is pure.
b4_define_flag_if([yacc]) # Whether POSIX Yacc is emulated.
-## ------------------------- ##
-## Assigning token numbers. ##
-## ------------------------- ##
-
-
## ----------- ##
## Synclines. ##
## ----------- ##
m4_ifval([$1], [m4_define([b4_percent_code_bison_qualifiers(]$1[)])])dnl
m4_ifdef(b4_macro_name,
[b4_comment([m4_if([$#], [0], [[Unqualified %code]],
- [[%code "]$1["]])[ blocks.]])
+ [["%code ]$1["]])[ blocks.]])
b4_user_code([m4_indir(b4_macro_name)])
])dnl
m4_popdef([b4_macro_name])])
[$3])])
+# Default values for %define.
+# ---------------------------
+# If the %token.prefix, it is empty.
+m4_percent_define_default([[token.prefix]], [[]])
+
+
+
## ----------------------------------------------------------- ##
## After processing the skeletons, check that all the user's ##
## %define variables and %code qualifiers were used by Bison. ##
[b4_percent_]$1[_user_]$2[s],
[[b4_percent_]$1[_bison_]$2[s]])])])
-m4_wrap([
+m4_wrap_lifo([
b4_check_user_names_wrap([[define]], [[variable]])
b4_check_user_names_wrap([[code]], [[qualifier]])
])