Thanks to visit codestin.com
Credit goes to github.com

Skip to content

electrikmilk/aml

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AML

Build Releases License GoDoc Go Report Card

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@latest

Build from source:

go build
sudo mv aml /usr/local/bin

Run the interpreter with no arguments to enter the interactive shell:

aml
Enter "q" to quit

> _

Run with an AML file:

aml file.aml

Run tests after building:

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.

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.


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.

Error Handling