- See the blog post.
- Expression parsing in C++ with Dijkstra's Shunting-yard algorithm.
- Original version by Jessee Brown.
#include <iostream>
#include "shunting-yard.h"
int main() {
std::map<std::string, double> vars;
vars["pi"] = 3.14;
std::cout << calculator::calculate("-pi+1", &vars) << std::endl;
return 0;
}
- See
test-shunting-yard.cpp
.
- Unary operators. +, -
- Binary operators. +, -, /, +, <<, >>
- Map of variable names.
To add a binary operator,
- Update the operator precedence map in
calculator::calculate
. - Add the computation to
calculator::consume
.