Skip to content

rudlorenz/MathParser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 

Repository files navigation

Math parser

Simple math symbolic manipulation library.

Requirements

  1. C++17 compatible compiler
  2. CMake 3.13

Usage

Clone

https://github.com/rudlorenz/mathParser

To use Expressions in your project add src folder with add_subdirectory() command to your CmakeLists.txt file and include Expressions.h and Parser.h in source files.

Alternatively you can use supplied main.cpp.

Examples

Parsing expression from string:

#include <Parser.h>

auto result = parser::parse("x + y");
if (result != nullptr) {
    std::cout << "result : " << result->to_string();
}

Parse expression from string and find derivative:

#include <Parser.h>

auto result = parser::parse("x * x + 2*x + 10");
if (result != nullptr)
{
    auto derivative = result->diff("x");
    std::cout << "expression : " << result->to_string() << "\n"
        << "derivative : " << derivative->to_string(); 
}

Calls are chainable:

auto result = parser::parse("x*x*y + x*y*y");
auto as_string = result != nullptr
    ? result->diff(x)->diff(y)->to_string();

You can create expressions directly, but it's highly discouraged:

#include "Expressions.h"
    // x * x + y
    auto var_x = std::make_shared<Variable>("x");
    auto var_y = std::make_shared<Variable>("y"); 
    auto result = std::make_shared<Sum>(
        std::make_shared<Mul>(var_x, var_x),
        var_y
    );

TODO

  1. Unit testing.
  2. Proper lexical and synax analysis i.e. input expression validation. Right now it works "garbage in --> garbage out".
  3. Expression simplification.
  4. Proper parser errors.

About

Parse and differentiate math expressions.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •