Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/sahidev1/calculator
- Owner: Sahidev1
- Created: 2024-12-10T17:44:58.000Z (about 2 months ago)
- Default Branch: main
- Last Pushed: 2025-01-07T19:58:11.000Z (23 days ago)
- Last Synced: 2025-01-07T20:45:34.057Z (23 days ago)
- Topics: elixir, evaluator, functional-programming, lexer, parser
- Language: Elixir
- Homepage:
- Size: 1.11 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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.