I'm trying to make a calculator that parses input like [TEX]( 3 + 2 ) * 5[/TEX]
I want to use formal grammar for this, and I'm wondering how to organize this. I was thinking having a class for Value, which would basically just be a number. Then I want to have another class called Expression, which is made up of 3 parts: the left, the middle (the operator) and the right. However, the left and right could be Expressions, or they could be Values. I was looking into polymorphism, but that was a little confusing. How would I structure this nicely?
And also, what about expressions that dont follow the value, operator, value scheme, like square root? Thanks in advance!