calc

command module
v0.0.0-...-9c46660 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 28, 2023 License: GPL-3.0 Imports: 6 Imported by: 0

README

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.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL