Minimal expression tree for a calculator grammar
View source on GitHubB1Z0N/AntlrCalculator

lablanguagestools

AntlrCalculator

Parser-generator calculator lab.
  • Java
  • ANTLR
  • Maven
  • Docker
Date
April 2022
Status
Historical
Visibility
Public

Simple CLI calculator app for me to get used to ANTLR parser generator.

Operations

The calculator supports the following operations:

  • Addition (+)
  • Subtraction (-)
  • Multiplication (*)
  • Division (/)
  • Modulo (%)
  • Unary plus (+)
  • Unary minus (-)
  • Parentheses for grouping (())

Up and running

NB: For some of the scripts below you may need to run it with sudo, even though I discourage it.

Locally

To build locally you need maven, to run you need java. I use openjdk18.

  1. To build:
./scripts/build.sh
  1. To run as CLI:
./scripts/run.sh "(1.0 + -2)*-2.5e+1"  # wait for some time
  1. To run as interactive REPL:
./scripts/run.sh  # wait for some time
  1. To run tests:
./scripts/test.sh

Docker

  1. To build:
./scripts/docker/build.sh
  1. To run as CLI:
./scripts/docker/run.sh "(1.0 + -2)*-2.5e+1"  # wait for some time
  1. To run as interactive REPL:
./scripts/docker/run.sh  # wait for some time
  1. To run tests:
./scripts/docker/test.sh

TODO

  1. Cache some maven dependencies during docker build so that it doesn’t take lifetime to run.
  2. Mount src to docker so that you could edit it on the fly.