A simple and lightweight math library, that can parse and calculate string expressions.

Overview

Package Logo
pub version License: MIT

Documentation

Create local instance of expression parser.

final ExpressionParser expressionParser = ExpressionParser();

Then you can calculate your "string" expression like:

23 ">
final String exp = "-2 + 5 + 10 * 2";
final double? result = expressionParser.calculate(exp); // --> 23

When we call calculate, it checks the validness of expression automatically. So, we needn't to do some manual checking here. (If expression is invalid, then result would be null)

But in anyways, if you wanna check the validness of expression manually, you can do it, like:

final bool isInvalid = expressionParser.isInvalidExp(exp) // --> false

Also, you can enable, taking the sum of the last result and current by setting keepAddingOn to true.

So, when you enable it, parser allways store your last expression parts. By doing that it can take sum of the last result you got, and the current one.

For example: you calculate "8+2" and got 10 as result. Parser keeps ["8", "+2"] as parts of expression. So, when you make operation after that one, e.g: "2+3", then parts of expression would be: ["8", "+2", "2", "+3"] So, the final result would be (8+2) + (2+3) = 15.

Check official example to see the UI implementation of Mate

Explanation

Parser divides string expression as parts (Stores them in custom Expression class), then loops through the parts and takes sum of them. If string expression is "2+5" then parts would be: ["2", "+5"]. So the sum of parts would be 2+(+5) --> 7.

Let's see with default example: "-2 + 5 + 10 * 2". In this case, parts would be: ["-2", "+5", "10*2"]. We got "10*2" at the end of the part, because of operation priority. So, the final result would be: -2+(+5)+(10*2) --> 3+20 --> 23.

Comments
  • feature/improve errors

    feature/improve errors

    This PR adds high level errors to the calculator.

    Commits:

    • feat: improve repl by adding token logger
    • bugfix: fix sign-number reading issue of lexer
    • hotfix: fix the calculator's index overflow issue
    • feat: add index field to the token structure
    • feat: improve current error cases
    • feat: implement indexed errors
    opened by theiskaa 1
  • feature/absolute value

    feature/absolute value

    Adds the absolute value functionality and updated error handling and errors.

    Commits:

    • feat: improve repl by adding token logger
    • bugfix: fix sign-number reading issue of lexer
    • hotfix: fix the calculator's index overflow issue
    • feat: add index field to the token structure
    • feat: improve current error cases
    • feat: implement indexed errors
    • hotfix: fix typo on changelog
    • hotfix: rename the ROOT related actions to POWER
    • feat: implement abs to token, tokentype, sub
    • feat: improve the sub implementation to [token] and [monitor]
    • feat: re-impl the abs [token-type] implementation
    • feat: impl abs parsing to lexer
    • feat: impl the abs calculator execution
    • chore: update documentations
    documentation feature 
    opened by theiskaa 0
  • Feature/improve errors

    Feature/improve errors

    This PR adds high level errors to the calculator.

    Commits:

    • feat: improve repl by adding token logger
    • bugfix: fix sign-number reading issue of lexer
    • hotfix: fix the calculator's index overflow issue
    • feat: add index field to the token structure
    • feat: improve current error cases
    feature 
    opened by theiskaa 0
  • feature/root

    feature/root

    Adds support to parse and calculate power root expressions.

    5 ^ 2 -> 2th power of 5 -> 25

    Commits:

    • feat: add root token
    • feat: improve token monitoring
    • feat: impl functionality to collect roots in sub-exps
    • feat: implement combine_roots method's functionality
    • feat: impl power calculating to calculator
    • feat: add root tests to lexer
    • chore: update v0.1.3 related documentation
    feature 
    opened by theiskaa 0
  • feature/auto-multiplication

    feature/auto-multiplication

    Diagram:

    Auto append multiplication ◀╮
    if there is no sign between │ two "number"(normal number and sub-exp) token.
       ╭──────────────────╭─────╯
    ╭─ ▼ ───────╮     ╭── ▼ ─────────╮
    │ 4(2 + 10) │ ──▶ │ 4 • (2 + 10) │
    ╰───────────╯     ╰──────────────╯
    

    Description:

    Adds a simple functionality to parse and understood kinda algebric expressions: For example: 5(5 / 2) is same as 5 * (5 / 2), In this case, to make calculator understood this expression, we have to add a PRODUCT(multiplication) token manually between two token numbers. (in this case between 5 and (5 / 2)).

    feature 
    opened by theiskaa 0
  • Feature/parentheses

    Feature/parentheses

    Resolves: #3


    TODO:

    • [x] Aditional tests for parentheses expressions
    • [x] Test deeply, parsing too-high nested expressions
    • [x] Imrpove expression's invalidness chcecker.
    feature 
    opened by theiskaa 0
  • calculate factorial numbers

    calculate factorial numbers

    In mathematics, the factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n. The factorial n! also equals the product of n with the next smaller factorial.

    So how does factorial computing work? Example;

    5! = 5 * 4 * 3 * 2 * 1 = 120

    opened by onurhan1337 1
Releases(v0.1.4)
  • v0.1.4(Nov 2, 2022)

    v0.1.4

    The fifth version of mate.

    1. Added high-level error handling and errors: see in docs
    2. Implemented functionality to parse and calculate absolute-value expressions.
    • Pull Requests: #22 & #23
    • H-E that versions has ability to solve: [ 2 - 12 ] / 2 -> 5
    Source code(tar.gz)
    Source code(zip)
Owner
Ismael Shakverdiev
Self-taught, language-agnostic programmer
Ismael Shakverdiev
Complete clean coded monitized flutter and firebase math app

Clean Archeticture (Flutter Firebase) Complete clean coded monitized flutter and firebase math app | | | | | | This project is a starting point for a

Mason Rahmani (Pahlawan) 4 Nov 15, 2022
Math expression editing using an on-screen software keyboard or physical keyboard input in a typeset input field in Flutter.

math_keyboard is a Flutter package that allows editing math expressions using a typeset input field (so-called "math field") and a custom-made fully i

simpleclub 98 Oct 10, 2022
Instead of a simple counter app, the @FlutterDev team can provide a simple game like the one below.

Instead of a simple counter app, the @FlutterDev team can provide a simple game like the one below. Thanks to the @rive_app team for their easy-to-use animation kit.

Md. Siam 10 Oct 27, 2022
A simple, interactive and customizable on-tap bounce animation that can be wrapped on any widgets that you like.

A simple, interactive and customizable on-tap bounce animation that can be wrapped on any widgets that you like.

null 16 Nov 2, 2022
A simple App made with flutter where you can create Q&A List

iQuestions ?? Welcome to Iquestions project! A simple App made with flutter where you can create Q&A List. This is a Fully Functional App that uses Ge

Filipe Lukebana 3 Sep 13, 2022
Real short video app with firebase and pixels API.Where you can create a short video with pixels' stock videos and also merge your audio.

Real short video app with firebase and pixels API.Where you can create a short video with pixels' stock videos and also merge your audio.

Ansh rathod 55 Dec 26, 2022
A Flutter package which can be used to make polylines(route) from a source to a destination, and also handle a driver's realtime location (if any) on the map.

GoogleMapsWidget For Flutter A widget for flutter developers to easily integrate google maps in their apps. It can be used to make polylines from a so

Rithik Bhandari 14 Nov 30, 2022
It is an application where you can find out how many people are in space, news about space and access random space photos.

It is an application where you can find out how many people are in space, news about space and access random space photos. This application was made to learn the dart language.

Emre Taner Çetinkaya 4 Oct 8, 2021
Chitchat, a messaging app similar to other messengers, people can send and receive messages.

Chitchat, a messaging app similar to other messengers, people can send and receive messages. To send and receive messages you first need to create an account for the app!!.

Satyam kant 3 Oct 4, 2021
mezza 0 Nov 24, 2021
A social media platform where you can build your own community.

Commun App A social media platform where you can build your own community. Contributing If you wish to contribute a change to any of the existing feat

Sonu Sharma 61 Dec 24, 2022
Flutter Developer Profile App, you can contribute by adding yourself as a developer.

Flutter App - Developers Profile Flutter Developer Profile App. You can contribute by adding yourself as a developer. ?? About the repository This Rep

Hacktoberfest SIT '21 3 Nov 17, 2022
Flutter project file sturcture that can help me to create new project easily

flutter_project_arch A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you sta

Rafat Jamader Meraz 1 Oct 9, 2022
This is a User Profile where the user can edit their information.

Flutter User Profile App This repository shows how I built a simple User Profile UI using Flutter. Please note that I was unable to get the Profile Im

Ivanro Lagazo 20 Jan 4, 2023
A Flutter Ecommerce App can upload a product according to a particular category & brand

Ecommerce App This is a Flutter Project. Here, sellers can upload a product according to a particular category & brand. Customers can navigate the pro

Padmanabha Das 5 Oct 1, 2022
Create a way so that user can share all his social media profile links on a single click

Pro Share The objective of this project is to, create a way so that user can share all his social media profile links on a single click. The project a

Sarthak Agarwal 5 Nov 20, 2022
This is an E-commerce App that you can buy goods, it has no data base so all you see in this app are created as default

This is an E-commerce App that you can buy goods, it has no data base so all you see in this app are created as default. Once I create a server and connect with it, I will create another repository or simply update this one.

Khusan Flutter Dev 2 Feb 10, 2022
Poi-Poi-ToDo - A Task Management App where you can create task & maintain your daily life easily

"Poi Poi Todo" is a Task Management App where you can create task & maintain your daily life easily. In this app we use Path Provider, SQLite Database, DateTime Picker etc flutter pakages.

CPAD-Gazipur 8 Oct 30, 2022
Flutte movies app, can be use as a starting point for your next project

Flutte movies app, can be use as a starting point for your next project

Ezaldeen Sahb 2 Feb 28, 2022