Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/hacsoc/expr

An expression calculator example.
https://github.com/hacsoc/expr

Last synced: about 2 months ago
JSON representation

An expression calculator example.

Awesome Lists containing this project

README

        

# Expr

By Tim Henderson

## What?

A simple expression calculator for integer math. You give it an expression:

$ expr '1 + 2'
(+ 1 2)
3

It will calculate the result and additionally give you back your expression as
an s-expression.

## Why?

To demonstrate gradle, testing, lexing and recursive descent parsing.

## Install

You must have java 1.7+ and git on your system. Get those first!

$ git clone https://github.com/hacsoc/expr.git
## some output
$ cd expr
$ ./gradlew test installApp
## bunch of output
$ ./build/install/expr/bin/expr '1+2'
(+ 1 2)
3

To make it available for this session run

$ export PATH=$(pwd)/build/install/expr/bin:$PATH

Now you can just run

$ expr '4 * 3/5'
(/ (* 4 3) 5)
2

To "install" permanently do

$ echo "export PATH=$(pwd)/build/install/expr/bin:$PATH" >> .bashrc