This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
yyparse: replace some gotos with a while(1) loop
authorDavid Mitchell <davem@iabyn.com>
Sat, 3 Dec 2016 15:11:11 +0000 (15:11 +0000)
committerDavid Mitchell <davem@iabyn.com>
Mon, 5 Dec 2016 11:54:03 +0000 (11:54 +0000)
Just as efficient, and more readable.
Welcome to 1970's structured programming!

perly.c

diff --git a/perly.c b/perly.c
index ac6112a..0aff507 100644 (file)
--- a/perly.c
+++ b/perly.c
@@ -293,6 +293,7 @@ Perl_yyparse (pTHX_ int gramtype)
 `------------------------------------------------------------*/
   yynewstate:
 
+    while (1) {
     yystate = ps->state;
 
     YYDPRINTF ((Perl_debug_log, "Entering state %d\n", yystate));
@@ -326,7 +327,7 @@ Perl_yyparse (pTHX_ int gramtype)
 
     yyn = yypact[yystate];
     if (yyn == YYPACT_NINF)
-       goto yydefault;
+       break;
 
     /* Not known => get a lookahead token if don't already have one.  */
 
@@ -360,7 +361,8 @@ Perl_yyparse (pTHX_ int gramtype)
      * part of the  <=YYLAST test for speed */
     yyn += yytoken;
     if ((unsigned int)yyn > YYLAST || yycheck[yyn] != yytoken)
-       goto yydefault;
+       break;
+
     yyn = yytable[yyn];
     if (yyn <= 0) {
        if (yyn == 0 || yyn == YYTABLE_NINF)
@@ -393,18 +395,15 @@ Perl_yyparse (pTHX_ int gramtype)
     if (parser->yyerrstatus)
        parser->yyerrstatus--;
 
-    goto yynewstate;
+    }
 
 
   /*-----------------------------------------------------------.
-  | yydefault -- do the default action for the current state.  |
+  | do the default action for the current state.  |
   `-----------------------------------------------------------*/
-  yydefault:
     yyn = yydefact[yystate];
     if (yyn == 0)
        goto yyerrlab;
-    goto yyreduce;
-
 
   /*-----------------------------.
   | yyreduce -- Do a reduction.  |