This isn't related to being able to transform for into while, and appears to be a deliberate choice. The parser injects a constant "1" if either while() or the middle part of for(;;) are empty:
perly.y:
/* Loops: while, until, for, and a bare block */
loop : label WHILE '(' remember texpr ')' mintro mblock cont
{ PL_copline = (line_t)$2;
$$ = block_end($4,
newSTATEOP(0, $1,
newWHILEOP(0, 1, (LOOP*)Nullop,
$2, $5, $8, $9, $7)));
+ }
...
| label FOR '(' remember mnexpr ';' texpr ';' mintro mne
+xpr ')'
mblock
/* basically fake up an initialize-while lines
+eq */
{ OP *forop;
PL_copline = (line_t)$2;
forop = newSTATEOP(0, $1,
newWHILEOP(0, 1, (LOOP*)Nu
+llop,
$2, scalar($7),
$12, $10, $9));
if ($5) {
forop = append_elem(OP_LINESEQ,
newSTATEOP(0, ($1?savepv($1):N
+ullch),
$5),
forop);
}
$$ = block_end($4, forop); }
...
/* Boolean expression */
texpr : /* NULL means true */
{ (void)scan_num("1", &yylval); $$ = yylval.op
+val; }
| expr
;
("remember" starts a lexical scope, but doesn't use any tokens.)
AIUI, while () would be illegal if it had said
loop : label WHILE '(' remember expr ')' mintro mblock cont
instead.
In reply to Re: while ()
by ysth
in thread while ()
by blazar
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.