From 402332c4b610a78299904bf42f37aee63c640d34 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sat, 12 Oct 2019 11:40:46 +0200 Subject: [PATCH] lalr1.cc: use computed state types This skeleton uses a single stack of state structures, so it is less likely to benefit from a stack size reduction than yacc.c (which uses several stacks: state number, value and location). But it will reduce the size of the LAC stack. This skeleton was already using int for state numbers, so, contrary to yacc.c, this brings nothing for large automata. Overall, it is still nicer to make the skeletons alike. * data/skeletons/lalr1.cc (state_type): Here. --- data/skeletons/lalr1.cc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/data/skeletons/lalr1.cc b/data/skeletons/lalr1.cc index 81ccfbd7..b9a3c98d 100644 --- a/data/skeletons/lalr1.cc +++ b/data/skeletons/lalr1.cc @@ -241,8 +241,8 @@ m4_define([b4_shared_declarations], /// Only used for debbuging output. void yy_lac_discard_ (const char* event);]])[ - /// State numbers. - typedef int state_type; + /// Stored state numbers (used for stacks). + typedef ]b4_int_type(0, m4_eval(b4_states_number - 1))[ state_type; /// Generate an error message. /// \param yystate the state where the error occurred. @@ -803,7 +803,6 @@ m4_if(b4_prefix, [yy], [], int ]b4_parser_class[::parse () { - // State. int yyn; /// Length of the RHS of the rule being reduced. int yylen = 0; @@ -916,7 +915,7 @@ b4_dollar_popdef])[]dnl --yyerrstatus_; // Shift the lookahead token. - yypush_ ("Shifting", yyn, YY_MOVE (yyla));]b4_lac_if([[ + yypush_ ("Shifting", static_cast (yyn), YY_MOVE (yyla));]b4_lac_if([[ yy_lac_discard_ ("shift");]])[ goto yynewstate; @@ -1079,7 +1078,7 @@ b4_dollar_popdef])[]dnl // Shift the error token.]b4_lac_if([[ yy_lac_discard_ ("error recovery");]])[ - error_token.state = yyn; + error_token.state = static_cast (yyn); yypush_ ("Shifting", YY_MOVE (error_token)); } goto yynewstate;