[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: gawk's "for" does not allow simple-statements.

From: Kenny McCormack
Subject: Re: gawk's "for" does not allow simple-statements.
Date: 12 Jan 2002 09:43:28 -0600

In article <address@hidden>,
Aharon Robbins <address@hidden> wrote:
>Greetings.  Re this:
>> To: address@hidden
>> From: David Jones <address@hidden>
>> Subject: gawk's "for" does not allow simple-statements.
>> Date: Mon, 07 Jan 2002 13:46:33 +0000
>> In a for statement:
>> for(x;;y)
>> x and y are both allowed to be simple_statement (in the single unix spec
>> Version 2, but also in the IEEE P1003.1, Draft 7, Issue 6).
>> That means the following ought to work (outputting "9\n").
>> ./gawk 'BEGIN{for(print 9;0;);}'
>> but it doesn't (I get parse error).
>> Cheers,
>>  drj
>> # versions etc
>> $ ./gawk --version
>> GNU Awk 3.1.0
>> $ uname -a
>> FreeBSD topcat.zoonami.com 4.3-RELEASE FreeBSD 4.3-RELEASE #0: Thu Nov  1 
>> 14:13:13 GMT 2001     address@hidden:/usr/src/sys/compile/GENERIC  i386
>Fortunately, this was fairly straightforward to fix.  Here is an unofficial 
>This patch will cause a few innocuous errors in the test suite that will
>be straightened out for gawk 3.1.1.

But are you sure this is the right thing to do?  I don't think that (G)AWK
should allow statements there (*), but I suppose the point is
that if the "standard" says it should, then it should.  BTW, are you sure
that the standard statement referred-to/quoted-by the OP is genuine/valid?

(*) In C, there really aren't any statements, per se.  There are only
control structures and expressions.  The definition of the C "for"
statement (er, I mean, the "for" control structure) says that the
things between the ;s are expressions (which, for practical purposes in C
ends up meaning the same thing as "statement").  Well, it seems to me that
AWK ought to be the same - that is, the definition of "for" ought to be
"expressions", and that if we want to extend the definition of "expression"
to be all-encompassing, as it is in C, then that would be fine.

I.e., if:

        for (print 9;;)

works, then so should:

        t = print 9

I am basing this, in part, on the fact that T-AWK doesn't allow statements
in the "for" statement, and that just seems to make intuitive sense to me.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]