AML (Arith-Metic Language) is an interpreted math equation language. You can either use the interactive shell by running the interpreter with no arguments, or with a file ending in .aml by passing the name of the file as an argument.
Build latest release:
go install github.com/electrikmilk/aml@latestBuild from source:
go build
sudo mv aml /usr/local/binRun the interpreter with no arguments to enter the interactive shell:
aml
Enter "q" to quit
> _Run with an AML file:
aml file.amlRun tests after building:
go run tests.goAML can interpret human readable equations, no extra syntax is required beyond standard mathematical syntax.
| Operator | Action |
|---|---|
| + | Add |
| - | Subtract |
| *, × (times) | Multiply |
| / | Divide |
| % | Modulus (division remainder) |
| ^ | Denote Exponent |
| ( | Start closure |
| ) | End closure |
| = | Equality |
| var | Denote variable |
| const | Denote constant |
Each equation must be on its own line.
Basic arithmetic operators should only be in between integers (or decimals).
Expressions (a statement of integers and operators) may be inside of closures and calculated separately, but operands must follow and precede closures. Closures will be evaluated separately in order.
5 * (8 + 4) / 8
Exponents are supported by following an integer or decimal with the ^ operator and following it with another integer or decimal.
2^4 * 16
Comments are allowed, but must either be on their own line or at the very end of a line. Comments are denoted using #.
# This is a comment
2 + 2 # equals 5
# This is a
# multiline
# comment
Variables and constants are supported, but currently must be only one character long.
var x = 10
const y = 10
x * y
Variables can be reassigned, while constants cannot. Variables and constants must all have unique identifiers.
Variables and constants must either be an integer, decimal or exponent.
When an input is found to be invalid during or after parsing, a detailed error message will be printed showing the exact line and column that is invalid.