Re: [PATCH] Lighten up glob
[p5sagit/p5-mst-13.2.git] / perly.y
diff --git a/perly.y b/perly.y
index 93e5f77..a30f4ce 100644 (file)
--- a/perly.y
+++ b/perly.y
@@ -1,6 +1,6 @@
 /*    perly.y
  *
- *    Copyright (c) 1991-1997, Larry Wall
+ *    Copyright (c) 1991-2001, Larry Wall
  *
  *    You may distribute under the terms of either the GNU General Public
  *    License or the Artistic License, as specified in the README file.
@@ -16,7 +16,9 @@
 #include "EXTERN.h"
 #define PERL_IN_PERLY_C
 #include "perl.h"
-
+#ifdef EBCDIC
+#undef YYDEBUG
+#endif
 #define dep() deprecate("\"do\" to call subroutines")
 
 /* stuff included here to make perly_c.diff apply better */
@@ -39,22 +41,7 @@ struct ysv {
     YYSTYPE oldyylval;
 };
 
-static void yydestruct(void *ptr);
-
-static void
-yydestruct(void *ptr)
-{
-    struct ysv* ysave = (struct ysv*)ptr;
-    if (ysave->yyss) Safefree(ysave->yyss);
-    if (ysave->yyvs) Safefree(ysave->yyvs);
-    yydebug    = ysave->oldyydebug;
-    yynerrs    = ysave->oldyynerrs;
-    yyerrflag  = ysave->oldyyerrflag;
-    yychar     = ysave->oldyychar;
-    yyval      = ysave->oldyyval;
-    yylval     = ysave->oldyylval;
-    Safefree(ysave);
-}
+static void yydestruct(pTHXo_ void *ptr);
 
 %}
 
@@ -76,6 +63,7 @@ yydestruct(void *ptr)
 
 #ifdef USE_PURE_BISON
 #define YYLEX_PARAM (&yychar)
+#define yylex yylex_r
 #endif
 
 %}
@@ -139,7 +127,7 @@ yydestruct(void *ptr)
 prog   :       /* NULL */
                {
 #if defined(YYDEBUG) && defined(DEBUGGING)
-                   yydebug = (PL_debug & 1);
+                   yydebug = (DEBUG_p_TEST);
 #endif
                    PL_expect = XSTATE;
                }
@@ -262,13 +250,20 @@ loop      :       label WHILE '(' remember mtexpr ')' mblock cont
                                 newFOROP(0, $1, $2, Nullop, $5, $7, $8)); }
        |       label FOR '(' remember mnexpr ';' mtexpr ';' mnexpr ')' mblock
                        /* basically fake up an initialize-while lineseq */
-                       { OP *forop = append_elem(OP_LINESEQ,
-                                       scalar($5),
-                                       newWHILEOP(0, 1, (LOOP*)Nullop,
-                                                  $2, scalar($7),
-                                                  $11, scalar($9)));
+                       { OP *forop;
                          PL_copline = $2;
-                         $$ = block_end($4, newSTATEOP(0, $1, forop)); }
+                         forop = newSTATEOP(0, $1,
+                                           newWHILEOP(0, 1, (LOOP*)Nullop,
+                                               $2, scalar($7),
+                                               $11, $9));
+                         if ($5) {
+                               forop = append_elem(OP_LINESEQ,
+                                        newSTATEOP(0, ($1?savepv($1):Nullch),
+                                                  $5),
+                                       forop);
+                         }
+
+                         $$ = block_end($4, forop); }
        |       label block cont  /* a block is a loop that happens once */
                        { $$ = newSTATEOP(0, $1,
                                 newWHILEOP(0, 1, (LOOP*)Nullop,
@@ -281,7 +276,7 @@ nexpr       :       /* NULL */
        ;
 
 texpr  :       /* NULL means true */
-                       { (void)scan_num("1"); $$ = yylval.opval; }
+                       { (void)scan_num("1", &yylval); $$ = yylval.opval; }
        |       expr
        ;
 
@@ -352,7 +347,7 @@ startformsub:       /* NULL */      /* start a format subroutine scope */
 
 subname        :       WORD    { STRLEN n_a; char *name = SvPV(((SVOP*)$1)->op_sv,n_a);
                          if (strEQ(name, "BEGIN") || strEQ(name, "END")
-                             || strEQ(name, "INIT"))
+                             || strEQ(name, "INIT") || strEQ(name, "CHECK"))
                              CvSPECIAL_on(PL_compcv);
                          $$ = $1; }
        ;