my own programming language that transpiles to C, written in C99
  • C 98.7%
  • Shell 0.6%
  • Dockerfile 0.4%
  • Makefile 0.3%
Find a file
2026-02-15 21:27:12 +01:00
src change: use DO instead of THEN for while loops 2026-02-15 21:27:12 +01:00
tests change: use DO instead of THEN for while loops 2026-02-15 21:27:12 +01:00
.gitignore chore: add leak check script 2026-02-15 20:21:20 +01:00
Dockerfile chore: add leak check script 2026-02-15 20:21:20 +01:00
leak_check.sh change: use DO instead of THEN for while loops 2026-02-15 21:27:12 +01:00
Makefile chore: rename transpiler binary to c4t 2026-02-15 19:29:23 +01:00
README.md feat: implement while-statement parsing 2026-02-15 21:14:13 +01:00

C4

A minimal programming language that transpiles to C. Hobby project for learning compiler design and is not intended to replace C.

Current Features

Working:

  • Integer variables with := assignment
  • Arithmetic operators: +, -, *, / with proper precedence
  • Comparison operators: <, >, ==, !=, <=, >=
  • Parentheses for grouping
  • print() statement
  • if/else statements
  • while statements
  • Full lexer → parser → code generator pipeline

Example:

x := 5 + 10;
y := x * 2;
result := y > 15;
print(result);

Generates valid C code, compiles, and runs.

What's Missing

  • Functions
  • Types beyond integers
  • Strings
  • Custom output names

Build and run

make
./c4t tests/comparisons.c4
./program

Running memory leak tests

To do this, you must have podman installed on your machine.

# 1. build the image
podman build -t c4t-dev .

# 2. run the script
./leak_check.sh

## or do it yourself:
podman run --rm -it \
  -v "$PWD:/code" \
  -w /code \
  c4t-dev \
  bash -c "
    make &&
    valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes ./c4t tests/numbers.c4
  "