bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] pretty-print eats parentheses


From: Manuel Collado
Subject: Re: [bug-gawk] pretty-print eats parentheses
Date: Thu, 30 Oct 2014 11:05:44 +0100
User-agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/17.0 Thunderbird/17.0

El 30/10/2014 5:03, Hermann Peifer escribió:
Hi Arnold and others,

Below a small observation which I made while trying to construct a
string consisting of negative integers with FS in between.

I'm on gawk from git, on OSX 10.10.

Regards, Hermann

PS: I had a feeling of "déjà vu", but this historical issue was slightly
different:
http://lists.gnu.org/archive/html/bug-gnu-utils/2009-08/msg00018.html

-------

# Does not work as I expected..
$ gawk 'BEGIN{FS="|"; str = -8 FS -9 ; print str}'
-8-9

The second minus sign is parsed as a subtract operator. The expression is evaluated as -8 (FS - 9). FS is converted to number before subtraction and later concatenation. The pretty printer gives:

$ gawk -o/dev/stdout 'BEGIN{FS="|"; str = -8 FS -9 ; print str}'
-8-9
        BEGIN {
                FS = "|"
                str = -8 FS - 9
                print str
        }


# ..but this does
$ gawk 'BEGIN{FS="|"; str = -8 FS (-9) ; print str}'
-8|-9

Now the second minus sign is parsed as part of a negative numeric constant. There is no subtract operator, just a concatenation one.


# My parentheses are gone :-(
$ gawk -o/dev/stdout 'BEGIN{FS="|"; str = -8 FS (-9) ; print str}'
BEGIN {
     FS = "|"
     str = -8 FS -9
     print str
}


This is really weird. In any case please note the difference "- 9" vs "-9" in the prettied code for both cases.

Hope this helps. Regards.

--
Manuel Collado - http://lml.ls.fi.upm.es/~mcollado




reply via email to

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