Skip to content

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

License

Notifications You must be signed in to change notification settings

leslierichardson95/cpp-expression-parser

 
 

Repository files navigation

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.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 100.0%