This is a compiler from a subset of C to highly unoptimized Brainfuck. There are no support for dynamic allocations, pointers and global variables. Everything else can be derived from the present:
-
Types:
int-- the size of bf machine cell, e.g. 8 bitsT[N]-- arrays of typeTwith statically known sizeNstruct { T f; ... }-- custom structs
Types can be defined as usual with
typedef struct { .. } S; -
Functions:
T func(T arg, ...);-- declarationT func(T arg, ...) { .. }-- definition
-
Statements:
T x = expr-- local variables declarationsx = expr-- assignmentsif (expr) { .. } else { .. }-- conditionalswhile (expr) { .. }-- loop construcionsfunc(expr, ...)-- function calls
-
Expressions
x-- refering to local variables and argumentsexpr.field-- accessing structures' fieldsx[expr]-- indexing arrays with custom expressionsfunc(expr, ...)-- calling functionsexpr + expr,expr - expr-- wrapping on overvflow addition and subtraction
All features are presented in example implementation of Rule 110 (Run compiled version).