Introduction

A simple compiler for an extremely minimal dialect of BASIC called Tiny BASIC. It’s fairly dumb: it tokenizes and parses the source code into an abstract syntax tree, translates the abstract syntax tree into a stack-based intermediate representation and then turns that fairly directly into amd64 assembly.

Example

The following example demonstrates most features of the Tiny BASIC language. It’s a program for printing out square numbers:

10 PRINT "How many squares?"
20 INPUT N
30 LET X = 1
40 PRINT X, " * ", X, " = ", X * X
50 LET X = X + 1
60 IF X > N THEN END
70 GOTO 40

Running the compiler and then the compiled program produces the following output:

$ ./tinybasic examples/squares.tb
$ ./examples/squares
How many squares?
5
1 * 1 = 1
2 * 2 = 4
3 * 3 = 9
4 * 4 = 16
5 * 5 = 25
$

Source code

This project is open-source software available under the terms of the ISC license, which is similar to the 2-clause BSD license. The source code is hosted on GitHub. The README file contains instructions for building and testing it.