AeroScript
Started as a course project in programming language design at the University of Oslo. The static analysis was added after the course.
A small programming language for drone flight missions. You write a mission in plain commands, and AeroScript reads it, checks it for mistakes before anything flies, and then runs it step by step.
Try it
Edit the mission and press Run. Mistakes are caught before the mission runs. Try removing TAKEOFF or dividing by zero. The map shows the points the drone moves to.
This playground runs a small JavaScript port of the interpreter so it works in the browser. The real one is Java and ANTLR, and it's on GitHub.
How it works
Every programming language goes through the same steps before anything runs. AeroScript has all of them.
- Lexer. Splits the text into tokens like
MOVE,(,40and names. - Parser. Checks the tokens against the grammar and builds a tree of the program. A missing bracket stops here with an error.
- Static analysis. Checks the mission before it runs. It catches variables used before they exist, moving before
TAKEOFFor afterLAND, division by zero, backwardsRANDOMranges and zero or negative speeds. Values that don't depend onRANDOMare worked out ahead of time, soLET z = 1 - 1followed by10 / zis caught too. - Interpreter. Walks the tree, keeps track of variables, evaluates the maths and runs each instruction in order. It only runs if the analysis found no errors.
The grammar is written in ANTLR, which generates the lexer and parser from it. The interpreter is a visitor in Java, and JUnit tests cover parsing, expressions, the static analysis, the interpreter and error handling.
The language
| Statement | What it does |
|---|---|
TAKEOFF | Launch the drone |
LAND | Land the drone |
MOVE TO (x, y) | Fly to a point, with optional SPEED and TIME. MOVE TO POINT (x, y) also works |
WAIT n | Hold position, with optional TIME |
LET name = … | Store a value in a variable |
Expressions support + - * /, minus signs, brackets, variables and randomness with RANDOM or RANDOM [lo, hi]. Comments use // or /* */.