bug-gnu-utils
[Top][All Lists]
Advanced

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

Re: Unexpected result while constructing strings


From: Hermann Peifer
Subject: Re: Unexpected result while constructing strings
Date: Sat, 30 Oct 2010 16:38:50 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.12) Gecko/20101027 Thunderbird/3.1.6

On 30/10/2010 16:05, Davide Brini wrote:
On Sat, 30 Oct 2010 16:00:20 +0200 Hermann Peifer<address@hidden>  wrote:

I think I got it now: `FS ++c' is not (mis)interpreted as `FS + +c', but
rather as `FS++ c'. See below. Let's see if Arnold agrees.

Hermann

$ cat data
A
B
C
$ gawk-stable/gawk --dump-variables '{ print FS ++c }' data ; tail -n1
awkvars.out
0
1
2
c: string ("")
$ gawk-stable/gawk --dump-variables '{ print FS++ c }' data ; tail -n1
awkvars.out
0
1
2
c: string ("")
Thanks. It seems you're right indeed:

$ gawk 'BEGIN{ c++; print FS ++c ; print FS}'
01
1
$ gawk --dump-variables 'BEGIN{ c++; print FS++ c ; print FS}'
01
1
$ grep -E '^(c|FS)' awkvars.out
FS: number (1)
c: number (1)

That would explain the leading 0 (FS converted to number before the
postincrement). Still, it seems weird to me that "FS ++c" is parsed
as being a postincrement for FS, despite the intervening space. A (very)
quick look at the grammar doesn't seem to allow that.

But yes, it seems that it happily accepts it:

$ gawk 'BEGIN{ print ++   c}'
1


Just to add another (somewhat surprising) result:

$ gawk-stable/gawk --dump-variables '{ print -- FS++ c }' data ; egrep "^(FS|c)" awkvars.out
-11
-22
-33
FS: number (-3)
c: number (3)

Hermann



reply via email to

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