Skip to content
Vinícius Garcia edited this page May 1, 2017 · 20 revisions

Expression Parser • Build Status License

This project provides a powerful expression parser capable of serving as a core engine for building a programming language. For those interested only in a simple expression parser the calculator class does the job and is quite easy to use. The main parser follows Dijkstra's Shunting-yard algorithm, and modifies Jesse Brown's original code.

This project was developed by Brandon Amos and Vinícius Garcia.

An Engine for Programming Languages

This project provides an Engine for programming languages, meaning it is equipped to support all the most complex features a programming language may need, such as:

  1. Global and local scope management.
  2. Generic built-in data containers (Lists, Maps, Tuples).
  3. A built-in garbage collector with reference counting.
  4. A fully customizable set of operations, functions, types and reserved words.

To know more about it check the links below:

  • Getting Started - basic tutorial
  • Examples - how to build your own programming language
  • Reference section - all the details (under construction)

Mathematical parser:

If all you need is a mathematical parser, the example bellow shows how it works. The built-in operations are sane and will probably satisfy most things you may need.

#include <iostream>
#include "shunting-yard.h"

int main() {
  TokenMap vars;
  vars["pi"] = 3.14;
  std::cout << calculator::calculate("-pi 1", vars) << std::endl; // 2.14
  std::cout << calculator::calculate("b = 0.14", vars) << std::endl; // 0.14
  std::cout << calculator::calculate("pi-b == 3", vars) << std::endl; // 1 (true)
  std::cout << calculator::calculate("sqrt(4)   3**2 == 11") << std::endl; // 1 (true)
  
  return 0;
}

To learn how to download, compile and link this library to your project please follow the steps on this tutorial.