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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.