summaryrefslogtreecommitdiff
path: root/perly.y
diff options
context:
space:
mode:
authorPerl 5 Porters <perl5-porters@africa.nicoh.com>1996-11-19 14:16:00 +1200
committerChip Salzenberg <chip@atlantic.net>1996-11-19 14:16:00 +1200
commit55497cffdd24c959994f9a8ddd56db8ce85e1c5b (patch)
tree444dfb8adc0e5b96d56e0532791122c366f50a3e /perly.y
parentc822f08a5087943f7d9e2c36ce42ea035f03ab97 (diff)
downloadperl-55497cffdd24c959994f9a8ddd56db8ce85e1c5b.tar.gz
[inseparable changes from patch from perl5.003_07 to perl5.003_08]
CORE LANGUAGE CHANGES Subject: Bitwise op sign rationalization From: Chip Salzenberg <chip@atlantic.net> Files: op.c opcode.pl pod/perlop.pod pod/perltoc.pod pp.c pp.h pp_hot.c proto.h sv.c t/op/bop.t Make bitwise ops result in unsigned values, unless C<use integer> is in effect. Includes initial support for UVs. Subject: Defined scoping for C<my> in control structures From: Chip Salzenberg <chip@atlantic.net> Files: op.c perly.c perly.c.diff perly.h perly.y proto.h toke.c Finally defines semantics of "my" in control expressions, like the condition of "if" and "while". In all cases, scope of a "my" var extends to the end of the entire control structure. Also adds new construct "for my", which automatically declares the control variable "my" and limits its scope to the loop. Subject: Fix ++/-- after int conversion (e.g. 'printf "%d"') From: Chip Salzenberg <chip@atlantic.net> Files: pp.c pp_hot.c sv.c This patch makes Perl correctly ignore SvIVX() if either NOK or POK is true, since SvIVX() may be a truncated or overflowed version of the real value. Subject: Make code match Camel II re: functions that use $_ From: Paul Marquess <pmarquess@bfsec.bt.co.uk> Files: opcode.pl Subject: Provide scalar context on left side of "->" From: Chip Salzenberg <chip@atlantic.net> Files: perly.c perly.y Subject: Quote bearword package/handle FOO in "funcname FOO => 'bar'" From: Chip Salzenberg <chip@atlantic.net> Files: toke.c OTHER CORE CHANGES Subject: Warn on overflow of octal and hex integers From: Chip Salzenberg <chip@atlantic.net> Files: proto.h toke.c util.c Subject: If -w active, warn for commas and hashes ('#') in qw() From: Chip Salzenberg <chip@atlantic.net> Files: toke.c Subject: Fixes for pack('w') From: Ulrich Pfeifer <pfeifer@charly.informatik.uni-dortmund.de> Files: pp.c t/op/pack.t Subject: More complete output from sv_dump() From: Gurusamy Sarathy <gsar@engin.umich.edu> Files: sv.c Subject: Major '..' and debugger patches From: Ilya Zakharevich <ilya@math.ohio-state.edu> Files: lib/perl5db.pl op.c pp_ctl.c scope.c scope.h Subject: Fix for formline() From: Gurusamy Sarathy <gsar@engin.umich.edu> Files: global.sym mg.c perl.h pod/perldiag.pod pp_ctl.c proto.h sv.c t/op/write.t Subject: Fix stack botch in untie and binmode From: Gurusamy Sarathy <gsar@engin.umich.edu> Files: pp_sys.c Subject: Complete EMBED, including symbols from interp.sym From: Chip Salzenberg <chip@atlantic.net> Files: MANIFEST embed.pl ext/DynaLoader/dlutils.c ext/SDBM_File/sdbm/sdbm.h global.sym handy.h malloc.c perl.h pp_sys.c proto.h regexec.c toke.c util.c x2p/Makefile.SH x2p/a2p.h x2p/handy.h x2p/util.h New define EMBEDMYMALLOC makes embedding total by avoiding "Mymalloc" etc. Subject: Support old embedding for people who want it From: Chip Salzenberg <chip@atlantic.net> Files: MANIFEST Makefile.SH old_embed.pl old_global.sym PORTABILITY Subject: Miscellaneous VMS fixes From: Charles Bailey <bailey@HMIVAX.HUMGEN.UPENN.EDU> Files: lib/ExtUtils/Liblist.pm lib/ExtUtils/MM_VMS.pm lib/Math/Complex.pm lib/Time/Local.pm lib/timelocal.pl perl.h perl_exp.SH proto.h t/TEST t/io/read.t t/lib/findbin.t t/lib/getopt.t util.c utils/h2xs.PL vms/Makefile vms/config.vms vms/descrip.mms vms/ext/Stdio/Stdio.pm vms/ext/Stdio/Stdio.xs vms/perlvms.pod vms/test.com vms/vms.c Subject: DJGPP patches (MS-DOS) From: "Douglas E. Wegscheid" <wegscd@whirlpool.com> Files: doio.c dosish.h ext/SDBM_File/sdbm/sdbm.c handy.h lib/AutoSplit.pm lib/Cwd.pm lib/File/Find.pm malloc.c perl.c perl.h pp_sys.c proto.h sv.c util.c Subject: Patch to make Perl work under AmigaOS From: "Norbert Pueschel" <pueschel@imsdd.meb.uni-bonn.de> Files: MANIFEST hints/amigaos.sh installman lib/File/Basename.pm lib/File/Find.pm pod/pod2man.PL pp_sys.c util.c
Diffstat (limited to 'perly.y')
-rw-r--r--perly.y134
1 files changed, 97 insertions, 37 deletions
diff --git a/perly.y b/perly.y
index 57c9630f0b..4feb549be5 100644
--- a/perly.y
+++ b/perly.y
@@ -43,15 +43,16 @@ dep()
%token <ival> LOOPEX DOTDOT
%token <ival> FUNC0 FUNC1 FUNC
%token <ival> RELOP EQOP MULOP ADDOP
-%token <ival> DOLSHARP DO LOCAL HASHBRACK NOAMP
+%token <ival> DOLSHARP DO HASHBRACK NOAMP
+%token LOCAL MY
-%type <ival> prog decl format remember startsub '&'
-%type <opval> block lineseq line loop cond nexpr else argexpr
+%type <ival> prog decl local format startsub remember mremember '&'
+%type <opval> block mblock mintro lineseq line loop cond else
%type <opval> expr term scalar ary hsh arylen star amper sideff
+%type <opval> argexpr nexpr texpr iexpr mexpr mtexpr miexpr
%type <opval> listexpr listexprcom indirob
-%type <opval> texpr listop method proto
+%type <opval> listop method proto cont my_scalar
%type <pval> label
-%type <opval> cont
%left <ival> OROP
%left ANDOP
@@ -95,8 +96,25 @@ block : '{' remember lineseq '}'
{ $$ = block_end($1,$2,$3); }
;
-remember: /* NULL */ /* start a lexical scope */
- { $$ = block_start(); }
+remember: /* NULL */ /* start a full lexical scope */
+ { $$ = block_start(TRUE); }
+ ;
+
+mblock : '{' mintro mremember lineseq '}'
+ { if ($2)
+ $4 = $4 ? append_list(OP_LINESEQ,
+ (LISTOP*)$2, (LISTOP*)$4) : $2;
+ $$ = block_end($1, $3, $4); }
+ ;
+
+mintro : /* NULL */ /* introduce pending lexicals */
+ { $$ = min_intro_pending
+ ? newSTATEOP(0, Nullch, newOP(OP_NULL, 0))
+ : NULL; }
+ ;
+
+mremember: /* NULL */ /* start a partial lexical scope */
+ { $$ = block_start(FALSE); }
;
lineseq : /* NULL */
@@ -137,28 +155,28 @@ sideff : error
{ $$ = newLOGOP(OP_OR, 0, $3, $1); }
| expr WHILE expr
{ $$ = newLOOPOP(OPf_PARENS, 1, scalar($3), $1); }
- | expr UNTIL expr
- { $$ = newLOOPOP(OPf_PARENS, 1, invert(scalar($3)), $1);}
+ | expr UNTIL iexpr
+ { $$ = newLOOPOP(OPf_PARENS, 1, $3, $1);}
;
else : /* NULL */
{ $$ = Nullop; }
- | ELSE block
+ | ELSE mblock
{ $$ = scope($2); }
- | ELSIF '(' expr ')' block else
+ | ELSIF '(' mexpr ')' mblock else
{ copline = $1;
- $$ = newSTATEOP(0, 0,
- newCONDOP(0, $3, scope($5), $6));
+ $$ = newCONDOP(0, $3, scope($5), $6);
hints |= HINT_BLOCK_SCOPE; }
;
-cond : IF '(' expr ')' block else
+cond : IF '(' remember mexpr ')' mblock else
{ copline = $1;
- $$ = newCONDOP(0, $3, scope($5), $6); }
- | UNLESS '(' expr ')' block else
+ $$ = block_end($1, $3,
+ newCONDOP(0, $4, scope($6), $7)); }
+ | UNLESS '(' remember miexpr ')' mblock else
{ copline = $1;
- $$ = newCONDOP(0,
- invert(scalar($3)), scope($5), $6); }
+ $$ = block_end($1, $3,
+ newCONDOP(0, $4, scope($6), $7)); }
| IF block block else
{ copline = $1;
deprecate("if BLOCK BLOCK");
@@ -176,16 +194,18 @@ cont : /* NULL */
{ $$ = scope($2); }
;
-loop : label WHILE '(' texpr ')' block cont
+loop : label WHILE '(' remember mtexpr ')' mblock cont
{ copline = $2;
- $$ = newSTATEOP(0, $1,
- newWHILEOP(0, 1, (LOOP*)Nullop,
- $4, $6, $7) ); }
- | label UNTIL '(' expr ')' block cont
+ $$ = block_end($2, $4,
+ newSTATEOP(0, $1,
+ newWHILEOP(0, 1, (LOOP*)Nullop,
+ $5, $7, $8) )); }
+ | label UNTIL '(' remember miexpr ')' mblock cont
{ copline = $2;
- $$ = newSTATEOP(0, $1,
- newWHILEOP(0, 1, (LOOP*)Nullop,
- invert(scalar($4)), $6, $7) ); }
+ $$ = block_end($2, $4,
+ newSTATEOP(0, $1,
+ newWHILEOP(0, 1, (LOOP*)Nullop,
+ $5, $7, $8) )); }
| label WHILE block block cont
{ copline = $2;
$$ = newSTATEOP(0, $1,
@@ -196,19 +216,32 @@ loop : label WHILE '(' texpr ')' block cont
$$ = newSTATEOP(0, $1,
newWHILEOP(0, 1, (LOOP*)Nullop,
invert(scalar(scope($3))), $4, $5)); }
+ | label FOR MY remember my_scalar '(' expr ')' mblock cont
+ { $$ = block_end($2, $4,
+ newFOROP(0, $1, $2, $5, $7, $9, $10)); }
| label FOR scalar '(' expr ')' block cont
{ $$ = newFOROP(0, $1, $2, mod($3, OP_ENTERLOOP),
$5, $7, $8); }
- | label FOR '(' expr ')' block cont
- { $$ = newFOROP(0, $1, $2, Nullop, $4, $6, $7); }
- | label FOR '(' nexpr ';' texpr ';' nexpr ')' block
+ | label FOR '(' remember expr ')' mblock cont
+ { $$ = block_end($2, $4,
+ newFOROP(0, $1, $2, Nullop, $5, $7, $8)); }
+ | label FOR '(' remember nexpr ';'
+ { if ($5) {
+ $5 = scalar($5);
+ if (min_intro_pending)
+ $5 = newSTATEOP(0, Nullch, $5); } }
+ texpr ';'
+ { $8 = scalar($8);
+ if (min_intro_pending)
+ $8 = newSTATEOP(0, Nullch, $8); }
+ nexpr ')' mblock
/* basically fake up an initialize-while lineseq */
- { copline = $2;
- $$ = append_elem(OP_LINESEQ,
- newSTATEOP(0, $1, scalar($4)),
- newSTATEOP(0, $1,
- newWHILEOP(0, 1, (LOOP*)Nullop,
- scalar($6), $10, scalar($8)) )); }
+ { copline = $2;
+ $$ = block_end($2, $4,
+ append_elem(OP_LINESEQ, $5,
+ newSTATEOP(0, $1,
+ newWHILEOP(0, 1, (LOOP*)Nullop,
+ $8, $13, scalar($11))))); }
| label block cont /* a block is a loop that happens once */
{ $$ = newSTATEOP(0,
$1, newWHILEOP(0, 1, (LOOP*)Nullop,
@@ -225,6 +258,25 @@ texpr : /* NULL means true */
| expr
;
+iexpr : expr
+ { $$ = invert(scalar($1)); }
+ ;
+
+mexpr : expr
+ { $$ = min_intro_pending
+ ? newSTATEOP(0, Nullch, $1) : $1; }
+ ;
+
+mtexpr : texpr
+ { $$ = min_intro_pending
+ ? newSTATEOP(0, Nullch, $1) : $1; }
+ ;
+
+miexpr : iexpr
+ { $$ = min_intro_pending
+ ? newSTATEOP(0, Nullch, $1) : $1; }
+ ;
+
label : /* empty */
{ $$ = Nullch; }
| LABEL
@@ -294,7 +346,7 @@ listop : LSTOP indirob argexpr
| term ARROW method '(' listexprcom ')'
{ $$ = convert(OP_ENTERSUB, OPf_STACKED,
append_elem(OP_LIST,
- prepend_elem(OP_LIST, $1, $5),
+ prepend_elem(OP_LIST, scalar($1), $5),
newUNOP(OP_METHOD, 0, $3))); }
| METHOD indirob listexpr
{ $$ = convert(OP_ENTERSUB, OPf_STACKED,
@@ -374,7 +426,7 @@ term : term ASSIGNOP term
| PREDEC term
{ $$ = newUNOP(OP_PREDEC, 0,
mod(scalar($2), OP_PREDEC)); }
- | LOCAL term %prec UNIOP
+ | local term %prec UNIOP
{ $$ = localize($2,$1); }
| '(' expr ')'
{ $$ = sawparens($2); }
@@ -533,6 +585,14 @@ listexprcom: /* NULL */
{ $$ = $1; }
;
+local : LOCAL { $$ = 0; }
+ | MY { $$ = 1; }
+ ;
+
+my_scalar: scalar
+ { in_my = 0; $$ = my($1); }
+ ;
+
amper : '&' indirob
{ $$ = newCVREF($1,$2); }
;