All projects

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.

Built withJava, ANTLR 4, Gradle, JUnit 5
CodeGitHub

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.

  1. Lexer. Splits the text into tokens like MOVE, (, 40 and names.
  2. Parser. Checks the tokens against the grammar and builds a tree of the program. A missing bracket stops here with an error.
  3. Static analysis. Checks the mission before it runs. It catches variables used before they exist, moving before TAKEOFF or after LAND, division by zero, backwards RANDOM ranges and zero or negative speeds. Values that don't depend on RANDOM are worked out ahead of time, so LET z = 1 - 1 followed by 10 / z is caught too.
  4. 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

StatementWhat it does
TAKEOFFLaunch the drone
LANDLand the drone
MOVE TO (x, y)Fly to a point, with optional SPEED and TIME. MOVE TO POINT (x, y) also works
WAIT nHold 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 /* */.