Rely on the state stack to display reduction traces.

To display rhs symbols before a reduction, we used information about the rule
reduced, which required the tables yyrhs and yyprhs.  Now use rely only on the
state stack to get the same information.

	* data/lalr1.cc (b4_rhs_data, b4_rhs_state): New.
	Use them.
	(parser::yyrhs_, parser::yyprhs_): Remove.
	(parser::yy_reduce_print_): Use the state stack.
This commit is contained in:
Akim Demaille
2008-07-31 12:50:42 +02:00
parent e1f93869da
commit 33c195cc37
2 changed files with 32 additions and 14 deletions

View File

@@ -1,3 +1,15 @@
2008-11-09 Akim Demaille <demaille@gostai.com>
Rely on the state stack to display reduction traces.
To display rhs symbols before a reduction, we used information about the rule
reduced, which required the tables yyrhs and yyprhs. Now use rely only on the
state stack to get the same information.
* data/lalr1.cc (b4_rhs_data, b4_rhs_state): New.
Use them.
(parser::yyrhs_, parser::yyprhs_): Remove.
(parser::yy_reduce_print_): Use the state stack.
2008-11-09 Akim Demaille <demaille@gostai.com> 2008-11-09 Akim Demaille <demaille@gostai.com>
Fuse yyval and yyloc into yylhs. Fuse yyval and yyloc into yylhs.

View File

@@ -60,19 +60,36 @@ m4_define([b4_lhs_location],
[yylhs.location]) [yylhs.location])
# b4_rhs_data(RULE-LENGTH, NUM)
# -----------------------------
# Return the data corresponding to the symbol #NUM, where the current
# rule has RULE-LENGTH symbols on RHS.
m4_define([b4_rhs_data],
[yystack_@{($1) - ($2)@}])
# b4_rhs_state(RULE-LENGTH, NUM)
# -----------------------------
# The state corresponding to the symbol #NUM, where the current
# rule has RULE-LENGTH symbols on RHS.
m4_define([b4_rhs_state],
[b4_rhs_data([$1], [$2]).state])
# b4_rhs_value(RULE-LENGTH, NUM, [TYPE]) # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
# -------------------------------------- # --------------------------------------
# Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
# symbols on RHS. # symbols on RHS.
m4_define([b4_rhs_value], m4_define([b4_rhs_value],
[b4_symbol_value([yystack_@{($1) - ($2)@}.value], [$3])]) [b4_symbol_value([b4_rhs_data([$1], [$2]).value], [$3])])
# b4_rhs_location(RULE-LENGTH, NUM) # b4_rhs_location(RULE-LENGTH, NUM)
# --------------------------------- # ---------------------------------
# Expansion of @NUM, where the current rule has RULE-LENGTH symbols # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
# on RHS. # on RHS.
m4_define([b4_rhs_location], m4_define([b4_rhs_location],
[yystack_@{($1) - ($2)@}.location]) [b4_rhs_data([$1], [$2]).location])
# b4_symbol_actions(FILENAME, LINENO, # b4_symbol_actions(FILENAME, LINENO,
@@ -441,10 +458,6 @@ m4_ifdef([b4_stype],
#endif #endif
#if YYDEBUG #if YYDEBUG
/// A `-1'-separated list of the rules' RHS.
static const ]b4_int_type_for([b4_rhs])[ yyrhs_[];
/// For each rule, the index of the first RHS symbol in \a yyrhs_.
static const ]b4_int_type_for([b4_prhs])[ yyprhs_[];
/// For each rule, its source line number. /// For each rule, its source line number.
static const ]b4_int_type_for([b4_rline])[ yyrline_[]; static const ]b4_int_type_for([b4_rline])[ yyrline_[];
/// For each scanner token number, its symbol number. /// For each scanner token number, its symbol number.
@@ -1210,13 +1223,6 @@ b4_error_verbose_if([ tok])[)
#endif #endif
#if YYDEBUG #if YYDEBUG
/* YYRHS -- A `-1'-separated list of the rules' RHS. */
]b4_table_define([rhs], [b4_rhs])[;
/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
YYRHS. */
]b4_table_define([prhs], [b4_prhs])[;
/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
]b4_table_define([rline], [b4_rline])[; ]b4_table_define([rline], [b4_rline])[;
@@ -1245,7 +1251,7 @@ b4_error_verbose_if([ tok])[)
/* The symbols being reduced. */ /* The symbols being reduced. */
for (int yyi = 0; yyi < yynrhs; yyi++) for (int yyi = 0; yyi < yynrhs; yyi++)
YY_SYMBOL_PRINT (" $" << yyi + 1 << " =", YY_SYMBOL_PRINT (" $" << yyi + 1 << " =",
yyrhs_[yyprhs_[yyrule] + yyi], ]yystos_@{b4_rhs_state(yynrhs, yyi + 1)@}[,
]b4_rhs_value(yynrhs, yyi + 1)[, ]b4_rhs_value(yynrhs, yyi + 1)[,
]b4_rhs_location(yynrhs, yyi + 1)[); ]b4_rhs_location(yynrhs, yyi + 1)[);
} }