/calc

➗ A command line math expression parser / interpreter.

Primary LanguageKotlin

➗ Calc

Build Status

A totally overkill command line math expression parser / interpreter.

Installation

Installation instructions will follow soon.

Usage

For short expressions, the easiest way to use the calculator is by passing a math expression as a command line argument to the application.

Examples:

$ calc 4 * (5 + 3)
// Output: 32
$ calc 4^2 + sqrt 25 - 20
// Output: 1

Language Specification

Program         => Expression+
Expression      => ( Expression ) | UnaryOperation Expression | Expression BinaryOperation Expression | Number

UnaryOperation  => - | sqrt | √
BinaryOperation => + | - | / | * | ^ | % | mod

Number          => Integer | Float
Integer         => Digits
Float           => Digits . Digits | . Digits | Digits .

Digits          => [0-9]+

Notes (not necessarily related to the specification):

The unary operations sqrt and are equivalent.

The binary operations mod and % are equivalent.

In the current version multiple-expression programs are not allowed.