/* 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 GRAMBARESTMT GRAMFULLSTMT GRAMSTMTSEQ
+%token <ival> GRAMPROG GRAMEXPR GRAMBLOCK GRAMBARESTMT GRAMFULLSTMT GRAMSTMTSEQ
%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> LOCAL MY MYSUB REQUIRE
%token <i_tkval> COLONATTR
-%type <i_tkval> lpar_or_qw
-
%type <ival> grammar remember mremember
%type <ival> startsub startanonsub startformsub
/* FIXME for MAD - are these two ival? */
%type <ival> mydefsv 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> listexpr nexpr texpr iexpr mexpr mnexpr miexpr
+%type <opval> optlistexpr optexpr indirob listop method
%type <opval> formname subname proto subbody cont my_scalar
%type <opval> subattrlist myattrlist myattrterm myterm
%type <opval> termbinop termunop anonymous termdo
-%type <p_tkval> label
%nonassoc <i_tkval> PREC_LOW
%nonassoc LOOPEX
newPROG(block_end($3,$4));
$$ = 0;
}
+ | GRAMEXPR
+ {
+ parser->expect = XTERM;
+ }
+ optexpr
+ {
+ PL_eval_root = $3;
+ $$ = 0;
+ }
| GRAMBLOCK
{
parser->expect = XBLOCK;
}
;
-/* A statement in the program, including optional label */
-fullstmt: label barestmt
+/* 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(SvUTF8(((SVOP*)$1)->op_sv),
+ savepv(SvPVX(((SVOP*)$1)->op_sv)), $2);
+ TOKEN_GETMAD($1,
+ $2 ? cLISTOPx($$)->op_first : $$, 'L');
+ }
+ | LABEL labfullstmt
+ {
+ $$ = newSTATEOP(SvUTF8(((SVOP*)$1)->op_sv),
+ savepv(SvPVX(((SVOP*)$1)->op_sv)), $2);
+ TOKEN_GETMAD($1, cLISTOPx($$)->op_first, 'L');
+ }
;
/* A bare statement, lacking label and other aspects of state op */
#endif
if (CvOUTSIDE(fmtcv) && !CvUNIQUE(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
}
| USE startsub
{ CvSPECIAL_on(PL_compcv); /* It's a BEGIN {} */ }
- WORD WORD listexpr ';'
+ WORD WORD optlistexpr ';'
{
SvREFCNT_inc_simple_void(PL_compcv);
#ifdef MAD
$$ = (OP*)NULL;
#endif
}
- | IF lpar_or_qw remember mexpr ')' mblock else
+ | IF '(' remember mexpr ')' mblock else
{
$$ = block_end($3,
newCONDOP(0, $4, op_scope($6), $7));
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, op_scope($6), $7));
TOKEN_GETMAD($5,$$,')');
PL_parser->copline = (line_t)IVAL($1);
}
- | GIVEN lpar_or_qw remember mydefsv mexpr ')' mblock
+ | GIVEN '(' remember mydefsv mexpr ')' mblock
{
$$ = block_end($3,
newGIVENOP($5, op_scope($7), (PADOFFSET)$4));
PL_parser->copline = (line_t)IVAL($1);
}
- | WHEN lpar_or_qw remember mexpr ')' mblock
+ | WHEN '(' remember mexpr ')' mblock
{ $$ = block_end($3, newWHENOP($4, op_scope($6))); }
| DEFAULT block
{ $$ = newWHENOP(0, op_scope($2)); }
- | WHILE lpar_or_qw remember texpr ')' mintro mblock cont
+ | WHILE '(' remember texpr ')' mintro mblock cont
{
$$ = block_end($3,
newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
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,
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);
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');
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,
op_lvalue($2, OP_ENTERLOOP), $5, $7, $8));
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));
$$ = 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),
{ $$ = $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; }
;
{ $$ = 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();
$$ = $1;
#endif
}
- | argexpr ',' term
+ | listexpr ',' term
{
OP* term = $3;
DO_MAD(
;
/* 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');
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),
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),
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,$$,'(');
| 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));
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,$$,'{');
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,$$,'(');
{ $$ = newUNOP(OP_NULL, OPf_SPECIAL, op_scope($2));
TOKEN_GETMAD($1,$$,'D');
}
- | DO WORD lpar_or_qw ')' /* do somesub() */
+ | DO WORD '(' ')' /* do somesub() */
{ $$ = newUNOP(OP_ENTERSUB,
OPf_SPECIAL|OPf_STACKED,
op_prepend_elem(OP_LIST,
TOKEN_GETMAD($3,$$,'(');
TOKEN_GETMAD($4,$$,')');
}
- | DO WORD lpar_or_qw expr ')' /* do somesub(@args) */
+ | DO WORD '(' expr ')' /* do somesub(@args) */
{ $$ = newUNOP(OP_ENTERSUB,
OPf_SPECIAL|OPf_STACKED,
op_append_elem(OP_LIST,
TOKEN_GETMAD($3,$$,'(');
TOKEN_GETMAD($5,$$,')');
}
- | DO scalar lpar_or_qw ')' /* do $subref () */
+ | DO scalar '(' ')' /* do $subref () */
{ $$ = newUNOP(OP_ENTERSUB, OPf_SPECIAL|OPf_STACKED,
op_prepend_elem(OP_LIST,
scalar(newCVREF(0,scalar($2))), (OP*)NULL)); dep();
TOKEN_GETMAD($3,$$,'(');
TOKEN_GETMAD($4,$$,')');
}
- | DO scalar lpar_or_qw expr ')' /* do $subref (@args) */
+ | DO scalar '(' expr ')' /* do $subref (@args) */
{ $$ = newUNOP(OP_ENTERSUB, OPf_SPECIAL|OPf_STACKED,
op_prepend_elem(OP_LIST,
$4,
{ $$ = $1; }
| amper /* &foo; */
{ $$ = newUNOP(OP_ENTERSUB, 0, scalar($1)); }
- | amper lpar_or_qw ')' /* &foo() */
+ | amper '(' ')' /* &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) */
{
$$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
op_append_elem(OP_LIST, $3, scalar($1)));
token_getmad($4,op,')');
})
}
- | NOAMP WORD listexpr /* foo(@args) */
+ | NOAMP WORD optlistexpr /* foo(@args) */
{ $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
op_append_elem(OP_LIST, $3, scalar($2)));
TOKEN_GETMAD($1,$$,'o');
{ $$ = 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');
}
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)); }
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
;
/* 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