I have to write an interpreter for tristate logic as a Uni assignment.
I got most of the things down, like expression tree and such, there is just one thing that's bugging me, that is input, or a particular part of it.
The thing is, in the expression there can be a reference to another expression (they are numbered). My problem is, how does one expression know about the address of another?
I can see two approaches to this, neither satisfactory.
One thing is to keep a
vector of pointers as a static class member, second is to move parsing outside of the class, which incurs writing much more code.
If I have been unclear, consider this sample input.
S followed by a number is an expression or a reference to one.
Oh yeah, forgot to mention, this is Polish (prefix) notation.
S1 = OR T x1 S0 = AND S2 S1 print S0 S1 = AND F x0 S3 = ARG2 S0 S4 = OR S1 x0