[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
glr2.cc: reorganize the skeleton
From: |
Akim Demaille |
Subject: |
glr2.cc: reorganize the skeleton |
Date: |
Sun, 27 Dec 2020 06:44:34 +0100 |
commit 2777b7316641691dc810ac5287df370b57a2d3d3
Author: Akim Demaille <akim.demaille@gmail.com>
Date: Sat Dec 26 16:47:09 2020 +0100
glr2.cc: reorganize the skeleton
Restore a more natural order: first define the macros and then use
them. Currently, some macros were defined between the moment the
header is issued, and then the implementation file. As a result, it
was possible for the header and the implementation to not use the same
versions of the macros.
* data/skeletons/glr2.cc: Define the macros first, then use them.
* data/skeletons/lalr1.cc: Minor comment and quoting changes.
diff --git a/data/skeletons/glr2.cc b/data/skeletons/glr2.cc
index c3502abb..72b790f6 100644
--- a/data/skeletons/glr2.cc
+++ b/data/skeletons/glr2.cc
@@ -15,6 +15,8 @@
# 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_skeletonsdir/[c++.m4])
+
# b4_tname_if(TNAME-NEEDED, TNAME-NOT-NEEDED)
# -------------------------------------------
m4_define([b4_tname_if],
@@ -23,10 +25,6 @@ m4_define([b4_tname_if],
[b4_token_table_if([$1],
[$2])])])
-# We require a pure interface.
-m4_define([b4_pure_flag], [1])
-
-m4_include(b4_skeletonsdir/[c++.m4])
b4_bison_locations_if([
m4_define([b4_location_constructors])
m4_include(b4_skeletonsdir/[location.cc])])
@@ -48,6 +46,82 @@ m4_defn([b4_initial_action])]))])[
b4_namespace_ref[::]b4_parser_class[::symbol_kind::]b4_symbol($1,
kind_base))
])
+## ---------------- ##
+## Default values. ##
+## ---------------- ##
+
+# Stack parameters.
+m4_define_default([b4_stack_depth_max], [10000])
+m4_define_default([b4_stack_depth_init], [200])
+
+
+
+## ------------ ##
+## Interfaces. ##
+## ------------ ##
+
+# b4_user_formals
+# ---------------
+# The possible parse-params formal arguments preceded by a comma.
+#
+# This is not shared with yacc.c in c.m4 because GLR relies on ISO C
+# formal argument declarations.
+m4_define([b4_user_formals],
+[m4_ifset([b4_parse_param], [, b4_formals(b4_parse_param)])])
+
+
+# b4_symbol_kind(NUM)
+# -------------------
+m4_define([b4_symbol_kind],
+[symbol_kind::b4_symbol_kind_base($@)])
+
+
+## ----------------- ##
+## Semantic Values. ##
+## ----------------- ##
+
+
+# b4_lhs_value(SYMBOL-NUM, [TYPE])
+# --------------------------------
+# See README.
+m4_define([b4_lhs_value],
+[b4_symbol_value([(*yyvalp)], [$1], [$2])])
+
+
+# b4_rhs_data(RULE-LENGTH, POS)
+# -----------------------------
+# See README.
+m4_define([b4_rhs_data],
+[(static_cast<glr_stack_item const *>(yyvsp))@{YYFILL (b4_subtract([$2],
[$1]))@}.getState()])
+
+
+# b4_rhs_value(RULE-LENGTH, POS, SYMBOL-NUM, [TYPE])
+# --------------------------------------------------
+# Expansion of $$ or $<TYPE>$, for symbol SYMBOL-NUM.
+m4_define([b4_rhs_value],
+[b4_symbol_value([b4_rhs_data([$1], [$2]).value ()], [$3], [$4])])
+
+
+
+## ----------- ##
+## Locations. ##
+## ----------- ##
+
+# b4_lhs_location()
+# -----------------
+# Expansion of @$.
+m4_define([b4_lhs_location],
+[(*yylocp)])
+
+
+# b4_rhs_location(RULE-LENGTH, NUM)
+# ---------------------------------
+# Expansion of @NUM, where the current rule has RULE-LENGTH symbols
+# on RHS.
+m4_define([b4_rhs_location],
+[(b4_rhs_data([$1], [$2]).yyloc)])
+
+
# b4_lex
# ------
# Call yylex.
@@ -279,9 +353,19 @@ const std::ptrdiff_t strong_index_alias<T>::INVALID_INDEX =
]m4_popdef([b4_parse_param])dnl
])[
-]b4_header_if(
-[b4_output_begin([b4_spec_header_file])
-b4_copyright([Skeleton interface for Bison GLR parsers in C++],
+
+## -------------- ##
+## Output files. ##
+## -------------- ##
+
+
+# ------------- #
+# Header file. #
+# ------------- #
+
+]b4_header_if([[
+]b4_output_begin([b4_spec_header_file])[
+]b4_copyright([Skeleton interface for Bison GLR parsers in C++],
[2002-2015, 2018-2020])[
// C++ GLR parser skeleton written by Valentin Tolmer.
@@ -289,98 +373,17 @@ b4_copyright([Skeleton interface for Bison GLR parsers in
C++],
]b4_cpp_guard_open([b4_spec_mapped_header_file])[
]b4_shared_declarations[
]b4_cpp_guard_close([b4_spec_mapped_header_file])[
-]b4_output_end])
-
-## ---------------- ##
-## Default values. ##
-## ---------------- ##
-
-# Stack parameters.
-m4_define_default([b4_stack_depth_max], [10000])
-m4_define_default([b4_stack_depth_init], [200])
-
-
-
-## ------------ ##
-## Interfaces. ##
-## ------------ ##
-
-# b4_user_formals
-# ---------------
-# The possible parse-params formal arguments preceded by a comma.
-#
-# This is not shared with yacc.c in c.m4 because GLR relies on ISO C
-# formal argument declarations.
-m4_define([b4_user_formals],
-[m4_ifset([b4_parse_param], [, b4_formals(b4_parse_param)])])
-
-
-# b4_symbol_kind(NUM)
-# -------------------
-m4_define([b4_symbol_kind],
-[symbol_kind::b4_symbol_kind_base($@)])
-
-
-## ----------------- ##
-## Semantic Values. ##
-## ----------------- ##
-
-
-# b4_lhs_value(SYMBOL-NUM, [TYPE])
-# --------------------------------
-# See README.
-m4_define([b4_lhs_value],
-[b4_symbol_value([(*yyvalp)], [$1], [$2])])
-
-
-# b4_rhs_data(RULE-LENGTH, POS)
-# -----------------------------
-# See README.
-m4_define([b4_rhs_data],
-[(static_cast<glr_stack_item const *>(yyvsp))@{YYFILL (b4_subtract([$2],
[$1]))@}.getState()])
-
-
-# b4_rhs_value(RULE-LENGTH, POS, SYMBOL-NUM, [TYPE])
-# --------------------------------------------------
-# Expansion of $$ or $<TYPE>$, for symbol SYMBOL-NUM.
-m4_define([b4_rhs_value],
-[b4_symbol_value([b4_rhs_data([$1], [$2]).value ()], [$3], [$4])])
-
-
-
-## ----------- ##
-## Locations. ##
-## ----------- ##
+]b4_output_end])[
-# b4_lhs_location()
-# -----------------
-# Expansion of @$.
-m4_define([b4_lhs_location],
-[(*yylocp)])
+# --------------------- #
+# Implementation file. #
+# --------------------- #
-# b4_rhs_location(RULE-LENGTH, NUM)
-# ---------------------------------
-# Expansion of @NUM, where the current rule has RULE-LENGTH symbols
-# on RHS.
-m4_define([b4_rhs_location],
-[(b4_rhs_data([$1], [$2]).yyloc)])
-
-
-## -------------- ##
-## Output files. ##
-## -------------- ##
-
-
-# ------------------------- #
-# The implementation file. #
-# ------------------------- #
-
-b4_output_begin([b4_parser_file_name])
-b4_copyright([Skeleton implementation for Bison GLR parsers in C],
- [2002-2015, 2018-2019])[
-/* New C++ GLR parser skeleton written by Akim Demaille, adapted by Valentin
- * Tolmer. */
+]b4_output_begin([b4_parser_file_name])[
+]b4_copyright([Skeleton implementation for Bison GLR parsers in C],
+ [2002-2015, 2018-2019])[
+// C++ GLR parser skeleton written by Valentin Tolmer.
]b4_disclaimer[
]b4_identification[
diff --git a/data/skeletons/lalr1.cc b/data/skeletons/lalr1.cc
index 76603492..c583f356 100644
--- a/data/skeletons/lalr1.cc
+++ b/data/skeletons/lalr1.cc
@@ -493,16 +493,21 @@ m4_define([b4_shared_declarations],
]b4_namespace_close[
]b4_percent_code_get([[provides]])[
-]])
+]])[
+
## -------------- ##
## Output files. ##
## -------------- ##
-b4_header_if(
-[b4_output_begin([b4_spec_header_file])
-b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++])
-[
+# ------------- #
+# Header file. #
+# ------------- #
+
+]b4_header_if([[
+]b4_output_begin([b4_spec_header_file])[
+]b4_copyright([Skeleton interface for Bison LALR(1) parsers in C++])[
+
/**
** \file ]b4_spec_mapped_header_file[
** Define the ]b4_namespace_ref[::parser class.
@@ -515,10 +520,14 @@ b4_copyright([Skeleton interface for Bison LALR(1)
parsers in C++])
]b4_shared_declarations(hh)[
]b4_cpp_guard_close([b4_spec_mapped_header_file])[
]b4_output_end[
-]])
+]])[
+
+# --------------------- #
+# Implementation file. #
+# --------------------- #
-b4_output_begin([b4_parser_file_name])[
+]b4_output_begin([b4_parser_file_name])[
]b4_copyright([Skeleton implementation for Bison LALR(1) parsers in C++])[
]b4_disclaimer[
]b4_percent_code_get([[top]])[]dnl
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- glr2.cc: reorganize the skeleton,
Akim Demaille <=