bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: yy_state_t


From: Akim Demaille
Subject: Re: yy_state_t
Date: Tue, 15 Oct 2019 08:45:00 +0200


> Le 13 oct. 2019 à 09:54, Akim Demaille <address@hidden> a écrit :
> 
> Here's what it gives.   Cheers!
> 
> commit 3c9656ec6ea39c4f1bad4ab2c153267f61015438
> Author: Akim Demaille <address@hidden>
> Date:   Sat Oct 12 11:00:05 2019 +0200
> 
>    yacc: rename types for states
> 
>    * data/skeletons/yacc.c (yy_state_num): Rename as...
>    (yy_state_t): this.
>    (yy_state_fast_t): New.
>    Use it.

Installed.

I'm ambivalent for glr.c and lalr1.cc, since they already use int everywhere 
for states, and are unlikely to benefit from the width reduction.  Except for 
the auxiliary state stack for LAC in lalr1.cc.

I do like the fact that the skeletons are more consistent between them (I will 
rename the types for states afterwards), but still...  I'd appreciate other 
opinions.

commit 838b33b033f2136caec2e0710d82cb5d02e286de
Author: Akim Demaille <address@hidden>
Date:   Sat Oct 12 10:59:24 2019 +0200

    glr: also use a computed type for states
    
    This skeleton uses a structure for states (state number, value and
    location), so it is less likely to benefit from a stack size reduction
    than yacc.c (which uses several stacks: state number, value and
    location).
    
    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/glr.c (yyStateNum): Copy the definition from yacc.c.

diff --git a/data/skeletons/glr.c b/data/skeletons/glr.c
index 64f56a62..2805a409 100644
--- a/data/skeletons/glr.c
+++ b/data/skeletons/glr.c
@@ -623,8 +623,8 @@ yytnamerr (char *yyres, const char *yystr)
 
 #endif /* !YYERROR_VERBOSE */
 
-/** State numbers, as in LALR(1) machine */
-typedef int yyStateNum;
+/** Stored state numbers (used for stacks). */
+typedef ]b4_int_type(0, m4_eval(b4_states_number - 1))[ yyStateNum;
 
 /** Rule numbers, as in LALR(1) machine */
 typedef int yyRuleNum;
@@ -2264,7 +2264,7 @@ yyrecoverSyntaxError (yyGLRStack* 
yystackp]b4_user_formals[)
               YYLLOC_DEFAULT (yyerrloc, (yystackp->yyerror_range), 2);]])[
               YY_SYMBOL_PRINT ("Shifting", yystos[yyaction],
                                &yylval, &yyerrloc);
-              yyglrShift (yystackp, 0, yyaction,
+              yyglrShift (yystackp, 0, (yyStateNum) yyaction,
                           yys->yyposn, &yylval]b4_locations_if([, 
&yyerrloc])[);
               yys = yystackp->yytops.yystates[0];
               break;
@@ -2365,7 +2365,7 @@ b4_dollar_popdef])[]dnl
                   YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
                   yychar = YYEMPTY;
                   yyposn += 1;
-                  yyglrShift (&yystack, 0, yyaction, yyposn, 
&yylval]b4_locations_if([, &yylloc])[);
+                  yyglrShift (&yystack, 0, (yyStateNum) yyaction, yyposn, 
&yylval]b4_locations_if([, &yylloc])[);
                   if (0 < yystack.yyerrState)
                     yystack.yyerrState -= 1;
                 }
@@ -2442,7 +2442,7 @@ b4_dollar_popdef])[]dnl
               /* Note that yyconflicts were handled by yyprocessOneStack.  */
               YYDPRINTF ((stderr, "On stack %ld, ", (long) yys));
               YY_SYMBOL_PRINT ("shifting", yytoken_to_shift, &yylval, &yylloc);
-              yyglrShift (&yystack, yys, yyaction, yyposn,
+              yyglrShift (&yystack, yys, (yyStateNum) yyaction, yyposn,
                           &yylval]b4_locations_if([, &yylloc])[);
               YYDPRINTF ((stderr, "Stack %ld now in state #%d\n",
                           (long) yys,












commit ec8a57bec11638964f1e2b9e23f90c74e82014db
Author: Akim Demaille <address@hidden>
Date:   Sat Oct 12 11:40:46 2019 +0200

    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.

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<state_type> (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<state_type> (yyn);
       yypush_ ("Shifting", YY_MOVE (error_token));
     }
     goto yynewstate;





reply via email to

[Prev in Thread] Current Thread [Next in Thread]