:  Mercat


my cross-platform programming system

Published: 2017 October 13


Back in 1997 I decided, more or less for the hell of it, to design and implement a programming system. Mercat, nee Micron, is that language, and this is it.

Mercat is not really useful for anything much. It is, on the other hand, an excellent example of how to implement a self-hosted recursive-descent-parsed language and virtual machine. The code is --- I hope --- reasonably easy to understand, and I think the overall design is quite elegant.

Features include:

  • Garbage collection
  • Portable binary files
  • C-like syntax
  • Associative arrays as a primitive type
  • Real strings
  • Easily expandable through a simple, fast system call interface
  • Self-hosted; the compiler and assembler are written in Mercat
  • Text screen interface through ncurses

Supported platforms:

  • DOS, 16-bit (compiled with Borland C)
  • DOS, 32-bit (compiled with DJGPP)
  • Linux
  • Any other Posix system

Here's some code, taken from one of the example programs, a full-screen editor.

function void MenuInitialise
        array Menu menubar;
    int i;
    int j;
    int x := 1;
    int w;
    string label;

    for(i:=0; i<sizeof(menubar); i:=i+1)
        menubar[i].x := x;
        w := sizeof(menubar[i].label);
        x := x + 2 + w;
        for(j:=0; j<sizeof(menubar[i].item); j:=j+1)
            label := menubar[i].item[j].label;
            if (sizeof(label) > w)
                w := sizeof(label);
        menubar[i].width := w;

So you want to give Mercat a try

Because Mercat is portable, the bulk of the code is provided as platform-independent .mo files. All you need is an interpreter for your system. Therefore, you will need:

plus one of these, depending on your platform:

If you don't have any of those platforms, or want to rebuild the run-time from source, then you'll want this:

Example programs and documentation are provided in the core file.

One of the main interesting features of mercat is the bootstrap compiler, which is a full recursive-descent compiler written in... awk. Yes, really. It actually works reasonably well, although it does stretch the limits of what the language can do. For convenience, therefore, here's a direct download.

If you are of a historical bent, you might be interested in the prior Mercat version, 0.2.1.