snusp2c

snusp2c [1] is a slightly optimizing compiler from Modular SNUSP to C in Python.

SNUSP

SNUSP (SNUSP’s Not Unix, but a Structured Path) is a 2-dimensional esoteric language, a successor to Path, and a relative of Brainfuck. In SNUSP source code is a grid of characters, each being a command. The instruction pointer starts at the first column of the first row (or at the $ character location, if present) and travels to the right, executing each command.

The core SNUSP commands are:

Modular SNUSP adds two more commands:

All other characters are comments.

You can read more about SNUSP and its variants at [2] and [3].

SNUSP2C

The SNUSP specification leaves a number of corner cases underspecified; to clarify snusp2c behavior:

Examples

Here’s a SNUSP program that echoes to stdout whatever it reads from stdin:

cat = !/,+?\#
       \=.-/

snusp2c will compile it into this (or similar) code:

#include <stdio.h>
#include <stdlib.h>
#define LEFT(n)  ptr -= n
#define RIGHT(n) ptr += n
#define INCR(n)  mem[ptr] += n
#define DECR(n)  mem[ptr] -= n
#define READ     mem[ptr] = getc(stdin)
#define WRITE    putc(mem[ptr], stdout)
#define ZERO     (mem[ptr] == 0)
static unsigned char *mem;
static long ptr;
int main() {
    mem = malloc(30000);
    ptr = 0;
r_9_1:
    READ;
    INCR(1);
    if (ZERO) goto r_13_1;
    DECR(1);
    WRITE;
    goto r_9_1;
r_13_1:
    return 0;
}

References

  1. http://hg.tx97.net/snusp2c/

  2. http://esolangs.org/wiki/SNUSP

  3. http://c2.com/cgi/wiki?SnuspLanguage