Update: What you suggest using Reverse Polish or Shunting Yard (Note ! works on one variable like this !x)?
I am going to implement a simple compiler in C++ that supports the following 5 signs
+ - * / !
While !
is always calculated first and the rest are calculated from left to right (non has advantage on the other)
Plus, I want the compiler to support braces so the following z= x + ( y+l)
will calculate y+l first then add x to it while z=x+ y+ l
calculates x+y first and adds z to it and this is illegal: z=x+
I though about adding braces whenever possible and then always to follow the deepest one like turning this: z=x+ y+ l
into this: z=((x+ y)+ l)
But that sounds to be hard and easy to make mistakes.
Any different suggestions? I heard once about using trees but C++11 has no trees and I don't know how exactly trees may work here
Please share details ideas if possible