diff options
author | Stephen McCamant <smcc@mit.edu> | 1999-07-23 10:55:22 -0500 |
---|---|---|
committer | Gurusamy Sarathy <gsar@cpan.org> | 1999-07-26 10:44:11 +0000 |
commit | fad39ff13c300fe483c6155ea2883280e12fc89c (patch) | |
tree | 5ced2802fa81825ad5bc148be165aa3a8e20a7ac /perly.y | |
parent | 43192e07925c626b8d615aff545160df8bd7c3f8 (diff) | |
download | perl-fad39ff13c300fe483c6155ea2883280e12fc89c.tar.gz |
allow arrow omission in $foo[10]->('foo') etc. (but not in
foo()->()); rework grammar to remove conflicts
Message-ID: <14232.54970.771570.548676@alias-2.pr.mcs.net>
Subject: [PATCH _57, long] Re: optional arrow asymmetry
p4raw-id: //depot/perl@3767
Diffstat (limited to 'perly.y')
-rw-r--r-- | perly.y | 108 |
1 files changed, 63 insertions, 45 deletions
@@ -43,7 +43,7 @@ #endif %} -%token <ival> '{' ')' +%token <ival> '{' %token <opval> WORD METHOD FUNCMETH THING PMFUNC PRIVATEREF %token <opval> FUNC0SUB UNIOPSUB LSTOPSUB @@ -59,12 +59,15 @@ %type <ival> prog decl local format startsub startanonsub startformsub %type <ival> remember mremember '&' %type <opval> block mblock lineseq line loop cond else -%type <opval> expr term scalar ary hsh arylen star amper sideff +%type <opval> expr term subscripted scalar ary hsh arylen star amper sideff %type <opval> argexpr nexpr texpr iexpr mexpr mnexpr mtexpr miexpr %type <opval> listexpr listexprcom indirob listop method %type <opval> formname subname proto subbody cont my_scalar %type <pval> label +%nonassoc PREC_LOW +%nonassoc LOOPEX + %left <ival> OROP %left ANDOP %right NOTOP @@ -88,7 +91,9 @@ %right <ival> POWOP %nonassoc PREINC PREDEC POSTINC POSTDEC %left ARROW +%nonassoc <ival> ')' %left '(' +%left '[' '{' %% /* RULES */ @@ -332,14 +337,14 @@ expr : expr ANDOP expr { $$ = newLOGOP(OP_AND, 0, $1, $3); } | expr OROP expr { $$ = newLOGOP($2, 0, $1, $3); } - | argexpr + | argexpr %prec PREC_LOW ; argexpr : argexpr ',' { $$ = $1; } | argexpr ',' term { $$ = append_elem(OP_LIST, $1, $3); } - | term + | term %prec PREC_LOW ; listop : LSTOP indirob argexpr @@ -383,6 +388,49 @@ method : METHOD | scalar ; +subscripted: star '{' expr ';' '}' + { $$ = newBINOP(OP_GELEM, 0, $1, scalar($3)); } + | scalar '[' expr ']' + { $$ = newBINOP(OP_AELEM, 0, oopsAV($1), scalar($3)); } + | term ARROW '[' expr ']' + { $$ = newBINOP(OP_AELEM, 0, + ref(newAVREF($1),OP_RV2AV), + scalar($4));} + | subscripted '[' expr ']' + { $$ = newBINOP(OP_AELEM, 0, + ref(newAVREF($1),OP_RV2AV), + scalar($3));} + | scalar '{' expr ';' '}' + { $$ = newBINOP(OP_HELEM, 0, oopsHV($1), jmaybe($3)); + PL_expect = XOPERATOR; } + | term ARROW '{' expr ';' '}' + { $$ = newBINOP(OP_HELEM, 0, + ref(newHVREF($1),OP_RV2HV), + jmaybe($4)); + PL_expect = XOPERATOR; } + | subscripted '{' expr ';' '}' + { $$ = newBINOP(OP_HELEM, 0, + ref(newHVREF($1),OP_RV2HV), + jmaybe($3)); + PL_expect = XOPERATOR; } + | term ARROW '(' ')' + { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, + newCVREF(0, scalar($1))); } + | term ARROW '(' expr ')' + { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, + append_elem(OP_LIST, $4, + newCVREF(0, scalar($1)))); } + + | subscripted '(' expr ')' + { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, + append_elem(OP_LIST, $3, + newCVREF(0, scalar($1)))); } + | subscripted '(' ')' + { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, + newCVREF(0, scalar($1))); } + + + term : term ASSIGNOP term { $$ = newASSIGNOP(OPf_STACKED, $1, $2, $3); } | term POWOP term @@ -442,9 +490,9 @@ term : term ASSIGNOP term { $$ = sawparens($2); } | '(' ')' { $$ = sawparens(newNULLLIST()); } - | '[' expr ']' %prec '(' + | '[' expr ']' { $$ = newANONLIST($2); } - | '[' ']' %prec '(' + | '[' ']' { $$ = newANONLIST(Nullop); } | HASHBRACK expr ';' '}' %prec '(' { $$ = newANONHASH($2); } @@ -454,50 +502,27 @@ term : term ASSIGNOP term { $$ = newANONSUB($2, $3, $4); } | scalar %prec '(' { $$ = $1; } - | star '{' expr ';' '}' - { $$ = newBINOP(OP_GELEM, 0, $1, scalar($3)); } | star %prec '(' { $$ = $1; } - | scalar '[' expr ']' %prec '(' - { $$ = newBINOP(OP_AELEM, 0, oopsAV($1), scalar($3)); } - | term ARROW '[' expr ']' %prec '(' - { $$ = newBINOP(OP_AELEM, 0, - ref(newAVREF($1),OP_RV2AV), - scalar($4));} - | term '[' expr ']' %prec '(' - { assertref($1); $$ = newBINOP(OP_AELEM, 0, - ref(newAVREF($1),OP_RV2AV), - scalar($3));} | hsh %prec '(' { $$ = $1; } | ary %prec '(' { $$ = $1; } | arylen %prec '(' { $$ = newUNOP(OP_AV2ARYLEN, 0, ref($1, OP_AV2ARYLEN));} - | scalar '{' expr ';' '}' %prec '(' - { $$ = newBINOP(OP_HELEM, 0, oopsHV($1), jmaybe($3)); - PL_expect = XOPERATOR; } - | term ARROW '{' expr ';' '}' %prec '(' - { $$ = newBINOP(OP_HELEM, 0, - ref(newHVREF($1),OP_RV2HV), - jmaybe($4)); - PL_expect = XOPERATOR; } - | term '{' expr ';' '}' %prec '(' - { assertref($1); $$ = newBINOP(OP_HELEM, 0, - ref(newHVREF($1),OP_RV2HV), - jmaybe($3)); - PL_expect = XOPERATOR; } - | '(' expr ')' '[' expr ']' %prec '(' + | subscripted + { $$ = $1; } + | '(' expr ')' '[' expr ']' { $$ = newSLICEOP(0, $5, $2); } - | '(' ')' '[' expr ']' %prec '(' + | '(' ')' '[' expr ']' { $$ = newSLICEOP(0, $4, Nullop); } - | ary '[' expr ']' %prec '(' + | ary '[' expr ']' { $$ = prepend_elem(OP_ASLICE, newOP(OP_PUSHMARK, 0), newLISTOP(OP_ASLICE, 0, list($3), ref($1, OP_ASLICE))); } - | ary '{' expr ';' '}' %prec '(' + | ary '{' expr ';' '}' { $$ = prepend_elem(OP_HSLICE, newOP(OP_PUSHMARK, 0), newLISTOP(OP_HSLICE, 0, @@ -546,13 +571,6 @@ term : term ASSIGNOP term prepend_elem(OP_LIST, $4, scalar(newCVREF(0,scalar($2))))); dep();} - | term ARROW '(' ')' %prec '(' - { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, - newCVREF(0, scalar($1))); } - | term ARROW '(' expr ')' %prec '(' - { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, - append_elem(OP_LIST, $4, - newCVREF(0, scalar($1)))); } | LOOPEX { $$ = newOP($1, OPf_SPECIAL); PL_hints |= HINT_BLOCK_SCOPE; } @@ -588,9 +606,9 @@ term : term ASSIGNOP term | listop ; -listexpr: /* NULL */ +listexpr: /* NULL */ %prec PREC_LOW { $$ = Nullop; } - | argexpr + | argexpr %prec PREC_LOW { $$ = $1; } ; @@ -636,7 +654,7 @@ star : '*' indirob indirob : WORD { $$ = scalar($1); } - | scalar + | scalar %prec PREC_LOW { $$ = scalar($1); } | block { $$ = scope($1); } |