Asterix: a BNF-like low-level programming language
==================================================

Introduction
------------
Asterix is a programming language that provides low- to medium-level
general-purpose functionality (basic integer arithmetic, memory access,
functions, and variables) with a syntax that resembles the Backus-Naur
Form (BNF) and compiler/parser-generator languages like Yacc.

It is currently bootstrapped by a compiler written in prox2, which
itself is a low-level language that combines the compiler-generator
style with more C-like general-purpose coding. However, in prox2, these
two different styles were separated and did not interact very well,
requiring choices between which one to use for each part of the code as
well as some specific run-time code to glue them together (i.e.
transfer control and data between them).

In Asterix on the other hand, functions and "grammar rules" are the same
thing. Its statements and expressions somewhat resemble "semantic
actions" from conventional parser generators, but can also specify
arbitrary conditions to be "matched". Control flow is defined by
BNF-like sequence, alternation, and repetition forms.

It should not be confused with an actual parser generator, because it
does not treat the code as any kind of formal language specification or
other high-level definition. Instead, the "rules" specify a program
directly, and are compiled to low-level instructions linearly, without
any optimization or thorough analysis.

Like prox2 and its predecessors, Asterix takes significant inspiration
from a compiler-writing language published in 1964 called "META II"[1].

Besides its unusual style, one of Asterix's primary "features" is its
size: the self-hosting compiler, assembler (intermediate code to machine
code), and run-time support code together make up only about 1000 lines
of code.

The bootstrapping path involves more code, of course, since it goes
through prox2 (which is larger) and several predecessors that came
before it, down to cmeta and a hex-to-binary conversion program[2]. This
adds up to several thousand lines of code. Building the binaries also
requires a few utilities from the operating system. For a more detailed
description of the bootstrap, see the file "bootstrap.txt".

[1] "META II -- a syntax-oriented compiler writing language" --
    D. V. Schorre ... http://www.ibm-1401.info/Meta-II-schorre.pdf

[2] The idea of bootstrapping a compiler "from scratch" this way was
    inspired by a project called "bcompiler" by Edmund Grimley Evans.

A word of warning
-----------------
Asterix is not an easy language to use, let alone get started with. The
compiler was written to be small and simple as an implementation of the
language, not necessarily to be simple and easy to use. Variables are
untyped, there is no real hand-holding and not much in the way of error
reporting. It does not generate any debugging information, so stepping
through a program and inspecting its state is a tedious process.

Even simple Asterix programs usually need some code to at least set up
their input and output buffers before they can do anything useful, and
they must take care to catch and handle any failures that may occur, as
well as exit gracefully once the program has done its work, in order to
avoid simply crashing at the end of it.

The language description file has a section describing some possible
pitfalls to watch out for.

Documentation
-------------
For a description of the language, see the file "language.txt".

For an explanation on how to compile Asterix programs, see "build.txt".

Legal information
-----------------
Copyright (c) 2019, 2020 Pim Goossens

Except where explicitly specified otherwise, files in this repository
are distributed under the GNU Lesser General Public License (LGPL),
version 3 or any later version.

This software is provided with NO WARRANTY of any kind.

See the file COPYING for details. Note that it makes references to
another license, namely the GNU General Public License version 3. A copy
of that license is included for reference in the file "GPL-3.txt".
