/* 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.
%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
/* 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> 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
}
;
-/* 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(0, PVAL($1), $2);
+ TOKEN_GETMAD($1,
+ $2 ? cLISTOPx($$)->op_first : $$, 'L');
+ }
+ | LABEL labfullstmt
+ {
+ $$ = newSTATEOP(0, PVAL($1), $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
{ $$ = $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; }
;
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($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)); }