K
K
Kirill Zhilyaev2018-11-18 00:17:24
Algorithms
Kirill Zhilyaev, 2018-11-18 00:17:24

How to parse unary operator in reverse polish notation?

Did OPN according to this article: https://m.habr.com/post/282379/. Everything is fine, but the algorithm does not work correctly with carbon monoxide negation. How to fix?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
jcmvbkbc, 2018-11-18
@kirill_782

Everything is fine, but the algorithm does not work correctly with unary negation.

It is not designed to work with unary negation.
The easiest way is by introducing a special symbol for unary negation, which is different from other operators.
Otherwise, you will have to enter an additional state - whether the previous character was and whether it was an operator, and if so, then treat the operator '-' immediately following it as unary.

X
xmoonlight, 2018-11-18
@xmoonlight

Add your operator or function, and process.
(Out of the box, OPN does not work with unary negation)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question