Giter Club home page Giter Club logo

functionparser's Introduction

Function Parser

Source Dandarawy/FunctionParser
This fork fix bug with math.pow
This repo contains 4 different projects:

1. FunctionParser:

A class library to parse and evaluate any mathematical expression.
The parser is applying the following rules to evaluate any expression:

  • expr → expr + term | expr - term | term
  • term → term * factor | term / factor | term ^ factor | factor
  • factor → number | ( expr ) | -factor | id | function
  • function → functerm
  • func → Sinh | Sin | Cosh | Cos | Tanh | Tan | Coth | Cot | Sich | Sic | Csch | Csc | E | Log | Ln

For more information about parsing technique check this Compiler Course Notes.

How to use?

To use the FunctionParser library download the repo and build the project or get the dlls from the release section, then add it to your project, after that you should be able to parse any function using this library as the following:

  • First use the FunctionParser namespace:
    using FunctionParser;
  • Check if the exression is valid or not, if valid create the Expression object
    if (Expression.IsExpression(equation, idsNames))
    {
      Expression expression = new Expression(equation, idsNames, null);
     //Use the expression ...
    }
  • Calculate the expression value according to specific ids values:
    double result = expression.CalculateValue(idsValues);

For more details about how to use the library check FunctionParserWindowsFormTester and FunctionParserAndPlotterTester projects.


2. FunctionParserWindowsFormTester:

FunctionParserWindowsFormTester screenshot

This is a simple tester for the parsing library, write the expression in the textbox if the expression contains ids (variables) add the ids names and values, then the application will evaluate the expression and show the parse tree.


3. FunctionPlotter:

A class library project to plot any series of points, it is based on GDI+. The main class in the library is the Plotter class. To use the plotter class you need to define an object of this class the following line will define a plotter object in which the unit on the x and y axis is represented by 50 pixels and the center of the axis (the origin) is at the center point on the picBox_graph:

Plotter plotter = new Plotter(50, 50, new Point(picBox_graph.Width / 2, picBox_graph.Height / 2));

Create a Curve object and populate its points list, then add this curve object to the plotter's curves list:

plotter.Curves.Add(curve);

Call the Draw functions of the plotter and send the graphics object associated with the control that you want to draw on it, the typical way to do that is to call the draw functions in the paint event of the control

       private void picBox_graph_Paint(object sender, PaintEventArgs e)
       {
           plotter.DrawGridandAxes(e.Graphics, picBox_graph.Width, picBox_graph.Height);
           plotter.DrawCurves(e.Graphics);
       }

For more info about how to use the plotter check FunctionParserAndPlotterTester source code.


4. FunctionParserAndPlotterTester [TBC]:

FunctionParserAndPlotterTester screenshot

functionparser's People

Contributors

dandarawy avatar bourhood avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.