Command line program written in Swift that acts as a simple calculator: it takes a single argument as an expression and prints out the integer result of evaluating it.
The syntax resembles S-expressions but the rules are simplified. An expression can be in one of two forms:
An integer is just a sequence of base 10 digits. For example:
123
A function call takes the following form:
(FUNCTION EXPR EXPR)
A function call is always delimited by parenthesis (
and )
.
The FUNCTION
is one of add
or multiply
.
The EXPR
can be any arbitrary expression, i.e. it can be further function
calls or integer expressions.
Exactly one space is used to separate each term.
For example:
(add 123 456)
(multiply (add 1 2) 3)
The program can be built using the command:
swift build -c release
And its SwiftCalculator
executable will be located inside the .build/release/
folder.