Hello.
This code snippet is a basic calculator.
The general concept is that the calculator accepts infix expressions as strings, converts them to reverse polish notation by way of the shunting-yard algorithm and then evaluates the resulting expression.
I tried to encapsulate the functionality of each piece so that, in theory, they could be pulled out and used independently. The shunting-yard behavior is provided via class ShuntingYard
; I used the visitor pattern for the Token
; and RPNExpression
could be built by hand (or some other process) and still be used with Calculator
.
I removed almost all error checking and input validation for the sake of brevity and readibility. Code compiles with MSVC++ and GCC 4.6.3.
Any feedback is appreciated.