leslierichardson95 / cpp-expression-parser

Expression parsing in C++ with Dijkstra's Shunting-yard algorithm.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

About

Expression parsing in C++ with Dijkstra's Shunting-yard algorithm.

License:MIT License


Languages

Language:C++ 100.0%