A lightweight, single-pass translator that translates a subset of the Oberon programming language (Small Oberon) into C99.
This project is written in strictly portable C (no structs, no enums, minimal dependencies) and is designed to be easily used for bootstrapping, retro/embedded programming.
- Module System: Supports
MODULE,IMPORT, and symbol exporting (*). - Data Types:
BOOLEAN,CHAR,INTEGER,LONGINT,REAL,LONGREAL,POINTER, and 1DARRAY. - Control Flow:
IF/ELSIF/ELSE,WHILE,REPEAT/UNTIL,BREAK,CONTINUE. - Built-ins:
INC,DEC,SHL,SHR,Adr(address of). - Output: Generates paired
.c(implementation) and.h(header) files. - C Injection: Inject raw C code into .c using
(*{ ... *)directives. - C Injection: Inject raw C code into .h using
(*# ... *)directives.
Compile the translator with any standard C compiler:
gcc -o sobt sobt.cor
wcl sobt.cRun the translator on your Oberon module file:
./sobt MyModule.modThis will produce:
MyModule.cMyModule.h
Input (Test.mod):
MODULE Test;
VAR
val*: INTEGER;
PROCEDURE Add(x: INTEGER);
BEGIN
INC(val, x)
END Add;
BEGIN
val := 0;
Add(10)
END Test.Generated C (Test.c):
#include "Test.h"
int Test_val;
static void Test_Add(int Test_x) {
Test_val += (Test_x);
}
void mod_Test_init() {
Test_val = (0);
Test_Add((10));
}Generated H (Test.h):
#ifndef Test_H
#define Test_H
#include <stdint.h>
extern int Test_val;
extern void mod_Test_init();
#endif- Arrays: Supports single-dimensional arrays only (
ARRAY 10 OF INTEGER). - Records: No support for
RECORDtypes (structs). - Syntax: Strict Oberon subset; expects well-formatted input.
Small Oberon Translator has CC0 1.0 Universal.