DEV Community

RobEst
RobEst

Posted on

I built a compiler for my own language. Took way longer than expected, but it works

Started this like a month ago, wanted to understand how compilers actually work under the hood. Picked LLVM because everyone says it's the way to go. Did not expect it to be this painful.
The language is called tTek. The idea is instead of writing event loops you just declare rules — describe when something should happen and it runs:

mem temperature: i32 = 22;
mem ac_on: i32 = 0;

rule too_hot when temperature > 25 && ac_on == 0 {
ac_on = 1;
print("AC on\n");
}

rule shutdown when temperature > 40 {
halt;
}

Spent way too long on the linker throwing undefined reference to WinMain for no obvious reason, object files coming out 0 bytes, segfaults in codegen that had no error message at all. Good times.
Eventually got it working. Compiles to a real native exe through LLVM, no C in between. Functions, if/else, while, sleep, halt — all working.
Repo: https://github.com/RobEst0906/tTek-language
Still a lot missing (timers, preprocessor, proper pointer support) but the core works. Curious what people think of the rule-based approach, and also what I probably did wrong in the compiler lol.

Top comments (1)

Collapse
 
alexrosito67 profile image
Alex Rosito

Writing your own compiler from scratch is probably the most humbling and rewarding experience in software engineering. The title hits close to home—it always takes way longer than expected because the edge cases in semantic analysis and AST generation are a brutal reality check.

There's a massive difference between reading about language design and actually implementing symbol tables, handling scope validation, and emitting clean bytecode or assembly without blowing up the memory.

Kudos for pushing through and getting it to work. It’s posts like this that remind us why clean, low-level architecture matters. Are you planning to target a custom VM or emit native machine code next?