Git Product home page Git Product logo

calc's Introduction

Warning

This was the beginning of my journey into programming language design.
This repository is now unmaintained and buggy.
For a cli calculator that does way more than this (it's actually an entire programming language) refer to Tau.
Tau is where all the development in the subject is being carried out.

calc

A fast and simple cli calculator.

Install

You can install calc just as any other go project:

go get -u github.com/NicoNex/calc

Usage

You can use calc in both shell mode and command mode.

Shell mode

This mode is like the python shell, this mode supports many comfortable and useful terminal features.

>>> 2+2
4
>>> 3*(5/(3-4))
-15
>>> my_var = 4*2^5
128
>>> my_var = my_var/2
64
>>> big_var = 2^128
3.402823669209385e+38
>>> 2*/(3+8)
syntax error: invalid operand
	2*/(3+8)
	  ^

Command mode

You can use calc to evaluate expressions with a single command:

$ calc '3^2+(19-4)*2'
39
$

Supported functions, operators and constants

Operators

+, -, *, /, ^. Other operators coming soon.

Functions

Coming soon.

Constants

Coming soon.

Backstory

I was annoyed by the lack of 'bc' on the old Windows version I have to use at work so I thought that writing my own cli calculator would allow me to learn some fun stuff.

Additional resources

The lexer is heavily inspired by 2011 Rob Pike's talk on lexical scanning. The parser implements the Edsger Dijkstra's Shunting-Yard Algorithm to produce postfix notation from infix.

calc's People

Contributors

niconex avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.