Skip to content

Latest commit

 

History

History
34 lines (27 loc) · 955 Bytes

File metadata and controls

34 lines (27 loc) · 955 Bytes

C++ expression parsing.

Minimal example.

#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;
}

More examples.

  • See test-shunting-yard.cpp.

Features.

  • Unary operators. +, -
  • Binary operators. +, -, /, +, <<, >>
  • Map of variable names.

Adding a binary operator.

To add a binary operator,

  1. Update the operator precedence map in calculator::calculate.
  2. Add the computation to calculator::consume.