Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/sahidev1/calculator

A calculator for arithmetic mathematical expressions, developed from scratch with lexer, parser and evaluater
https://github.com/sahidev1/calculator

elixir evaluator functional-programming lexer parser

Last synced: 7 days ago
JSON representation

A calculator for arithmetic mathematical expressions, developed from scratch with lexer, parser and evaluater

Awesome Lists containing this project

README

        

This is code for an arithmetic calculator, it evaluates arbitrary mathematical expresssions such as "3 + 4 * (5 - 4/2)". It supports integer and decimal addition,subtraction,multiplication,division and exponentiation. It also support integer modulus operation.

The calculator consists of a tokenizer, parser and evaluater. The tokenizer creates tokens for the expression. The parser is a recursive decent parser which parses the tokens and builds an abstract syntax tree. The evaluater simply evaluates the abstract syntax tree.

To run the interactive calculator you need elixir installed. To run it from terminal:

iex interactive_calculator.ex

there is a mix version of app on the branch "mix"

## todo

* Fix exponentiation evaluation, right now it is evaluated left to right, but it should be right to left.