https://github.com/electrikmilk/aml
Interpreted math equation language 🧮
https://github.com/electrikmilk/aml
calculator interpreter language math math-language parser programming-language
Last synced: 7 days ago
JSON representation
Interpreted math equation language 🧮
- Host: GitHub
- URL: https://github.com/electrikmilk/aml
- Owner: electrikmilk
- License: gpl-2.0
- Created: 2022-08-10T19:25:15.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2023-04-08T15:05:45.000Z (about 3 years ago)
- Last Synced: 2025-11-22T09:19:51.198Z (7 months ago)
- Topics: calculator, interpreter, language, math, math-language, parser, programming-language
- Language: Go
- Homepage: https://pkg.go.dev/github.com/electrikmilk/aml?tab=doc
- Size: 29.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# AML
[](https://github.com/electrikmilk/aml/actions/workflows/go.yml)
[](https://github.com/electrikmilk/aml/releases)
[](https://github.com/electrikmilk/aml/blob/main/LICENSE)
[](https://pkg.go.dev/github.com/electrikmilk/aml?tab=doc)
[](https://goreportcard.com/report/github.com/electrikmilk/aml)
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:
```console
go install github.com/electrikmilk/aml@latest
```
Build from source:
```console
go build
sudo mv aml /usr/local/bin
```
Run the interpreter with no arguments to enter the interactive shell:
```console
aml
Enter "q" to quit
> _
```
Run with an AML file:
```console
aml file.aml
```
Run tests after building:
```console
go run tests.go
```
---
## Syntax
AML 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.
```aml
5 * (8 + 4) / 8
```
Exponents are supported by following an integer or decimal with the `^` operator and following it with another integer or decimal.
```aml
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 `#`.
```aml
# 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.
```aml
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.
---
## Error Handling
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.
