Procedure (== against no)

Does anyone know why "boolean not" has a higher priority than ==the order of operations for most programming languages?

In mathematical logic / model theory, right? I recently wrote the following in Lua:

if not 1 == 2 then
    print("hi")
end

He did not print “hello” due to the order of operations between not and ==, which seems strange to me.

+4
source share
3 answers

, . , , ( 1 ~= 2). , , , .

, not green and not blue " , ". not not (green and not blue), .

+5

not 1 == 2 not (1 == 2). , ; - not, 1, , , .

"/ ".

+1

== . - =. - . , == , ==.

= , a = b , a b - . , a ↔ b, a ↔ b, a b . , not a ↔ b (not a) ↔ b not a = b not (a = b).

, = == , , , , , ==, -.

The reason this is hard to implement is because the parser usually takes precedence over the statement. When the parser translated the source code into the syntax tree, the operator priority is already encoded in the tree. Type checking (if any) works with the syntax tree. Thus, the analyzer does not have access to type information, which implies that it cannot use type information to apply various priority rules.

0
source

Source: https://habr.com/ru/post/1660128/


All Articles