[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Factor the generation of the (integral) tables bw yacc.c and lal
From: |
Akim Demaille |
Subject: |
[PATCH] Factor the generation of the (integral) tables bw yacc.c and lalr1.cc. |
Date: |
Tue, 25 Nov 2008 21:25:48 +0100 |
* data/lalr1.cc (b4_tables_map): Move to...
* data/bison.m4: here.
Update the comment for yytable during the flight.
(b4_tables_declare, b4_tables_define): New.
* data/lalr1.cc: Use them.
* data/c.m4 (b4_table_define): New.
* data/yacc.c: Use b4_tables_define instead of output the tables
by hand.
* tests/regression.at (Web2c Actions): Adjust the expected output,
the order of the tables changed.
---
ChangeLog | 14 ++++++++++++
data/bison.m4 | 50 +++++++++++++++++++++++++++++++++++++++++++
data/c.m4 | 11 +++++++++
data/lalr1.cc | 39 +--------------------------------
data/yacc.c | 58 +--------------------------------------------------
tests/regression.at | 30 +++++++++++++-------------
6 files changed, 93 insertions(+), 109 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index c188d99..0cb281b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
2008-11-26 Akim Demaille <address@hidden>
+ Factor the generation of the (integral) tables bw yacc.c and lalr1.cc.
+ * data/lalr1.cc (b4_tables_map): Move to...
+ * data/bison.m4: here.
+ Update the comment for yytable during the flight.
+ (b4_tables_declare, b4_tables_define): New.
+ * data/lalr1.cc: Use them.
+ * data/c.m4 (b4_table_define): New.
+ * data/yacc.c: Use b4_tables_define instead of output the tables
+ by hand.
+ * tests/regression.at (Web2c Actions): Adjust the expected output,
+ the order of the tables changed.
+
+2008-11-26 Akim Demaille <address@hidden>
+
Get rid of (yy)rhs and (yy)prhs.
These tables are no longer needed in the parsers, and they don't seem to
be useful. They are not documented either.
diff --git a/data/bison.m4 b/data/bison.m4
index e7376c6..efcf2bd 100644
--- a/data/bison.m4
+++ b/data/bison.m4
@@ -245,6 +245,56 @@ m4_define([_b4_args],
+# 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. ##
## ------------------ ##
diff --git a/data/c.m4 b/data/c.m4
index f0b5f14..518c05b 100644
--- a/data/c.m4
+++ b/data/c.m4
@@ -169,6 +169,17 @@ m4_define([b4_int_type_for],
m4_define([b4_null], [0])
+# b4_table_define(TABLE-NAME, CONTENT, COMMENT)
+# ---------------------------------------------
+# Define "yy<TABLE-NAME>" which contents is CONTENT.
+m4_define([b4_table_define],
+[m4_ifval([$3], [b4_c_comment([$3], [ ])
+])dnl
+static const b4_int_type_for([$2]) yy$1[[]] =
+{
+ $2
+};dnl
+])
## ------------------------- ##
diff --git a/data/lalr1.cc b/data/lalr1.cc
index 79e7417..b751a08 100644
--- a/data/lalr1.cc
+++ b/data/lalr1.cc
@@ -39,41 +39,6 @@ m4_define([b4_table_define],
};dnl
])
-# 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.]])
-
-$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_symbol_value_template(VAL, [TYPE])
# -------------------------------------
@@ -711,7 +676,7 @@ m4_ifdef([b4_stype],
static const ]b4_int_type(b4_table_ninf, b4_table_ninf)[ yytable_ninf_;
/* Tables. */
-]b4_tables_map([b4_table_declare])[
+]b4_tables_declare[
#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
/// For a symbol, its name in clear.
@@ -1534,7 +1499,7 @@ b4_error_verbose_if([int yystate, int yytoken],
const ]b4_int_type(b4_table_ninf, b4_table_ninf)
b4_parser_class_name::yytable_ninf_ = b4_table_ninf[;
-]b4_tables_map([b4_table_define])[
+]b4_tables_define[
#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
diff --git a/data/yacc.c b/data/yacc.c
index faec957..eed13f7 100644
--- a/data/yacc.c
+++ b/data/yacc.c
@@ -526,67 +526,11 @@ static const ]b4_int_type_for([b4_toknum])[ yytoknum[] =
};
# endif
-/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
-static const ]b4_int_type_for([b4_r1])[ yyr1[] =
-{
- ]b4_r1[
-};
-
-/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
-static const ]b4_int_type_for([b4_r2])[ yyr2[] =
-{
- ]b4_r2[
-};
-
-/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
- STATE-NUM when YYTABLE doesn't specify something else to do. Zero
- means the default is an error. */
-static const ]b4_int_type_for([b4_defact])[ yydefact[] =
-{
- ]b4_defact[
-};
-
-/* YYDEFGOTO[NTERM-NUM]. */
-static const ]b4_int_type_for([b4_defgoto])[ yydefgoto[] =
-{
- ]b4_defgoto[
-};
-
-/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
- STATE-NUM. */
#define YYPACT_NINF ]b4_pact_ninf[
-static const ]b4_int_type_for([b4_pact])[ yypact[] =
-{
- ]b4_pact[
-};
-
-/* YYPGOTO[NTERM-NUM]. */
-static const ]b4_int_type_for([b4_pgoto])[ yypgoto[] =
-{
- ]b4_pgoto[
-};
-/* 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. */
#define YYTABLE_NINF ]b4_table_ninf[
-static const ]b4_int_type_for([b4_table])[ yytable[] =
-{
- ]b4_table[
-};
-
-static const ]b4_int_type_for([b4_check])[ yycheck[] =
-{
- ]b4_check[
-};
-/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
- symbol of state STATE-NUM. */
-static const ]b4_int_type_for([b4_stos])[ yystos[] =
-{
- ]b4_stos[
-};
+]b4_tables_define[
#define yyerrok (yyerrstatus = 0)
#define yyclearin (yychar = YYEMPTY)
diff --git a/tests/regression.at b/tests/regression.at
index 01bbb7a..489de4f 100644
--- a/tests/regression.at
+++ b/tests/regression.at
@@ -767,32 +767,24 @@ static const yytype_uint16 yytoknum[] =
{
0, 256, 257, 258, 259, 260, 261
};
-static const yytype_uint8 yyr1[] =
-{
- 0, 7, 8, 9, 9, 10, 11
-};
-static const yytype_uint8 yyr2[] =
+static const yytype_int8 yypact[] =
{
- 0, 2, 1, 0, 2, 4, 2
+ -2, -1, 4, -8, 0, 2, -8, -2, -8, -2,
+ -8, -8
};
static const yytype_uint8 yydefact[] =
{
3, 0, 0, 2, 0, 0, 1, 3, 4, 3,
6, 5
};
-static const yytype_int8 yydefgoto[] =
-{
- -1, 2, 3, 4, 8
-};
-static const yytype_int8 yypact[] =
-{
- -2, -1, 4, -8, 0, 2, -8, -2, -8, -2,
- -8, -8
-};
static const yytype_int8 yypgoto[] =
{
-8, -7, -8, -8, -8
};
+static const yytype_int8 yydefgoto[] =
+{
+ -1, 2, 3, 4, 8
+};
static const yytype_uint8 yytable[] =
{
10, 1, 11, 5, 6, 0, 7, 9
@@ -806,6 +798,14 @@ static const yytype_uint8 yystos[] =
0, 3, 8, 9, 10, 4, 0, 6, 11, 5,
8, 8
};
+static const yytype_uint8 yyr1[] =
+{
+ 0, 7, 8, 9, 9, 10, 11
+};
+static const yytype_uint8 yyr2[] =
+{
+ 0, 2, 1, 0, 2, 4, 2
+};
]])
AT_CLEANUP
--
1.6.0.2.588.g3102
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] Factor the generation of the (integral) tables bw yacc.c and lalr1.cc.,
Akim Demaille <=