Push the state, value, and location at the same time.

This is needed to prepare a forthcoming patch that fuses the three
stacks into one.

	* data/lalr1.cc (parser::yypush_): New.
	(parser::yynewstate): Change the semantics: instead of arriving to
	this label when value and location have been pushed, but yystate
	is to be pushed on the state stack, now the three of them must
	have been pushed before.  yystate still must be the new state.
	This allows to use yypush_ everywhere instead of individual
	handling of the stacks.
This commit is contained in:
Akim Demaille
2008-10-22 05:17:07 -05:00
parent c4585f1e2d
commit 7dedf26e55
2 changed files with 35 additions and 10 deletions

View File

@@ -1,3 +1,17 @@
2008-11-03 Akim Demaille <demaille@gostai.com>
Push the state, value, and location at the same time.
This is needed to prepare a forthcoming patch that fuses the three
stacks into one.
* data/lalr1.cc (parser::yypush_): New.
(parser::yynewstate): Change the semantics: instead of arriving to
this label when value and location have been pushed, but yystate
is to be pushed on the state stack, now the three of them must
have been pushed before. yystate still must be the new state.
This allows to use yypush_ everywhere instead of individual
handling of the stacks.
2008-11-03 Akim Demaille <demaille@gostai.com> 2008-11-03 Akim Demaille <demaille@gostai.com>
Prefer references to pointers. Prefer references to pointers.

View File

@@ -407,6 +407,11 @@ b4_error_verbose_if([, int tok])[);
semantic_type& yyvalue, semantic_type& yyvalue,
location_type& yylocation); location_type& yylocation);
/// Push a new state on the stack.
/// \warning the contents of \a v is stolen.
inline void yypush_ (state_type s,
semantic_type& v, const location_type& l);
/// Pop \a n symbols the three stacks. /// Pop \a n symbols the three stacks.
inline void yypop_ (unsigned int n = 1); inline void yypop_ (unsigned int n = 1);
@@ -623,6 +628,15 @@ do { \
} }
} }
void
]b4_parser_class_name[::yypush_ (state_type s,
semantic_type& v, const location_type& l)
{
yystate_stack_.push (s);
yysemantic_stack_.push (v);
yylocation_stack_.push (l);
}
void void
]b4_parser_class_name[::yypop_ (unsigned int n) ]b4_parser_class_name[::yypop_ (unsigned int n)
{ {
@@ -705,12 +719,12 @@ m4_popdef([b4_at_dollar])])dnl
yystate_stack_ = state_stack_type (0); yystate_stack_ = state_stack_type (0);
yysemantic_stack_ = semantic_stack_type (0); yysemantic_stack_ = semantic_stack_type (0);
yylocation_stack_ = location_stack_type (0); yylocation_stack_ = location_stack_type (0);
yysemantic_stack_.push (yylval); yypush_ (yystate, yylval, yylloc);
yylocation_stack_.push (yylloc);
/* New state. */ // A new state was pushed on the stack.
// Invariant: yystate == yystack_[0].state, i.e.,
// yystate was just pushed onto the state stack.
yynewstate: yynewstate:
yystate_stack_.push (yystate);
YYCDEBUG << "Entering state " << yystate << std::endl; YYCDEBUG << "Entering state " << yystate << std::endl;
/* Accept? */ /* Accept? */
@@ -771,8 +785,6 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
/* Discard the token being shifted. */ /* Discard the token being shifted. */
yychar = yyempty_; yychar = yyempty_;
yysemantic_stack_.push (yylval);
yylocation_stack_.push (yylloc);
/* Count tokens shifted since error; after three, turn off error /* Count tokens shifted since error; after three, turn off error
status. */ status. */
@@ -780,6 +792,7 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
--yyerrstatus_; --yyerrstatus_;
yystate = yyn; yystate = yyn;
yypush_ (yystate, yylval, yylloc);
goto yynewstate; goto yynewstate;
/*-----------------------------------------------------------. /*-----------------------------------------------------------.
@@ -827,8 +840,6 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
yypop_ (yylen); yypop_ (yylen);
yylen = 0; yylen = 0;
YY_STACK_PRINT (); YY_STACK_PRINT ();
yysemantic_stack_.push (yyval);
yylocation_stack_.push (yyloc);
/* Shift the result of the reduction. */ /* Shift the result of the reduction. */
yyn = yyr1_[yyn]; yyn = yyr1_[yyn];
@@ -838,6 +849,7 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
yystate = yytable_[yystate]; yystate = yytable_[yystate];
else else
yystate = yydefgoto_[yyn - yyntokens_]; yystate = yydefgoto_[yyn - yyntokens_];
yypush_ (yystate, yyval, yyloc);
goto yynewstate; goto yynewstate;
/*------------------------------------. /*------------------------------------.
@@ -932,14 +944,13 @@ b4_error_verbose_if([, yytoken])[));
// Using YYLLOC is tempting, but would change the location of // Using YYLLOC is tempting, but would change the location of
// the lookahead. YYLOC is available though. // the lookahead. YYLOC is available though.
YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2); YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2);
yysemantic_stack_.push (yylval);
yylocation_stack_.push (yyloc);
/* Shift the error token. */ /* Shift the error token. */
YY_SYMBOL_PRINT ("Shifting", yystos_[yyn], YY_SYMBOL_PRINT ("Shifting", yystos_[yyn],
yysemantic_stack_[0], yylocation_stack_[0]); yysemantic_stack_[0], yylocation_stack_[0]);
yystate = yyn; yystate = yyn;
yypush_ (yystate, yylval, yyloc);
goto yynewstate; goto yynewstate;
/* Accept. */ /* Accept. */