Calc.py - A powerful Python REPL calculator

Overview

Calc - A powerful Python REPL calculator

This is a calculator with a complex source that includes a small AST, a parser and a tokenizer. This is a personal project done in 2 days to understand how operator precedence works and to practice my rusty skills of making interpreters.

This project has no external dependencies and should work with minimum Python 3.8 and newer versions of the Python interpreter.

Features

  • Complex but small and understandable source code. Implemented in less than 450LoC
  • Supports all basic operations (sum, substraction, multiplication, division)
  • Supports use of parentheses
  • Proper precedence order of operations
  • Rich errors handling (human-readable exceptions and hints to fix them)

Usage

Just start main.py with Python, this will create a REPL in your terminal which you can close by typing exit.

Modules explanation

  • ast
    • Contains all Tree classes
  • evaluator
    • Evaluates our generated AST
  • exception
    • Error handling, custom Exception class
  • parser
    • Parses our generated tokens and makes an AST
  • scanner
    • Scans our expressions and makes tokens
  • token
    • Tokenizer classes, debugging function to print tokens

License

This calculator is licensed under GPLv3.

You might also like...
A simple and usefull python calculator.
A simple and usefull python calculator.

simplepy-calculator Your simple and fresh calculator. Getting Started Install python3 from the oficial python website or via terminal. Clone this repo

A complete python calculator with 2 modes Float and Int numbers.
A complete python calculator with 2 modes Float and Int numbers.

Python Calculator This program is made for learning purpose. Getting started This Program runs using python, install it via terminal or from thier ofi

A python script to decrypt media files encrypted using the Android application 'Secret Calculator Photo Vault'. Supports brute force of PIN also.

A python script to decrypt media files encrypted using the Android application 'Secret Calculator Photo Vault'. Supports brute force of PIN also.

The calculator on Python.

Calculator Contributors: Delitanast An official website. Information Hello! I am Damir. It`s my first Python project. I think you want see this. I imp

This is a program for Carbon Emission calculator.
This is a program for Carbon Emission calculator.

Summary This is a program for Carbon Emission calculator. Usage This will calculate the carbon emission by each person on various factors. Contributor

Number calculator application.

Number calculator application.

Simple calculator with random number button and dark gray theme created with PyQt6
Simple calculator with random number button and dark gray theme created with PyQt6

Calculator Application Simple calculator with random number button and dark gray theme created with : PyQt6 Python 3.9.7 you can download the dark gra

Flask-built web application that simulates a time and cost calculator for charging Electric Vehicles.

ev_charging_calculator Flask-built web application that simulates a time and cost calculator for charging Electric Vehicles. The project aims to simul

A GUI love Calculator which saves all the User Data in text file(sql based script will be uploaded soon). Interative GUI. Even For Admin Panel

Love-Calculator A GUI love Calculator which saves all the User Data in text file(sql based script will be uploaded soon). Interative GUI, even For Adm

Owner
Alejandro
Linux enthusiast, Neovim simp.
Alejandro
Implements a polyglot REPL which supports multiple languages and shared meta-object protocol scope between REPLs.

MetaCall Polyglot REPL Description This repository implements a Polyglot REPL which shares the state of the meta-object protocol between the REPLs. Us

MetaCall 10 Dec 28, 2022
Replite - An embeddable REPL powered by JupyterLite

replite An embeddable REPL, powered by JupyterLite. Usage To embed the code cons

Jeremy Tuloup 47 Nov 9, 2022
Subnet calculator script using python

subnetCalculator Subnet calculator script using python3 Interactive Version Define the subnet variable interactively Use: subnetDict = subnetCalculato

null 1 Feb 15, 2022
Python calculator made with tkinter package

Python-Calculator Python calculator made with tkinter package. works both on Visual Studio Code Or Any Other Ide Or You Just Copy paste The Same Thing

Pro_Gamer_711 1 Nov 11, 2021
This is a Python package named - calculator

Calculator Python Package This is a Calculator Package of Python. How To Install The Package? Install calchundred with pip (Package Installer Of Pytho

Arinjoy_Programmer 1 Nov 21, 2021
Calculator in command line using python programming language

Calculator in command line using python programming language University of the People Python fundamental Chapter 5 Conditionals and recursion The main

mark sikaundi 3 Dec 9, 2021
Simple calculator made in python

calculator Uma alculadora simples feita em python CMD, PowerShell, Bash ✔️ Início ?? apt-get update apt-get upgrade -y apt-get install python git git

Spyware 8 Dec 28, 2021
PythonCalculator - A simple Calculator made in python using tkinter for GUI

PythonCalculator A simple Calculator made in python using tkinter for GUI. For P

ʀᴇxɪɴᴀᴢᴏʀ 1 Jan 1, 2022
An easy python calculator for those who want's to know how if statements, loops, and imports works give it a try!

A usefull calculator for any student or anyone who want's to know how to build a simple 2 mode python based calculator.

Antonio Sánchez 1 Jan 6, 2022
A calculator developed in Python.

Calculadora Uma simples calculadora... ( + − × ÷ ) ?? Situação do projeto: Projeto finalizado ✔️ ?? Tecnologias: Python Tkinter (GUI) ⚙️ Pré-requisito

Arthur V.B.S. 1 Jan 27, 2022