Is it possible to parse an expression (without ambiguity) that can contains binary prefix, binary infix and binary postfix operators (let's assume that all the symbols are different) with precedence between them? For example:
a = 2 3 post+
b = pre+ 2 3*4
Then a
would equal to 5 because =
has lower precedence than the postfix post+
operator and b
would be 14
. I know that you can parse infix notated expressions with operator precedence parse or shunting yard but this problem seems far more complex for me.
Edit:
Parenthesis are allowed and pre/post variations of an operator have the same precedence as the infix one.
I would like to roll a hand-written algorithm.
Edit2:
By precedence I mean how much to consume. For example this:
a = 2 3 post+
Could 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 one is what I need in this situation). I can't really use existing parser generators or fixed grammar for operands because the operators are loaded dynamically.