snusp2c

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

You can read more about SNUSP and it's variants at [2] and [3].

Note that 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