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: Davide Brini
Subject: Re: Unexpected result while constructing strings
Date: Sat, 30 Oct 2010 15:05:15 +0100

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

-- 
D.



reply via email to

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