my own programming language that transpiles to C, written in C99
- C 98.7%
- Shell 0.6%
- Dockerfile 0.4%
- Makefile 0.3%
|
|
||
|---|---|---|
| src | ||
| tests | ||
| .gitignore | ||
| Dockerfile | ||
| leak_check.sh | ||
| Makefile | ||
| README.md | ||
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()statementif/elsestatementswhilestatements- 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
"