bug-gawk
[Top][All Lists]
Advanced

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

Re: A bug in parsing of conditional ops?


From: Denys Vlasenko
Subject: Re: A bug in parsing of conditional ops?
Date: Tue, 9 Jul 2024 18:36:46 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0

On 7/9/24 16:04, arnold@skeeve.com wrote:
since this unexpectedly works:

        $ awk 'BEGIN { print 3==v=3, v}'
        1 3

According to the table, it should not, (3==v)=3 is not a valid assignment.

It's parsed (as you noted) as 3 == (v = 3)

Well, it shouldn't. The == has higher precedence than =.


        $ awk 'BEGIN { print v=3==3, v}'
        1 1

This is parsed as v = (3 == 3). C parses it the same way.

Yes. This one is correct, no argument here.
I am showing that gawk correctly handles precedence of =
and == in this case.


But there is more: more than one comparison op fails to parse:

        $ awk 'BEGIN { print 3==3==3}'
        awk: cmd. line:1: BEGIN { print 3==3==3}
        awk: cmd. line:1:                   ^ syntax error

        $ awk 'BEGIN { print 3==3!=3}'
        awk: cmd. line:1: BEGIN { print 3==3!=3}
        awk: cmd. line:1:                   ^ syntax error

Brian Kernighan's awk treats it as a syntax error. Mawk
actually prints 0 for the first one and 1 for the second.

Looks like mawk gives correct results:
"3==3" is 1, and "1==3" is 0
"3==3" is 1, and "1!=3" is 1




reply via email to

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