Parsing an expression with binary prefix, infix and postfix operators

Is it possible to analyze an expression (without ambiguity), which may contain a binary prefix, a binary infix, and binary postfix operators (suppose that all characters are different) with priority between them? For instance:

a = 2 3 post+ b = pre+ 2 3*4 

Then a will be 5, because = has a lower priority than the postfix post+ operator, and b 14 . I know that you can parse infix notation expressions with parsing or bypass, but this problem seems to me more complicated.

Edit:

Brackets are allowed, and options before and after the operation have the same priority as the infix.

I would like to collapse the manual algorithm.

Edit2:

For example, I mean how much you need to consume. For instance:

 a = 2 3 post+ 

May result in these AST-s:

 '=' has higher precedence than 'post+': post+ / \ = 3 / \ a 2 'post+' has higher precedence than '=': = / \ a post+ / \ 2 3 

(The second is what I need in this situation). I cannot use existing parser generators or a fixed grammar for operands because statements load dynamically.

+5
source share

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


All Articles