Skip to content

Draggu/math-expression-evaluator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Math expression evaluator

Table of content

Build

run

cargo build --release

Features

  • operator precedense
  • operator associativity
  • nesting
  • functions
  • function from operator
  • pipes
  • variables

Usage

for convenience target/release/math-expression-evaluator will be called calc

all whitespace characters are ignored!

to evaluate expression run following

calc "expression"

to use variables specifie them in following format

calc --var <var_name>=<value> "expression"

example

calc --var a=1 --var b=2 "a+b-3"

parentheses are respected

calc "4*(2+3)"

outputs 20 as expected

functions can be used in different ways

classic call (trailing comma is optional)

calc "add(2,5,)"

converting operator to function

calc "(+)(2,5)"

every function is automatically curried

calc "(+)(2)(5)"
calc "add(2)(5)"

pipes syntax is

calc "<value> | <one_arg_function>"

example

calc "2|(+)(4)|(^)(3)"

and it's equal to

calc "3^(2+(4))"

Technologies

Purpose

this project was created to learn rust and parsers

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages