This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
handle bracket stack better in recdescent parsing
[perl5.git] / perly.y
diff --git a/perly.y b/perly.y
index 691ae94..cc27ee2 100644 (file)
--- a/perly.y
+++ b/perly.y
@@ -49,7 +49,7 @@
 
 /* FIXME for MAD - is the new mintro on while and until important?  */
 
-%start prog
+%start grammar
 
 %union {
     I32        ival; /* __DEFAULT__ (marker for regen_perly.pl;
 #endif
 }
 
+%token <ival> GRAMPROG GRAMFULLSTMT GRAMSTMTSEQ
+
 %token <i_tkval> '{' '}' '[' ']' '-' '+' '$' '@' '%' '*' '&' ';'
 
-%token <opval> WORD METHOD FUNCMETH THING PMFUNC PRIVATEREF
+%token <opval> WORD METHOD FUNCMETH THING PMFUNC PRIVATEREF QWLIST
 %token <opval> FUNC0SUB UNIOPSUB LSTOPSUB
 %token <opval> PLUGEXPR PLUGSTMT
 %token <p_tkval> LABEL
 %token <i_tkval> LOCAL MY MYSUB REQUIRE
 %token <i_tkval> COLONATTR
 
-%type <ival> prog progstart remember mremember
+%type <i_tkval> lpar_or_qw
+
+%type <ival> grammar prog progstart remember mremember
 %type <ival>  startsub startanonsub startformsub
 /* FIXME for MAD - are these two ival? */
 %type <ival> mydefsv mintro
 
-%type <opval> decl format subrout mysubrout package use peg
-
+%type <opval> fullstmt decl format subrout mysubrout package use peg
 %type <opval> block package_block mblock lineseq line loop cond else
 %type <opval> expr term subscripted scalar ary hsh arylen star amper sideff
 %type <opval> argexpr nexpr texpr iexpr mexpr mnexpr miexpr
 
 %% /* RULES */
 
+/* Top-level choice of what kind of thing yyparse was called to parse */
+grammar        :       GRAMPROG prog
+                       { $$ = $2; }
+       |       GRAMFULLSTMT fullstmt
+                       {
+                         PL_eval_root = $2;
+                         $$ = 0;
+                         yyunlex();
+                         parser->yychar = YYEOF;
+                       }
+       |       GRAMSTMTSEQ
+                       {
+                         parser->expect = XSTATE;
+                       }
+               lineseq
+                       {
+                         PL_eval_root = $3;
+                         $$ = 0;
+                       }
+       ;
+
 /* The whole program */
 prog   :       progstart
        /*CONTINUED*/   lineseq
@@ -186,21 +210,27 @@ lineseq   :       /* NULL */
                        { $$ = (OP*)NULL; }
        |       lineseq decl
                        {
-                       $$ = IF_MAD(
-                               append_list(OP_LINESEQ,
-                                   (LISTOP*)$1, (LISTOP*)$2),
-                               $1);
+                         $$ = IF_MAD(op_append_list(OP_LINESEQ, $1, $2), $1);
                        }
        |       lineseq line
-                       {   $$ = append_list(OP_LINESEQ,
-                               (LISTOP*)$1, (LISTOP*)$2);
+                       {   $$ = op_append_list(OP_LINESEQ, $1, $2);
                            PL_pad_reset_pending = TRUE;
                            if ($1 && $2)
                                PL_hints |= HINT_BLOCK_SCOPE;
                        }
        ;
 
-/* A "line" in the program */
+/* A statement, or "line", in the program */
+fullstmt:      decl
+                       { $$ = $1; }
+       |       line
+                       {
+                         PL_pad_reset_pending = TRUE;
+                         $$ = $1;
+                       }
+       ;
+
+/* A non-declaration statement */
 line   :       label cond
                        { $$ = newSTATEOP(0, PVAL($1), $2);
                          TOKEN_GETMAD($1,((LISTOP*)$$)->op_first,'L'); }
@@ -246,8 +276,7 @@ line        :       label cond
                        { $$ = newSTATEOP(0, NULL,
                                 newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
                                            NOLINE, (OP*)NULL, $1,
-                                           (OP*)NULL, 0));
-                         TOKEN_GETMAD($1,((LISTOP*)$$)->op_first,'L'); }
+                                           (OP*)NULL, 0)); }
        |       label PLUGSTMT
                        { $$ = newSTATEOP(0, PVAL($1), $2); }
        ;
@@ -289,7 +318,7 @@ else        :       /* NULL */
                        { ($2)->op_flags |= OPf_PARENS; $$ = scope($2);
                          TOKEN_GETMAD($1,$$,'o');
                        }
-       |       ELSIF '(' mexpr ')' mblock else
+       |       ELSIF lpar_or_qw mexpr ')' mblock else
                        { PL_parser->copline = (line_t)IVAL($1);
                            $$ = newCONDOP(0, newSTATEOP(OPf_SPECIAL,NULL,$3), scope($5), $6);
                            PL_hints |= HINT_BLOCK_SCOPE;
@@ -300,7 +329,7 @@ else        :       /* NULL */
        ;
 
 /* Real conditional expressions */
-cond   :       IF '(' remember mexpr ')' mblock else
+cond   :       IF lpar_or_qw remember mexpr ')' mblock else
                        { PL_parser->copline = (line_t)IVAL($1);
                            $$ = block_end($3,
                                   newCONDOP(0, $4, scope($6), $7));
@@ -308,7 +337,7 @@ cond        :       IF '(' remember mexpr ')' mblock else
                          TOKEN_GETMAD($2,$$,'(');
                          TOKEN_GETMAD($5,$$,')');
                        }
-       |       UNLESS '(' remember miexpr ')' mblock else
+       |       UNLESS lpar_or_qw remember miexpr ')' mblock else
                        { PL_parser->copline = (line_t)IVAL($1);
                            $$ = block_end($3,
                                   newCONDOP(0, $4, scope($6), $7));
@@ -319,7 +348,7 @@ cond        :       IF '(' remember mexpr ')' mblock else
        ;
 
 /* Cases for a switch statement */
-case   :       WHEN '(' remember mexpr ')' mblock
+case   :       WHEN lpar_or_qw remember mexpr ')' mblock
        { $$ = block_end($3,
                newWHENOP($4, scope($6))); }
        |       DEFAULT block
@@ -336,7 +365,7 @@ cont        :       /* NULL */
        ;
 
 /* Loops: while, until, for, and a bare block */
-loop   :       label WHILE '(' remember texpr ')' mintro mblock cont
+loop   :       label WHILE lpar_or_qw remember texpr ')' mintro mblock cont
                        { OP *innerop;
                          PL_parser->copline = (line_t)IVAL($2);
                            $$ = block_end($4,
@@ -349,7 +378,7 @@ loop        :       label WHILE '(' remember texpr ')' mintro mblock cont
                          TOKEN_GETMAD($6,innerop,')');
                        }
 
-       |       label UNTIL '(' remember iexpr ')' mintro mblock cont
+       |       label UNTIL lpar_or_qw remember iexpr ')' mintro mblock cont
                        { OP *innerop;
                          PL_parser->copline = (line_t)IVAL($2);
                            $$ = block_end($4,
@@ -361,7 +390,7 @@ loop        :       label WHILE '(' remember texpr ')' mintro mblock cont
                          TOKEN_GETMAD($3,innerop,'(');
                          TOKEN_GETMAD($6,innerop,')');
                        }
-       |       label FOR MY remember my_scalar '(' mexpr ')' mblock cont
+       |       label FOR MY remember my_scalar lpar_or_qw mexpr ')' mblock cont
                        { OP *innerop;
                          $$ = block_end($4,
                             innerop = newFOROP(0, PVAL($1), (line_t)IVAL($2),
@@ -372,7 +401,7 @@ loop        :       label WHILE '(' remember texpr ')' mintro mblock cont
                          TOKEN_GETMAD($6,((LISTOP*)innerop)->op_first->op_sibling,'(');
                          TOKEN_GETMAD($8,((LISTOP*)innerop)->op_first->op_sibling,')');
                        }
-       |       label FOR scalar '(' remember mexpr ')' mblock cont
+       |       label FOR scalar lpar_or_qw remember mexpr ')' mblock cont
                        { OP *innerop;
                          $$ = block_end($5,
                             innerop = newFOROP(0, PVAL($1), (line_t)IVAL($2),
@@ -382,7 +411,7 @@ loop        :       label WHILE '(' remember texpr ')' mintro mblock cont
                          TOKEN_GETMAD($4,((LISTOP*)innerop)->op_first->op_sibling,'(');
                          TOKEN_GETMAD($7,((LISTOP*)innerop)->op_first->op_sibling,')');
                        }
-       |       label FOR '(' remember mexpr ')' mblock cont
+       |       label FOR lpar_or_qw remember mexpr ')' mblock cont
                        { OP *innerop;
                          $$ = block_end($4,
                             innerop = newFOROP(0, PVAL($1), (line_t)IVAL($2),
@@ -392,7 +421,7 @@ loop        :       label WHILE '(' remember texpr ')' mintro mblock cont
                          TOKEN_GETMAD($3,((LISTOP*)innerop)->op_first->op_sibling,'(');
                          TOKEN_GETMAD($6,((LISTOP*)innerop)->op_first->op_sibling,')');
                        }
-       |       label FOR '(' remember mnexpr ';' texpr ';' mintro mnexpr ')'
+       |       label FOR lpar_or_qw remember mnexpr ';' texpr ';' mintro mnexpr ')'
                    mblock
                        /* basically fake up an initialize-while lineseq */
                        { OP *forop;
@@ -402,7 +431,7 @@ loop        :       label WHILE '(' remember texpr ')' mintro mblock cont
                                                IVAL($2), scalar($7),
                                                $12, $10, $9));
 #ifdef MAD
-                         forop = newUNOP(OP_NULL, 0, append_elem(OP_LINESEQ,
+                         forop = newUNOP(OP_NULL, 0, op_append_elem(OP_LINESEQ,
                                newSTATEOP(0,
                                           CopLABEL_alloc(($1)->tk_lval.pval),
                                           ($5 ? $5 : newOP(OP_NULL, 0)) ),
@@ -416,7 +445,7 @@ loop        :       label WHILE '(' remember texpr ')' mintro mblock cont
                          token_getmad($1,forop,'L');
 #else
                          if ($5) {
-                               forop = append_elem(OP_LINESEQ,
+                               forop = op_append_elem(OP_LINESEQ,
                                         newSTATEOP(0, CopLABEL_alloc($1), $5),
                                        forop);
                          }
@@ -432,7 +461,7 @@ loop        :       label WHILE '(' remember texpr ')' mintro mblock cont
        ;
 
 /* Switch blocks */
-switch :       label GIVEN '(' remember mydefsv mexpr ')' mblock
+switch :       label GIVEN lpar_or_qw remember mydefsv mexpr ')' mblock
                        { PL_parser->copline = (line_t) IVAL($2);
                            $$ = block_end($4,
                                newSTATEOP(0, PVAL($1),
@@ -667,9 +696,16 @@ package :  PACKAGE WORD WORD ';'
 
 package_block: PACKAGE WORD WORD '{' remember
                        {
+                         int save_3_latefree = $3->op_latefree;
+                         $3->op_latefree = 1;
                          package($3);
-                         if ($2)
+                         $3->op_latefree = save_3_latefree;
+                         if ($2) {
+                             int save_2_latefree = $2->op_latefree;
+                             $2->op_latefree = 1;
                              package_version($2);
+                             $2->op_latefree = save_2_latefree;
+                         }
                        }
                    lineseq '}'
                        { if (PL_parser->copline > (line_t)IVAL($4))
@@ -677,6 +713,9 @@ package_block:      PACKAGE WORD WORD '{' remember
                          $$ = block_end($5, $7);
                          TOKEN_GETMAD($4,$$,'{');
                          TOKEN_GETMAD($8,$$,'}');
+                         op_free($3);
+                         if ($2)
+                             op_free($2);
                        }
        ;
 
@@ -720,7 +759,7 @@ argexpr     :       argexpr ','
 #ifdef MAD
                          OP* op = newNULLLIST();
                          token_getmad($2,op,',');
-                         $$ = append_elem(OP_LIST, $1, op);
+                         $$ = op_append_elem(OP_LIST, $1, op);
 #else
                          $$ = $1;
 #endif
@@ -732,7 +771,7 @@ argexpr     :       argexpr ','
                              term = newUNOP(OP_NULL, 0, term);
                              token_getmad($2,term,',');
                          )
-                         $$ = append_elem(OP_LIST, $1, term);
+                         $$ = op_append_elem(OP_LIST, $1, term);
                        }
        |       term %prec PREC_LOW
        ;
@@ -740,20 +779,20 @@ argexpr   :       argexpr ','
 /* List operators */
 listop :       LSTOP indirob argexpr /* map {...} @args or print $fh @args */
                        { $$ = convert(IVAL($1), OPf_STACKED,
-                               prepend_elem(OP_LIST, newGVREF(IVAL($1),$2), $3) );
+                               op_prepend_elem(OP_LIST, newGVREF(IVAL($1),$2), $3) );
                          TOKEN_GETMAD($1,$$,'o');
                        }
        |       FUNC '(' indirob expr ')'      /* print ($fh @args */
                        { $$ = convert(IVAL($1), OPf_STACKED,
-                               prepend_elem(OP_LIST, newGVREF(IVAL($1),$3), $4) );
+                               op_prepend_elem(OP_LIST, newGVREF(IVAL($1),$3), $4) );
                          TOKEN_GETMAD($1,$$,'o');
                          TOKEN_GETMAD($2,$$,'(');
                          TOKEN_GETMAD($5,$$,')');
                        }
-       |       term ARROW method '(' listexprcom ')' /* $foo->bar(list) */
+       |       term ARROW method lpar_or_qw listexprcom ')' /* $foo->bar(list) */
                        { $$ = convert(OP_ENTERSUB, OPf_STACKED,
-                               append_elem(OP_LIST,
-                                   prepend_elem(OP_LIST, scalar($1), $5),
+                               op_append_elem(OP_LIST,
+                                   op_prepend_elem(OP_LIST, scalar($1), $5),
                                    newUNOP(OP_METHOD, 0, $3)));
                          TOKEN_GETMAD($2,$$,'A');
                          TOKEN_GETMAD($4,$$,'(');
@@ -761,20 +800,20 @@ listop    :       LSTOP indirob argexpr /* map {...} @args or print $fh @args */
                        }
        |       term ARROW method                     /* $foo->bar */
                        { $$ = convert(OP_ENTERSUB, OPf_STACKED,
-                               append_elem(OP_LIST, scalar($1),
+                               op_append_elem(OP_LIST, scalar($1),
                                    newUNOP(OP_METHOD, 0, $3)));
                          TOKEN_GETMAD($2,$$,'A');
                        }
        |       METHOD indirob listexpr              /* new Class @args */
                        { $$ = convert(OP_ENTERSUB, OPf_STACKED,
-                               append_elem(OP_LIST,
-                                   prepend_elem(OP_LIST, $2, $3),
+                               op_append_elem(OP_LIST,
+                                   op_prepend_elem(OP_LIST, $2, $3),
                                    newUNOP(OP_METHOD, 0, $1)));
                        }
        |       FUNCMETH indirob '(' listexprcom ')' /* method $object (@args) */
                        { $$ = convert(OP_ENTERSUB, OPf_STACKED,
-                               append_elem(OP_LIST,
-                                   prepend_elem(OP_LIST, $2, $4),
+                               op_append_elem(OP_LIST,
+                                   op_prepend_elem(OP_LIST, $2, $4),
                                    newUNOP(OP_METHOD, 0, $1)));
                          TOKEN_GETMAD($3,$$,'(');
                          TOKEN_GETMAD($5,$$,')');
@@ -794,8 +833,8 @@ listop      :       LSTOP indirob argexpr /* map {...} @args or print $fh @args */
                          $<opval>$ = newANONATTRSUB($2, 0, (OP*)NULL, $3); }
                    listexpr            %prec LSTOP  /* ... @bar */
                        { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
-                                append_elem(OP_LIST,
-                                  prepend_elem(OP_LIST, $<opval>4, $5), $1));
+                                op_append_elem(OP_LIST,
+                                  op_prepend_elem(OP_LIST, $<opval>4, $5), $1));
                        }
        ;
 
@@ -869,21 +908,21 @@ subscripted:    star '{' expr ';' '}'        /* *main::{something} */
                        }
        |       term ARROW '(' expr ')'     /* $subref->(@args) */
                        { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
-                                  append_elem(OP_LIST, $4,
+                                  op_append_elem(OP_LIST, $4,
                                       newCVREF(0, scalar($1))));
                          TOKEN_GETMAD($2,$$,'a');
                          TOKEN_GETMAD($3,$$,'(');
                          TOKEN_GETMAD($5,$$,')');
                        }
 
-       |       subscripted '(' expr ')'   /* $foo->{bar}->(@args) */
+       |       subscripted lpar_or_qw expr ')'   /* $foo->{bar}->(@args) */
                        { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
-                                  append_elem(OP_LIST, $3,
+                                  op_append_elem(OP_LIST, $3,
                                               newCVREF(0, scalar($1))));
                          TOKEN_GETMAD($2,$$,'(');
                          TOKEN_GETMAD($4,$$,')');
                        }
-       |       subscripted '(' ')'        /* $foo->{bar}->() */
+       |       subscripted lpar_or_qw ')'        /* $foo->{bar}->() */
                        { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
                                   newCVREF(0, scalar($1)));
                          TOKEN_GETMAD($2,$$,'(');
@@ -896,6 +935,11 @@ subscripted:    star '{' expr ';' '}'        /* *main::{something} */
                          TOKEN_GETMAD($4,$$,'[');
                          TOKEN_GETMAD($6,$$,']');
                        }
+       |       QWLIST '[' expr ']'            /* list literal slice */
+                       { $$ = newSLICEOP(0, $3, $1);
+                         TOKEN_GETMAD($2,$$,'[');
+                         TOKEN_GETMAD($4,$$,']');
+                       }
        |       '(' ')' '[' expr ']'                 /* empty list slice! */
                        { $$ = newSLICEOP(0, $4, (OP*)NULL);
                          TOKEN_GETMAD($1,$$,'(');
@@ -1062,10 +1106,10 @@ termdo  :       DO term %prec UNIOP                     /* do $filename */
                        { $$ = newUNOP(OP_NULL, OPf_SPECIAL, scope($2));
                          TOKEN_GETMAD($1,$$,'D');
                        }
-       |       DO WORD '(' ')'                         /* do somesub() */
+       |       DO WORD lpar_or_qw ')'                  /* do somesub() */
                        { $$ = newUNOP(OP_ENTERSUB,
                            OPf_SPECIAL|OPf_STACKED,
-                           prepend_elem(OP_LIST,
+                           op_prepend_elem(OP_LIST,
                                scalar(newCVREF(
                                    (OPpENTERSUB_AMPER<<8),
                                    scalar($2)
@@ -1074,10 +1118,10 @@ termdo  :       DO term %prec UNIOP                     /* do $filename */
                          TOKEN_GETMAD($3,$$,'(');
                          TOKEN_GETMAD($4,$$,')');
                        }
-       |       DO WORD '(' expr ')'                    /* do somesub(@args) */
+       |       DO WORD lpar_or_qw expr ')'             /* do somesub(@args) */
                        { $$ = newUNOP(OP_ENTERSUB,
                            OPf_SPECIAL|OPf_STACKED,
-                           append_elem(OP_LIST,
+                           op_append_elem(OP_LIST,
                                $4,
                                scalar(newCVREF(
                                    (OPpENTERSUB_AMPER<<8),
@@ -1087,17 +1131,17 @@ termdo  :       DO term %prec UNIOP                     /* do $filename */
                          TOKEN_GETMAD($3,$$,'(');
                          TOKEN_GETMAD($5,$$,')');
                        }
-       |       DO scalar '(' ')'                      /* do $subref () */
+       |       DO scalar lpar_or_qw ')'                /* do $subref () */
                        { $$ = newUNOP(OP_ENTERSUB, OPf_SPECIAL|OPf_STACKED,
-                           prepend_elem(OP_LIST,
+                           op_prepend_elem(OP_LIST,
                                scalar(newCVREF(0,scalar($2))), (OP*)NULL)); dep();
                          TOKEN_GETMAD($1,$$,'o');
                          TOKEN_GETMAD($3,$$,'(');
                          TOKEN_GETMAD($4,$$,')');
                        }
-       |       DO scalar '(' expr ')'                 /* do $subref (@args) */
+       |       DO scalar lpar_or_qw expr ')'           /* do $subref (@args) */
                        { $$ = newUNOP(OP_ENTERSUB, OPf_SPECIAL|OPf_STACKED,
-                           prepend_elem(OP_LIST,
+                           op_prepend_elem(OP_LIST,
                                $4,
                                scalar(newCVREF(0,scalar($2))))); dep();
                          TOKEN_GETMAD($1,$$,'o');
@@ -1131,6 +1175,8 @@ term      :       termbinop
                          TOKEN_GETMAD($1,$$,'(');
                          TOKEN_GETMAD($3,$$,')');
                        }
+       |       QWLIST
+                       { $$ = IF_MAD(newUNOP(OP_NULL,0,$1), $1); }
        |       '(' ')'
                        { $$ = sawparens(newNULLLIST());
                          TOKEN_GETMAD($1,$$,'(');
@@ -1149,7 +1195,7 @@ term      :       termbinop
        |       subscripted
                        { $$ = $1; }
        |       ary '[' expr ']'                     /* array slice */
-                       { $$ = prepend_elem(OP_ASLICE,
+                       { $$ = op_prepend_elem(OP_ASLICE,
                                newOP(OP_PUSHMARK, 0),
                                    newLISTOP(OP_ASLICE, 0,
                                        list($3),
@@ -1158,7 +1204,7 @@ term      :       termbinop
                          TOKEN_GETMAD($4,$$,']');
                        }
        |       ary '{' expr ';' '}'                 /* @hash{@keys} */
-                       { $$ = prepend_elem(OP_HSLICE,
+                       { $$ = op_prepend_elem(OP_HSLICE,
                                newOP(OP_PUSHMARK, 0),
                                    newLISTOP(OP_HSLICE, 0,
                                        list($3),
@@ -1172,15 +1218,15 @@ term    :       termbinop
                        { $$ = $1; }
        |       amper                                /* &foo; */
                        { $$ = newUNOP(OP_ENTERSUB, 0, scalar($1)); }
-       |       amper '(' ')'                        /* &foo() */
+       |       amper lpar_or_qw ')'                 /* &foo() */
                        { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1));
                          TOKEN_GETMAD($2,$$,'(');
                          TOKEN_GETMAD($3,$$,')');
                        }
-       |       amper '(' expr ')'                   /* &foo(@args) */
+       |       amper lpar_or_qw expr ')'            /* &foo(@args) */
                        {
                          $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
-                               append_elem(OP_LIST, $3, scalar($1)));
+                               op_append_elem(OP_LIST, $3, scalar($1)));
                          DO_MAD({
                              OP* op = $$;
                              if (op->op_type == OP_CONST) { /* defeat const fold */
@@ -1192,7 +1238,7 @@ term      :       termbinop
                        }
        |       NOAMP WORD listexpr                  /* foo(@args) */
                        { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
-                           append_elem(OP_LIST, $3, scalar($2)));
+                           op_append_elem(OP_LIST, $3, scalar($2)));
                          TOKEN_GETMAD($1,$$,'o');
                        }
        |       LOOPEX  /* loop exiting command (goto, last, dump, etc) */
@@ -1232,7 +1278,7 @@ term      :       termbinop
                        { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1)); }
        |       UNIOPSUB term                        /* Sub treated as unop */
                        { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
-                           append_elem(OP_LIST, $2, scalar($1))); }
+                           op_append_elem(OP_LIST, $2, scalar($1))); }
        |       FUNC0                                /* Nullary operator */
                        { $$ = newOP(IVAL($1), 0);
                          TOKEN_GETMAD($1,$$,'o');
@@ -1322,17 +1368,14 @@ listexprcom:    /* NULL */
                        { $$ = (OP*)NULL; }
        |       expr
                        { $$ = $1; }
-       |       expr ','
-                       {
-#ifdef MAD
-                         OP* op = newNULLLIST();
-                         token_getmad($2,op,',');
-                         $$ = append_elem(OP_LIST, $1, op);
-#else
-                         $$ = $1;
-#endif
+       ;
 
-                       }
+lpar_or_qw:    '('
+                       { $$ = $1; }
+       |       QWLIST
+                       { munge_qwlist_to_paren_list($1); }
+               '('
+                       { $$ = $3; }
        ;
 
 /* A little bit of trickery to make "for my $foo (@bar)" actually be