[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: |
Aharon Robbins |
Subject: |
Re: gawk's "for" does not allow simple-statements. |
Date: |
Mon, 7 Jan 2002 16:30:07 +0200 |
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
Hmm. This is a new one on me. The following experiment sheds interesting
light:
$ for i in nawk mawk gawk
> do $i 'BEGIN{for(print 9;0;);}'
> done
9
mawk: line 1: syntax error at or near print
mawk: line 1: extra ')'
gawk: cmd. line:1: BEGIN{for(print 9;0;);}
gawk: cmd. line:1: ^ parse error
gawk: cmd. line:1: BEGIN{for(print 9;0;);}
gawk: cmd. line:1: ^ parse error
This thus seems to be true "dark corner." The original grey awk book
indicates that the components of the for loop are expressions, and
not statements.
I'll look at fixing this, but messing w/the awk grammar is
always frought with peril.
Thanks,
Arnold