Skip to content

DosWorld/sobt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Small Oberon to C99 Translator

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.

Features

  • Module System: Supports MODULE, IMPORT, and symbol exporting (*).
  • Data Types: BOOLEAN, CHAR, INTEGER, LONGINT, REAL, LONGREAL, POINTER, and 1D ARRAY.
  • 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.

Build

Compile the translator with any standard C compiler:

gcc -o sobt sobt.c

or

wcl sobt.c

Usage

Run the translator on your Oberon module file:

./sobt MyModule.mod

This will produce:

  • MyModule.c
  • MyModule.h

Example

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

Limitations

  • Arrays: Supports single-dimensional arrays only (ARRAY 10 OF INTEGER).
  • Records: No support for RECORD types (structs).
  • Syntax: Strict Oberon subset; expects well-formatted input.

License

Small Oberon Translator has CC0 1.0 Universal.

Releases

No releases published

Packages

No packages published