This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Remove note of test failures on FAT that were fixed by perl #21442's fixes
[perl5.git] / perly.y
diff --git a/perly.y b/perly.y
index 3f6879e..1047913 100644 (file)
--- a/perly.y
+++ b/perly.y
@@ -1,7 +1,7 @@
 /*    perly.y
  *
  *    Copyright (c) 1991-2002, 2003, 2004, 2005, 2006 Larry Wall
- *    Copyright (c) 2007, 2008 by Larry Wall and others
+ *    Copyright (c) 2007, 2008, 2009, 2010, 2011 by Larry Wall and others
  *
  *    You may distribute under the terms of either the GNU General Public
  *    License or the Artistic License, as specified in the README file.
 #endif
 }
 
-%token <ival> GRAMPROG GRAMBLOCK GRAMFULLSTMT GRAMSTMTSEQ
+%token <ival> GRAMPROG GRAMEXPR GRAMBLOCK GRAMBARESTMT GRAMFULLSTMT GRAMSTMTSEQ
 
-%token <i_tkval> '{' '}' '[' ']' '-' '+' '$' '@' '%' '*' '&' ';'
+%token <i_tkval> '{' '}' '[' ']' '-' '+' '$' '@' '%' '*' '&' ';' '=' '.'
 
 %token <opval> WORD METHOD FUNCMETH THING PMFUNC PRIVATEREF QWLIST
-%token <opval> FUNC0SUB UNIOPSUB LSTOPSUB
+%token <opval> FUNC0OP FUNC0SUB UNIOPSUB LSTOPSUB
 %token <opval> PLUGEXPR PLUGSTMT
 %token <p_tkval> LABEL
 %token <i_tkval> FORMAT SUB ANONSUB PACKAGE USE
 %token <i_tkval> FUNC0 FUNC1 FUNC UNIOP LSTOP
 %token <i_tkval> RELOP EQOP MULOP ADDOP
 %token <i_tkval> DOLSHARP DO HASHBRACK NOAMP
-%token <i_tkval> LOCAL MY MYSUB REQUIRE
-%token <i_tkval> COLONATTR
+%token <i_tkval> LOCAL MY REQUIRE
+%token <i_tkval> COLONATTR FORMLBRACK FORMRBRACK
 
-%type <i_tkval> lpar_or_qw
-
-%type <ival> grammar prog progstart remember mremember
+%type <ival> grammar remember mremember
 %type <ival>  startsub startanonsub startformsub
 /* FIXME for MAD - are these two ival? */
-%type <ival> mydefsv mintro
+%type <ival> mintro
 
-%type <opval> stmtseq fullstmt barestmt block mblock else
+%type <opval> stmtseq fullstmt labfullstmt barestmt block mblock else
 %type <opval> expr term subscripted scalar ary hsh arylen star amper sideff
-%type <opval> argexpr nexpr texpr iexpr mexpr mnexpr miexpr
-%type <opval> listexpr listexprcom indirob listop method
-%type <opval> formname subname proto subbody cont my_scalar
+%type <opval> sliceme kvslice gelem
+%type <opval> listexpr nexpr texpr iexpr mexpr mnexpr miexpr
+%type <opval> optlistexpr optexpr indirob listop method
+%type <opval> formname subname proto optsubbody cont my_scalar formblock
 %type <opval> subattrlist myattrlist myattrterm myterm
-%type <opval> termbinop termunop anonymous termdo
-%type <p_tkval> label
+%type <opval> realsubbody subsignature termbinop termunop anonymous termdo
+%type <opval> formstmtseq formline formarg
 
 %nonassoc <i_tkval> PREC_LOW
 %nonassoc LOOPEX
 %left <i_tkval> MATCHOP
 %right <i_tkval> '!' '~' UMINUS REFGEN
 %right <i_tkval> POWOP
-%nonassoc <i_tkval> PREINC PREDEC POSTINC POSTDEC
+%nonassoc <i_tkval> PREINC PREDEC POSTINC POSTDEC POSTJOIN
 %left <i_tkval> ARROW
 %nonassoc <i_tkval> ')'
 %left <i_tkval> '('
 %% /* RULES */
 
 /* Top-level choice of what kind of thing yyparse was called to parse */
-grammar        :       GRAMPROG prog
-                       { $$ = $2; }
+grammar        :       GRAMPROG
+                       {
+                         PL_parser->expect = XSTATE;
+                       }
+               remember stmtseq
+                       {
+                         newPROG(block_end($3,$4));
+                         $$ = 0;
+                       }
+       |       GRAMEXPR
+                       {
+                         parser->expect = XTERM;
+                       }
+               optexpr
+                       {
+                         PL_eval_root = $3;
+                         $$ = 0;
+                       }
        |       GRAMBLOCK
                        {
                          parser->expect = XBLOCK;
@@ -153,6 +168,18 @@ grammar    :       GRAMPROG prog
                          yyunlex();
                          parser->yychar = YYEOF;
                        }
+       |       GRAMBARESTMT
+                       {
+                         parser->expect = XSTATE;
+                       }
+               barestmt
+                       {
+                         PL_pad_reset_pending = TRUE;
+                         PL_eval_root = $3;
+                         $$ = 0;
+                         yyunlex();
+                         parser->yychar = YYEOF;
+                       }
        |       GRAMFULLSTMT
                        {
                          parser->expect = XSTATE;
@@ -176,12 +203,6 @@ grammar    :       GRAMPROG prog
                        }
        ;
 
-/* The whole program */
-prog   :       progstart
-       /*CONTINUED*/   stmtseq
-                       { $$ = $1; newPROG(block_end($1,$2)); }
-       ;
-
 /* An ordinary block */
 block  :       '{' remember stmtseq '}'
                        { if (PL_parser->copline > (line_t)IVAL($1))
@@ -192,21 +213,20 @@ block     :       '{' remember stmtseq '}'
                        }
        ;
 
-remember:      /* NULL */      /* start a full lexical scope */
-                       { $$ = block_start(TRUE); }
-       ;
-
-mydefsv:       /* NULL */      /* lexicalize $_ */
-                       { $$ = (I32) Perl_allocmy(aTHX_ STR_WITH_LEN("$_"), 0); }
+/* format body */
+formblock:     '=' remember ';' FORMRBRACK formstmtseq ';' '.'
+                       { if (PL_parser->copline > (line_t)IVAL($1))
+                             PL_parser->copline = (line_t)IVAL($1);
+                         $$ = block_end($2, $5);
+                         TOKEN_GETMAD($1,$$,'{');
+                         TOKEN_GETMAD($7,$$,'}');
+                       }
        ;
 
-progstart:
-               {
-                   PL_parser->expect = XSTATE; $$ = block_start(TRUE);
-               }
+remember:      /* NULL */      /* start a full lexical scope */
+                       { $$ = block_start(TRUE); }
        ;
 
-
 mblock :       '{' mremember stmtseq '}'
                        { if (PL_parser->copline > (line_t)IVAL($1))
                              PL_parser->copline = (line_t)IVAL($1);
@@ -231,17 +251,45 @@ stmtseq   :       /* NULL */
                        }
        ;
 
-/* A statement in the program, including optional label */
-fullstmt:      label barestmt
+/* A sequence of format lines */
+formstmtseq:   /* NULL */
+                       { $$ = (OP*)NULL; }
+       |       formstmtseq formline
+                       {   $$ = op_append_list(OP_LINESEQ, $1, $2);
+                           PL_pad_reset_pending = TRUE;
+                           if ($1 && $2)
+                               PL_hints |= HINT_BLOCK_SCOPE;
+                       }
+       ;
+
+/* A statement in the program, including optional labels */
+fullstmt:      barestmt
                        {
-                         if (PVAL($1) || $2) {
-                             $$ = newSTATEOP(0, PVAL($1), $2);
-                             TOKEN_GETMAD($1,
-                                 $2 ? cLISTOPx($$)->op_first : $$, 'L');
+                         if($1) {
+                             $$ = newSTATEOP(0, NULL, $1);
                          } else {
-                             $$ = IF_MAD(newOP(OP_NULL, 0), $2);
+                             $$ = IF_MAD(newOP(OP_NULL, 0), NULL);
                          }
                        }
+       |       labfullstmt
+                       { $$ = $1; }
+       ;
+
+labfullstmt:   LABEL barestmt
+                       {
+                         $$ = newSTATEOP(SVf_UTF8
+                                          * PVAL($1)[strlen(PVAL($1))+1],
+                                         PVAL($1), $2);
+                         TOKEN_GETMAD($1,
+                             $2 ? cLISTOPx($$)->op_first : $$, 'L');
+                       }
+       |       LABEL labfullstmt
+                       {
+                         $$ = newSTATEOP(SVf_UTF8
+                                          * PVAL($1)[strlen(PVAL($1))+1],
+                                         PVAL($1), $2);
+                         TOKEN_GETMAD($1, cLISTOPx($$)->op_first, 'L');
+                       }
        ;
 
 /* A bare statement, lacking label and other aspects of state op */
@@ -252,10 +300,9 @@ barestmt:  PLUGSTMT
                          $$ = newOP(OP_NULL,0);
                          TOKEN_GETMAD($1,$$,'p');
                        }
-       |       FORMAT startformsub formname block
+       |       FORMAT startformsub formname formblock
                        {
                          CV *fmtcv = PL_compcv;
-                         SvREFCNT_inc_simple_void(PL_compcv);
 #ifdef MAD
                          $$ = newFORM($2, $3, $4);
                          prepend_madprops($1->tk_mad, $$, 'F');
@@ -265,43 +312,60 @@ barestmt: PLUGSTMT
                          newFORM($2, $3, $4);
                          $$ = (OP*)NULL;
 #endif
-                         if (CvOUTSIDE(fmtcv) && !CvUNIQUE(CvOUTSIDE(fmtcv))) {
+                         if (CvOUTSIDE(fmtcv) && !CvEVAL(CvOUTSIDE(fmtcv))) {
                              SvREFCNT_inc_simple_void(fmtcv);
-                             pad_add_anon((SV*)fmtcv, OP_NULL);
+                             pad_add_anon(fmtcv, OP_NULL);
                          }
                        }
-       |       SUB startsub subname proto subattrlist subbody
+       |       SUB subname startsub
+                       {
+                         if ($2->op_type == OP_CONST) {
+                           const char *const name =
+                               SvPV_nolen_const(((SVOP*)$2)->op_sv);
+                           if (strEQ(name, "BEGIN") || strEQ(name, "END")
+                             || strEQ(name, "INIT") || strEQ(name, "CHECK")
+                             || strEQ(name, "UNITCHECK"))
+                             CvSPECIAL_on(PL_compcv);
+                         }
+                         else
+                         /* State subs inside anonymous subs need to be
+                            clonable themselves. */
+                         if (CvANON(CvOUTSIDE(PL_compcv))
+                          || CvCLONE(CvOUTSIDE(PL_compcv))
+                          || !PadnameIsSTATE(PadlistNAMESARRAY(CvPADLIST(
+                                               CvOUTSIDE(PL_compcv)
+                                            ))[$2->op_targ]))
+                             CvCLONE_on(PL_compcv);
+                         PL_parser->in_my = 0;
+                         PL_parser->in_my_stash = NULL;
+                       }
+               proto subattrlist optsubbody
                        {
                          SvREFCNT_inc_simple_void(PL_compcv);
 #ifdef MAD
                          {
                              OP* o = newSVOP(OP_ANONCODE, 0,
-                               (SV*)newATTRSUB($2, $3, $4, $5, $6));
+                               (SV*)(
+#endif
+                         $2->op_type == OP_CONST
+                             ? newATTRSUB($3, $2, $5, $6, $7)
+                             : newMYSUB($3, $2, $5, $6, $7)
+#ifdef MAD
+                               ));
                              $$ = newOP(OP_NULL,0);
                              op_getmad(o,$$,'&');
-                             op_getmad($3,$$,'n');
-                             op_getmad($4,$$,'s');
-                             op_getmad($5,$$,'a');
+                             op_getmad($2,$$,'n');
+                             op_getmad($5,$$,'s');
+                             op_getmad($6,$$,'a');
                              token_getmad($1,$$,'d');
-                             append_madprops($6->op_madprop, $$, 0);
-                             $6->op_madprop = 0;
+                             append_madprops($7->op_madprop, $$, 0);
+                             $7->op_madprop = 0;
                          }
 #else
-                         newATTRSUB($2, $3, $4, $5, $6);
-                         $$ = (OP*)NULL;
-#endif
-                       }
-       |       MYSUB startsub subname proto subattrlist subbody
-                       {
-                         /* Unimplemented "my sub foo { }" */
-                         SvREFCNT_inc_simple_void(PL_compcv);
-#ifdef MAD
-                         $$ = newMYSUB($2, $3, $4, $5, $6);
-                         token_getmad($1,$$,'d');
-#else
-                         newMYSUB($2, $3, $4, $5, $6);
+                         ;
                          $$ = (OP*)NULL;
 #endif
+                         intro_my();
                        }
        |       PACKAGE WORD WORD ';'
                        {
@@ -320,7 +384,7 @@ barestmt:   PLUGSTMT
                        }
        |       USE startsub
                        { CvSPECIAL_on(PL_compcv); /* It's a BEGIN {} */ }
-               WORD WORD listexpr ';'
+               WORD WORD optlistexpr ';'
                        {
                          SvREFCNT_inc_simple_void(PL_compcv);
 #ifdef MAD
@@ -335,33 +399,40 @@ barestmt: PLUGSTMT
                          $$ = (OP*)NULL;
 #endif
                        }
-       |       IF lpar_or_qw remember mexpr ')' mblock else
+       |       IF '(' remember mexpr ')' mblock else
                        {
-                         $$ = block_end($3, newCONDOP(0, $4, scope($6), $7));
+                         $$ = block_end($3,
+                             newCONDOP(0, $4, op_scope($6), $7));
                          TOKEN_GETMAD($1,$$,'I');
                          TOKEN_GETMAD($2,$$,'(');
                          TOKEN_GETMAD($5,$$,')');
                          PL_parser->copline = (line_t)IVAL($1);
                        }
-       |       UNLESS lpar_or_qw remember miexpr ')' mblock else
+       |       UNLESS '(' remember miexpr ')' mblock else
                        {
-                         $$ = block_end($3, newCONDOP(0, $4, scope($6), $7));
+                         $$ = block_end($3,
+                             newCONDOP(0, $4, op_scope($6), $7));
                          TOKEN_GETMAD($1,$$,'I');
                          TOKEN_GETMAD($2,$$,'(');
                          TOKEN_GETMAD($5,$$,')');
                          PL_parser->copline = (line_t)IVAL($1);
                        }
-       |       GIVEN lpar_or_qw remember mydefsv mexpr ')' mblock
+       |       GIVEN '(' remember mexpr ')' mblock
                        {
+                         const PADOFFSET offset = pad_findmy_pvs("$_", 0);
                          $$ = block_end($3,
-                                 newGIVENOP($5, scope($7), (PADOFFSET)$4));
+                                 newGIVENOP($4, op_scope($6),
+                                   offset == NOT_IN_PAD
+                                   || PAD_COMPNAME_FLAGS_isOUR(offset)
+                                     ? 0
+                                     : offset));
                          PL_parser->copline = (line_t)IVAL($1);
                        }
-       |       WHEN lpar_or_qw remember mexpr ')' mblock
-                       { $$ = block_end($3, newWHENOP($4, scope($6))); }
+       |       WHEN '(' remember mexpr ')' mblock
+                       { $$ = block_end($3, newWHENOP($4, op_scope($6))); }
        |       DEFAULT block
-                       { $$ = newWHENOP(0, scope($2)); }
-       |       WHILE lpar_or_qw remember texpr ')' mintro mblock cont
+                       { $$ = newWHENOP(0, op_scope($2)); }
+       |       WHILE '(' remember texpr ')' mintro mblock cont
                        {
                          $$ = block_end($3,
                                  newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
@@ -371,7 +442,7 @@ barestmt:   PLUGSTMT
                          TOKEN_GETMAD($5,$$,')');
                          PL_parser->copline = (line_t)IVAL($1);
                        }
-       |       UNTIL lpar_or_qw remember iexpr ')' mintro mblock cont
+       |       UNTIL '(' remember iexpr ')' mintro mblock cont
                        {
                          $$ = block_end($3,
                                  newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
@@ -381,7 +452,7 @@ barestmt:   PLUGSTMT
                          TOKEN_GETMAD($5,$$,')');
                          PL_parser->copline = (line_t)IVAL($1);
                        }
-       |       FOR lpar_or_qw remember mnexpr ';' texpr ';' mintro mnexpr ')'
+       |       FOR '(' remember mnexpr ';' texpr ';' mintro mnexpr ')'
                mblock
                        {
                          OP *initop = IF_MAD($4 ? $4 : newOP(OP_NULL, 0), $4);
@@ -402,7 +473,7 @@ barestmt:   PLUGSTMT
                          TOKEN_GETMAD($10,$$,')');
                          PL_parser->copline = (line_t)IVAL($1);
                        }
-       |       FOR MY remember my_scalar lpar_or_qw mexpr ')' mblock cont
+       |       FOR MY remember my_scalar '(' mexpr ')' mblock cont
                        {
                          $$ = block_end($3, newFOROP(0, $4, $6, $8, $9));
                          TOKEN_GETMAD($1,$$,'W');
@@ -411,16 +482,16 @@ barestmt: PLUGSTMT
                          TOKEN_GETMAD($7,$$,')');
                          PL_parser->copline = (line_t)IVAL($1);
                        }
-       |       FOR scalar lpar_or_qw remember mexpr ')' mblock cont
+       |       FOR scalar '(' remember mexpr ')' mblock cont
                        {
                          $$ = block_end($4, newFOROP(0,
-                                     mod($2, OP_ENTERLOOP), $5, $7, $8));
+                                     op_lvalue($2, OP_ENTERLOOP), $5, $7, $8));
                          TOKEN_GETMAD($1,$$,'W');
                          TOKEN_GETMAD($3,$$,'(');
                          TOKEN_GETMAD($6,$$,')');
                          PL_parser->copline = (line_t)IVAL($1);
                        }
-       |       FOR lpar_or_qw remember mexpr ')' mblock cont
+       |       FOR '(' remember mexpr ')' mblock cont
                        {
                          $$ = block_end($3,
                                  newFOROP(0, (OP*)NULL, $4, $6, $7));
@@ -434,19 +505,12 @@ barestmt: PLUGSTMT
                          /* a block is a loop that happens once */
                          $$ = newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
                                  (OP*)NULL, $1, $2, 0);
-                         PL_parser->copline = NOLINE;
                        }
        |       PACKAGE WORD WORD '{' remember
                        {
-                         int save_3_latefree = $3->op_latefree;
-                         $3->op_latefree = 1;
                          package($3);
-                         $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;
                          }
                        }
                stmtseq '}'
@@ -454,9 +518,6 @@ barestmt:   PLUGSTMT
                          /* a block is a loop that happens once */
                          $$ = newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
                                  (OP*)NULL, block_end($5, $7), (OP*)NULL, 0);
-                         op_free($3);
-                         if ($2)
-                             op_free($2);
                          TOKEN_GETMAD($4,$$,'{');
                          TOKEN_GETMAD($8,$$,'}');
                          if (PL_parser->copline > (line_t)IVAL($4))
@@ -477,6 +538,36 @@ barestmt:  PLUGSTMT
                        }
        ;
 
+/* Format line */
+formline:      THING formarg
+                       { OP *list;
+                         if ($2) {
+                             OP *term = $2;
+                             DO_MAD(term = newUNOP(OP_NULL, 0, term));
+                             list = op_append_elem(OP_LIST, $1, term);
+                         }
+                         else {
+#ifdef MAD
+                             OP *op = newNULLLIST();
+                             list = op_append_elem(OP_LIST, $1, op);
+#else
+                             list = $1;
+#endif
+                         }
+                         if (PL_parser->copline == NOLINE)
+                              PL_parser->copline = CopLINE(PL_curcop)-1;
+                         else PL_parser->copline--;
+                         $$ = newSTATEOP(0, NULL,
+                                         convert(OP_FORMLINE, 0, list));
+                       }
+       ;
+
+formarg        :       /* NULL */
+                       { $$ = NULL; }
+       |       FORMLBRACK stmtseq FORMRBRACK
+                       { $$ = op_unscope($2); }
+       ;
+
 /* An expression which may have a side-effect */
 sideff :       error
                        { $$ = (OP*)NULL; }
@@ -504,20 +595,24 @@ sideff    :       error
                          PL_parser->copline = (line_t)IVAL($2);
                        }
        |       expr WHEN expr
-                       { $$ = newWHENOP($3, scope($1)); }
+                       { $$ = newWHENOP($3, op_scope($1)); }
        ;
 
 /* else and elsif blocks */
 else   :       /* NULL */
                        { $$ = (OP*)NULL; }
        |       ELSE mblock
-                       { ($2)->op_flags |= OPf_PARENS; $$ = scope($2);
+                       {
+                         ($2)->op_flags |= OPf_PARENS;
+                         $$ = op_scope($2);
                          TOKEN_GETMAD($1,$$,'o');
                        }
-       |       ELSIF lpar_or_qw mexpr ')' mblock else
+       |       ELSIF '(' 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;
+                           $$ = newCONDOP(0,
+                               newSTATEOP(OPf_SPECIAL,NULL,$3),
+                               op_scope($5), $6);
+                         PL_hints |= HINT_BLOCK_SCOPE;
                          TOKEN_GETMAD($1,$$,'I');
                          TOKEN_GETMAD($2,$$,'(');
                          TOKEN_GETMAD($4,$$,')');
@@ -528,7 +623,8 @@ else        :       /* NULL */
 cont   :       /* NULL */
                        { $$ = (OP*)NULL; }
        |       CONTINUE block
-                       { $$ = scope($2);
+                       {
+                         $$ = op_scope($2);
                          TOKEN_GETMAD($1,$$,'o');
                        }
        ;
@@ -571,20 +667,6 @@ miexpr     :       iexpr
                        { $$ = $1; intro_my(); }
        ;
 
-/* Optional "MAIN:"-style loop labels */
-label  :       /* empty */
-                       {
-#ifdef MAD
-                         YYSTYPE tmplval;
-                         tmplval.pval = NULL;
-                         $$ = newTOKEN(OP_NULL, tmplval, 0);
-#else
-                         $$ = NULL;
-#endif
-                       }
-       |       LABEL
-       ;
-
 formname:      WORD            { $$ = $1; }
        |       /* NULL */      { $$ = (OP*)NULL; }
        ;
@@ -606,12 +688,8 @@ startformsub:      /* NULL */      /* start a format subroutine scope */
        ;
 
 /* Name of a subroutine - must be a bareword, could be special */
-subname        :       WORD    { const char *const name = SvPV_nolen_const(((SVOP*)$1)->op_sv);
-                         if (strEQ(name, "BEGIN") || strEQ(name, "END")
-                             || strEQ(name, "INIT") || strEQ(name, "CHECK")
-                             || strEQ(name, "UNITCHECK"))
-                             CvSPECIAL_on(PL_compcv);
-                         $$ = $1; }
+subname        :       WORD
+       |       PRIVATEREF
        ;
 
 /* Subroutine prototype */
@@ -650,8 +728,40 @@ myattrlist:        COLONATTR THING
                        }
        ;
 
-/* Subroutine body - either null or a block */
-subbody        :       block   { $$ = $1; }
+/* Optional subroutine signature */
+subsignature:  /* NULL */ { $$ = (OP*)NULL; }
+       |       '('
+                       {
+                         if (!FEATURE_SIGNATURES_IS_ENABLED)
+                           Perl_croak(aTHX_ "Experimental "
+                               "subroutine signatures not enabled");
+                         Perl_ck_warner_d(aTHX_
+                               packWARN(WARN_EXPERIMENTAL__SIGNATURES),
+                               "The signatures feature is experimental");
+                         $<opval>$ = parse_subsignature();
+                       }
+               ')'
+                       {
+                         $$ = op_append_list(OP_LINESEQ, $<opval>2,
+                               newSTATEOP(0, NULL, sawparens(newNULLLIST())));
+                         PL_parser->expect = XBLOCK;
+                       }
+       ;
+
+/* Subroutine body - block with optional signature */
+realsubbody:   remember subsignature '{' stmtseq '}'
+                       {
+                         if (PL_parser->copline > (line_t)IVAL($3))
+                             PL_parser->copline = (line_t)IVAL($3);
+                         $$ = block_end($1,
+                               op_append_list(OP_LINESEQ, $2, $4));
+                         TOKEN_GETMAD($3,$$,'{');
+                         TOKEN_GETMAD($5,$$,'}');
+                       }
+       ;
+
+/* Optional subroutine body, for named subroutine declaration */
+optsubbody:    realsubbody { $$ = $1; }
        |       ';'     { $$ = IF_MAD(
                                    newOP(OP_NULL,0),
                                    (OP*)NULL
@@ -674,11 +784,11 @@ expr      :       expr ANDOP expr
                        { $$ = newLOGOP(OP_DOR, 0, $1, $3);
                          TOKEN_GETMAD($2,$$,'o');
                        }
-       |       argexpr %prec PREC_LOW
+       |       listexpr %prec PREC_LOW
        ;
 
 /* Expressions are a list of terms joined by commas */
-argexpr        :       argexpr ','
+listexpr:      listexpr ','
                        {
 #ifdef MAD
                          OP* op = newNULLLIST();
@@ -688,7 +798,7 @@ argexpr     :       argexpr ','
                          $$ = $1;
 #endif
                        }
-       |       argexpr ',' term
+       |       listexpr ',' term
                        { 
                          OP* term = $3;
                          DO_MAD(
@@ -701,7 +811,7 @@ argexpr     :       argexpr ','
        ;
 
 /* List operators */
-listop :       LSTOP indirob argexpr /* map {...} @args or print $fh @args */
+listop :       LSTOP indirob listexpr /* map {...} @args or print $fh @args */
                        { $$ = convert(IVAL($1), OPf_STACKED,
                                op_prepend_elem(OP_LIST, newGVREF(IVAL($1),$2), $3) );
                          TOKEN_GETMAD($1,$$,'o');
@@ -713,7 +823,7 @@ listop      :       LSTOP indirob argexpr /* map {...} @args or print $fh @args */
                          TOKEN_GETMAD($2,$$,'(');
                          TOKEN_GETMAD($5,$$,')');
                        }
-       |       term ARROW method lpar_or_qw listexprcom ')' /* $foo->bar(list) */
+       |       term ARROW method '(' optexpr ')' /* $foo->bar(list) */
                        { $$ = convert(OP_ENTERSUB, OPf_STACKED,
                                op_append_elem(OP_LIST,
                                    op_prepend_elem(OP_LIST, scalar($1), $5),
@@ -728,13 +838,13 @@ listop    :       LSTOP indirob argexpr /* map {...} @args or print $fh @args */
                                    newUNOP(OP_METHOD, 0, $3)));
                          TOKEN_GETMAD($2,$$,'A');
                        }
-       |       METHOD indirob listexpr              /* new Class @args */
+       |       METHOD indirob optlistexpr           /* new Class @args */
                        { $$ = convert(OP_ENTERSUB, OPf_STACKED,
                                op_append_elem(OP_LIST,
                                    op_prepend_elem(OP_LIST, $2, $3),
                                    newUNOP(OP_METHOD, 0, $1)));
                        }
-       |       FUNCMETH indirob '(' listexprcom ')' /* method $object (@args) */
+       |       FUNCMETH indirob '(' optexpr ')'    /* method $object (@args) */
                        { $$ = convert(OP_ENTERSUB, OPf_STACKED,
                                op_append_elem(OP_LIST,
                                    op_prepend_elem(OP_LIST, $2, $4),
@@ -742,11 +852,11 @@ listop    :       LSTOP indirob argexpr /* map {...} @args or print $fh @args */
                          TOKEN_GETMAD($3,$$,'(');
                          TOKEN_GETMAD($5,$$,')');
                        }
-       |       LSTOP listexpr                       /* print @args */
+       |       LSTOP optlistexpr                    /* print @args */
                        { $$ = convert(IVAL($1), 0, $2);
                          TOKEN_GETMAD($1,$$,'o');
                        }
-       |       FUNC '(' listexprcom ')'             /* print (@args) */
+       |       FUNC '(' optexpr ')'                 /* print (@args) */
                        { $$ = convert(IVAL($1), 0, $3);
                          TOKEN_GETMAD($1,$$,'o');
                          TOKEN_GETMAD($2,$$,'(');
@@ -755,7 +865,7 @@ listop      :       LSTOP indirob argexpr /* map {...} @args or print $fh @args */
        |       LSTOPSUB startanonsub block /* sub f(&@);   f { foo } ... */
                        { SvREFCNT_inc_simple_void(PL_compcv);
                          $<opval>$ = newANONATTRSUB($2, 0, (OP*)NULL, $3); }
-                   listexpr            %prec LSTOP  /* ... @bar */
+                   optlistexpr         %prec LSTOP  /* ... @bar */
                        { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
                                 op_append_elem(OP_LIST,
                                   op_prepend_elem(OP_LIST, $<opval>4, $5), $1));
@@ -768,7 +878,7 @@ method      :       METHOD
        ;
 
 /* Some kind of subscripted expression */
-subscripted:    star '{' expr ';' '}'        /* *main::{something} */
+subscripted:    gelem '{' expr ';' '}'        /* *main::{something} */
                         /* In this and all the hash accessors, ';' is
                          * provided by the tokeniser */
                        { $$ = newBINOP(OP_GELEM, 0, $1, scalar($3));
@@ -797,7 +907,7 @@ subscripted:    star '{' expr ';' '}'        /* *main::{something} */
                          TOKEN_GETMAD($2,$$,'[');
                          TOKEN_GETMAD($4,$$,']');
                        }
-       |       scalar '{' expr ';' '}'    /* $foo->{bar();} */
+       |       scalar '{' expr ';' '}'    /* $foo{bar();} */
                        { $$ = newBINOP(OP_HELEM, 0, oopsHV($1), jmaybe($3));
                            PL_parser->expect = XOPERATOR;
                          TOKEN_GETMAD($2,$$,'{');
@@ -839,14 +949,14 @@ subscripted:    star '{' expr ';' '}'        /* *main::{something} */
                          TOKEN_GETMAD($5,$$,')');
                        }
 
-       |       subscripted lpar_or_qw expr ')'   /* $foo->{bar}->(@args) */
+       |       subscripted '(' expr ')'   /* $foo->{bar}->(@args) */
                        { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
                                   op_append_elem(OP_LIST, $3,
                                               newCVREF(0, scalar($1))));
                          TOKEN_GETMAD($2,$$,'(');
                          TOKEN_GETMAD($4,$$,')');
                        }
-       |       subscripted lpar_or_qw ')'        /* $foo->{bar}->() */
+       |       subscripted '(' ')'        /* $foo->{bar}->() */
                        { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
                                   newCVREF(0, scalar($1)));
                          TOKEN_GETMAD($2,$$,'(');
@@ -922,7 +1032,7 @@ termbinop: term ASSIGNOP term                     /* $x = $y */
                              op = (UNOP*)op->op_first; /* get to flip */
                              op = (UNOP*)op->op_first; /* get to range */
                              token_getmad($2,(OP*)op,'o');
-                           })
+                           });
                        }
        |       term ANDAND term                       /* $x && $y */
                        { $$ = newLOGOP(OP_AND, 0, $1, $3);
@@ -967,22 +1077,34 @@ termunop : '-' term %prec UMINUS                       /* -$x */
                        }
        |       term POSTINC                           /* $x++ */
                        { $$ = newUNOP(OP_POSTINC, 0,
-                                       mod(scalar($1), OP_POSTINC));
+                                       op_lvalue(scalar($1), OP_POSTINC));
                          TOKEN_GETMAD($2,$$,'o');
                        }
        |       term POSTDEC                           /* $x-- */
                        { $$ = newUNOP(OP_POSTDEC, 0,
-                                       mod(scalar($1), OP_POSTDEC));
+                                       op_lvalue(scalar($1), OP_POSTDEC));
+                         TOKEN_GETMAD($2,$$,'o');
+                       }
+       |       term POSTJOIN    /* implicit join after interpolated ->@ */
+                       { $$ = convert(OP_JOIN, 0,
+                                      op_append_elem(
+                                       OP_LIST,
+                                       newSVREF(scalar(
+                                           newSVOP(OP_CONST,0,
+                                                   newSVpvs("\""))
+                                       )),
+                                       $1
+                                      ));
                          TOKEN_GETMAD($2,$$,'o');
                        }
        |       PREINC term                            /* ++$x */
                        { $$ = newUNOP(OP_PREINC, 0,
-                                       mod(scalar($2), OP_PREINC));
+                                       op_lvalue(scalar($2), OP_PREINC));
                          TOKEN_GETMAD($1,$$,'o');
                        }
        |       PREDEC term                            /* --$x */
                        { $$ = newUNOP(OP_PREDEC, 0,
-                                       mod(scalar($2), OP_PREDEC));
+                                       op_lvalue(scalar($2), OP_PREDEC));
                          TOKEN_GETMAD($1,$$,'o');
                        }
 
@@ -1011,7 +1133,7 @@ anonymous:        '[' expr ']'
                          TOKEN_GETMAD($2,$$,';');
                          TOKEN_GETMAD($3,$$,'}');
                        }
-       |       ANONSUB startanonsub proto subattrlist block    %prec '('
+       |       ANONSUB startanonsub proto subattrlist realsubbody      %prec '('
                        { SvREFCNT_inc_simple_void(PL_compcv);
                          $$ = newANONATTRSUB($2, $3, $4, $5);
                          TOKEN_GETMAD($1,$$,'o');
@@ -1027,52 +1149,9 @@ termdo   :       DO term %prec UNIOP                     /* do $filename */
                          TOKEN_GETMAD($1,$$,'o');
                        }
        |       DO block        %prec '('               /* do { code */
-                       { $$ = newUNOP(OP_NULL, OPf_SPECIAL, scope($2));
+                       { $$ = newUNOP(OP_NULL, OPf_SPECIAL, op_scope($2));
                          TOKEN_GETMAD($1,$$,'D');
                        }
-       |       DO WORD lpar_or_qw ')'                  /* do somesub() */
-                       { $$ = newUNOP(OP_ENTERSUB,
-                           OPf_SPECIAL|OPf_STACKED,
-                           op_prepend_elem(OP_LIST,
-                               scalar(newCVREF(
-                                   (OPpENTERSUB_AMPER<<8),
-                                   scalar($2)
-                               )),(OP*)NULL)); dep();
-                         TOKEN_GETMAD($1,$$,'o');
-                         TOKEN_GETMAD($3,$$,'(');
-                         TOKEN_GETMAD($4,$$,')');
-                       }
-       |       DO WORD lpar_or_qw expr ')'             /* do somesub(@args) */
-                       { $$ = newUNOP(OP_ENTERSUB,
-                           OPf_SPECIAL|OPf_STACKED,
-                           op_append_elem(OP_LIST,
-                               $4,
-                               scalar(newCVREF(
-                                   (OPpENTERSUB_AMPER<<8),
-                                   scalar($2)
-                               )))); dep();
-                         TOKEN_GETMAD($1,$$,'o');
-                         TOKEN_GETMAD($3,$$,'(');
-                         TOKEN_GETMAD($5,$$,')');
-                       }
-       |       DO scalar lpar_or_qw ')'                /* do $subref () */
-                       { $$ = newUNOP(OP_ENTERSUB, OPf_SPECIAL|OPf_STACKED,
-                           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 lpar_or_qw expr ')'           /* do $subref (@args) */
-                       { $$ = newUNOP(OP_ENTERSUB, OPf_SPECIAL|OPf_STACKED,
-                           op_prepend_elem(OP_LIST,
-                               $4,
-                               scalar(newCVREF(0,scalar($2))))); dep();
-                         TOKEN_GETMAD($1,$$,'o');
-                         TOKEN_GETMAD($3,$$,'(');
-                         TOKEN_GETMAD($5,$$,')');
-                       }
-
         ;
 
 term   :       termbinop
@@ -1085,7 +1164,7 @@ term      :       termbinop
                          TOKEN_GETMAD($4,$$,':');
                        }
        |       REFGEN term                          /* \$x, \@y, \%z */
-                       { $$ = newUNOP(OP_REFGEN, 0, mod($2,OP_REFGEN));
+                       { $$ = newUNOP(OP_REFGEN, 0, op_lvalue($2,OP_REFGEN));
                          TOKEN_GETMAD($1,$$,'o');
                        }
        |       myattrterm      %prec UNIOP
@@ -1118,21 +1197,53 @@ term    :       termbinop
                        { $$ = newUNOP(OP_AV2ARYLEN, 0, ref($1, OP_AV2ARYLEN));}
        |       subscripted
                        { $$ = $1; }
-       |       ary '[' expr ']'                     /* array slice */
+       |       sliceme '[' expr ']'                     /* array slice */
                        { $$ = op_prepend_elem(OP_ASLICE,
                                newOP(OP_PUSHMARK, 0),
                                    newLISTOP(OP_ASLICE, 0,
                                        list($3),
                                        ref($1, OP_ASLICE)));
+                         if ($$ && $1)
+                             $$->op_private |=
+                                 $1->op_private & OPpSLICEWARNING;
                          TOKEN_GETMAD($2,$$,'[');
                          TOKEN_GETMAD($4,$$,']');
                        }
-       |       ary '{' expr ';' '}'                 /* @hash{@keys} */
+       |       kvslice '[' expr ']'                 /* array key/value slice */
+                       { $$ = op_prepend_elem(OP_KVASLICE,
+                               newOP(OP_PUSHMARK, 0),
+                                   newLISTOP(OP_KVASLICE, 0,
+                                       list($3),
+                                       ref(oopsAV($1), OP_KVASLICE)));
+                         if ($$ && $1)
+                             $$->op_private |=
+                                 $1->op_private & OPpSLICEWARNING;
+                         TOKEN_GETMAD($2,$$,'[');
+                         TOKEN_GETMAD($4,$$,']');
+                       }
+       |       sliceme '{' expr ';' '}'                 /* @hash{@keys} */
                        { $$ = op_prepend_elem(OP_HSLICE,
                                newOP(OP_PUSHMARK, 0),
                                    newLISTOP(OP_HSLICE, 0,
                                        list($3),
                                        ref(oopsHV($1), OP_HSLICE)));
+                         if ($$ && $1)
+                             $$->op_private |=
+                                 $1->op_private & OPpSLICEWARNING;
+                           PL_parser->expect = XOPERATOR;
+                         TOKEN_GETMAD($2,$$,'{');
+                         TOKEN_GETMAD($4,$$,';');
+                         TOKEN_GETMAD($5,$$,'}');
+                       }
+       |       kvslice '{' expr ';' '}'                 /* %hash{@keys} */
+                       { $$ = op_prepend_elem(OP_KVHSLICE,
+                               newOP(OP_PUSHMARK, 0),
+                                   newLISTOP(OP_KVHSLICE, 0,
+                                       list($3),
+                                       ref($1, OP_KVHSLICE)));
+                         if ($$ && $1)
+                             $$->op_private |=
+                                 $1->op_private & OPpSLICEWARNING;
                            PL_parser->expect = XOPERATOR;
                          TOKEN_GETMAD($2,$$,'{');
                          TOKEN_GETMAD($4,$$,';');
@@ -1142,12 +1253,12 @@ term    :       termbinop
                        { $$ = $1; }
        |       amper                                /* &foo; */
                        { $$ = newUNOP(OP_ENTERSUB, 0, scalar($1)); }
-       |       amper lpar_or_qw ')'                 /* &foo() */
+       |       amper '(' ')'                 /* &foo() or foo() */
                        { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1));
                          TOKEN_GETMAD($2,$$,'(');
                          TOKEN_GETMAD($3,$$,')');
                        }
-       |       amper lpar_or_qw expr ')'            /* &foo(@args) */
+       |       amper '(' expr ')'          /* &foo(@args) or foo(@args) */
                        {
                          $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
                                op_append_elem(OP_LIST, $3, scalar($1)));
@@ -1158,13 +1269,34 @@ term    :       termbinop
                              }
                              token_getmad($2,op,'(');
                              token_getmad($4,op,')');
-                         })
+                         });
                        }
-       |       NOAMP WORD listexpr                  /* foo(@args) */
+       |       NOAMP subname optlistexpr       /* foo @args (no parens) */
                        { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
                            op_append_elem(OP_LIST, $3, scalar($2)));
                          TOKEN_GETMAD($1,$$,'o');
                        }
+       |       term ARROW '$' '*'
+                       { $$ = newSVREF($1);
+                         TOKEN_GETMAD($3,$$,'$');
+                       }
+       |       term ARROW '@' '*'
+                       { $$ = newAVREF($1);
+                         TOKEN_GETMAD($3,$$,'@');
+                       }
+       |       term ARROW '%' '*'
+                       { $$ = newHVREF($1);
+                         TOKEN_GETMAD($3,$$,'%');
+                       }
+       |       term ARROW '&' '*'
+                       { $$ = newUNOP(OP_ENTERSUB, 0,
+                                      scalar(newCVREF(IVAL($3),$1)));
+                         TOKEN_GETMAD($3,$$,'&');
+                       }
+       |       term ARROW '*' '*'      %prec '('
+                       { $$ = newGVREF(0,$1);
+                         TOKEN_GETMAD($3,$$,'*');
+                       }
        |       LOOPEX  /* loop exiting command (goto, last, dump, etc) */
                        { $$ = newOP(IVAL($1), OPf_SPECIAL);
                            PL_hints |= HINT_BLOCK_SCOPE;
@@ -1174,7 +1306,7 @@ term      :       termbinop
                        { $$ = newLOOPEX(IVAL($1),$2);
                          TOKEN_GETMAD($1,$$,'o');
                        }
-       |       NOTOP argexpr                        /* not $foo */
+       |       NOTOP listexpr                       /* not $foo */
                        { $$ = newUNOP(OP_NOT, 0, scalar($2));
                          TOKEN_GETMAD($1,$$,'o');
                        }
@@ -1213,6 +1345,13 @@ term     :       termbinop
                          TOKEN_GETMAD($2,$$,'(');
                          TOKEN_GETMAD($3,$$,')');
                        }
+       |       FUNC0OP       /* Same as above, but op created in toke.c */
+                       { $$ = $1; }
+       |       FUNC0OP '(' ')'
+                       { $$ = $1;
+                         TOKEN_GETMAD($2,$$,'(');
+                         TOKEN_GETMAD($3,$$,')');
+                       }
        |       FUNC0SUB                             /* Sub treated as nullop */
                        { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
                                scalar($1)); }
@@ -1231,10 +1370,21 @@ term    :       termbinop
                          TOKEN_GETMAD($2,$$,'(');
                          TOKEN_GETMAD($4,$$,')');
                        }
-       |       PMFUNC '(' argexpr ')'          /* m//, s///, tr/// */
-                       { $$ = pmruntime($1, $3, 1);
-                         TOKEN_GETMAD($2,$$,'(');
-                         TOKEN_GETMAD($4,$$,')');
+       |       PMFUNC /* m//, s///, qr//, tr/// */
+                       {
+                           if (   $1->op_type != OP_TRANS
+                               && $1->op_type != OP_TRANSR
+                               && (((PMOP*)$1)->op_pmflags & PMf_HAS_CV))
+                           {
+                               $<ival>$ = start_subparse(FALSE, CVf_ANON);
+                               SAVEFREESV(PL_compcv);
+                           } else
+                               $<ival>$ = 0;
+                       }
+                   '(' listexpr ')'
+                       { $$ = pmruntime($1, $4, 1, $<ival>2);
+                         TOKEN_GETMAD($3,$$,'(');
+                         TOKEN_GETMAD($5,$$,')');
                        }
        |       WORD
        |       listop
@@ -1254,7 +1404,7 @@ myattrterm:       MY myterm myattrlist
                              token_getmad($1,$$,'d');
                              append_madprops($3->op_madprop, $$, 'a');
                              $3->op_madprop = 0;
-                         )
+                         );
                        }
        |       MY myterm
                        { $$ = localize($2,IVAL($1));
@@ -1282,26 +1432,18 @@ myterm  :       '(' expr ')'
        ;
 
 /* Basic list expressions */
-listexpr:      /* NULL */ %prec PREC_LOW
+optlistexpr:   /* NULL */ %prec PREC_LOW
                        { $$ = (OP*)NULL; }
-       |       argexpr    %prec PREC_LOW
+       |       listexpr    %prec PREC_LOW
                        { $$ = $1; }
        ;
 
-listexprcom:   /* NULL */
+optexpr:       /* NULL */
                        { $$ = (OP*)NULL; }
        |       expr
                        { $$ = $1; }
        ;
 
-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
    lexical */
 my_scalar:     scalar
@@ -1322,12 +1464,14 @@ scalar  :       '$' indirob
 
 ary    :       '@' indirob
                        { $$ = newAVREF($2);
+                         if ($$) $$->op_private |= IVAL($1);
                          TOKEN_GETMAD($1,$$,'@');
                        }
        ;
 
 hsh    :       '%' indirob
                        { $$ = newHVREF($2);
+                         if ($$) $$->op_private |= IVAL($1);
                          TOKEN_GETMAD($1,$$,'%');
                        }
        ;
@@ -1336,6 +1480,10 @@ arylen   :       DOLSHARP indirob
                        { $$ = newAVREF($2);
                          TOKEN_GETMAD($1,$$,'l');
                        }
+       |       term ARROW DOLSHARP '*'
+                       { $$ = newAVREF($1);
+                         TOKEN_GETMAD($3,$$,'l');
+                       }
        ;
 
 star   :       '*' indirob
@@ -1344,13 +1492,34 @@ star    :       '*' indirob
                        }
        ;
 
+sliceme        :       ary
+       |       term ARROW '@'
+                       { $$ = newAVREF($1);
+                         TOKEN_GETMAD($3,$$,'@');
+                       }
+       ;
+
+kvslice        :       hsh
+       |       term ARROW '%'
+                       { $$ = newHVREF($1);
+                         TOKEN_GETMAD($3,$$,'@');
+                       }
+       ;
+
+gelem  :       star
+       |       term ARROW '*'
+                       { $$ = newGVREF(0,$1);
+                         TOKEN_GETMAD($3,$$,'*');
+                       }
+       ;
+
 /* Indirect objects */
 indirob        :       WORD
                        { $$ = scalar($1); }
        |       scalar %prec PREC_LOW
                        { $$ = scalar($1); }
        |       block
-                       { $$ = scope($1); }
+                       { $$ = op_scope($1); }
 
        |       PRIVATEREF
                        { $$ = $1; }