Which of the following postfix notations correctly represents the infix sum 1 + 2 + 3 + 4?

I am testing the infix-to-postfix-to-infix converter and have detected some uncertainty. For example, a simple infix sum

1 + 2 + 3 + 4

can be converted to postfix

1 2 + 3 + 4 +

assuming operators with the same priority do not accumulate. If they are then, I get

1 2 3 4 + + +

On the other hand, all subsequent postfix expressions can be converted to the initial sum

1 2 + 3 + 4 +
1 2 + 3 4 + +
1 2 3 4 + + +

Are all these postfix expressions correct?

Update1

If you made such a converter, in what form would you choose? I need to choose one for testing.

+3
source share
3

.

, . - .

1 2 3 4 b c d . , a + b + c + d , a b + c + d + .

, " ", . () C.

+6

, . :

((1 + 2) + 3) + 4
(1 + 2) + (3 + 4)
1 + (2 + (3 + 4))
+5

+ - , .

Consider replacement +to other local operators 1 a 2 b 3 c 4.
The correct result here for left-associative operators is

1 2 a 3 b 4 c

So in your case, I would expect 1 2 + 3 + 4 +

+2
source

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


All Articles