bug-gawk
[Top][All Lists]
Advanced

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

A bug in parsing of conditional ops?


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

Good day.

GNU Awk 5.3.0, API 4.0, PMA Avon 8-g1, (GNU MPFR 4.1.0-p13, GNU MP 6.2.1)
here.

Initially I thought that I found an error in docs
which state that the precedence table is:
   ...................
   < > <= >= == !=
   ~ !~
   in
   &&
   ||
   ?:
   = += -= *= /= %= ^=
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.

I thought that maybe it's just an error in docs,
== and = in fact have the same precedence and are both right-associative,
this would explain why the above works (it is treated as "3==(v=3)"),
and this also works:

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

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

This is more clearly a bug, since there is nothing wrong
with comparing the result of comparison. 3==3==3
should be interpreted as (3==3)==3 and evaluate to 0
("false, 1 is not equal to 3").

This suggests that parser is just broken somehow,
and "3==v=3" unexpectedly working is just a glitch
due to that breakage.

What do you think?




reply via email to

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