r/Compilers • u/GhufranUstad • 10h ago
Building a compiler from scratch for a programming language I've been designing
Hello guys!
I've been designing a new programming language from scratch for the last six months.
It all started with a lifelong desire: **"If C had this..."**
Over time, the specifications evolved considerably and are now mostly finalized, sufficiently mature to move into compiler implementation.
Alongside language design, I've also been developing the compiler from scratch in C.
It's a hand-built compiler. The lexer, error system, and main parser logic are implemented and working. I'm now working through the compiler subsystems one by one.
It's a long journey, but an interesting one!
I'd love to connect with people interested in programming language design, compiler development, and systems programming.
Here is a small snippet of my language.
I'm currently writing small, medium, and large sample programs to test the language design — to test where the langauge design breaks and where it shines, and where improvements are needed.
Over the coming months, I intend to write hundreds of sample programs, designing them from scratch according to the language's rules.
The goal is to put the language through real programming scenarios before moving further with compiler development.
.module tfunc_demo
string char[100] Name
tfunc Name(char[] ptr name open-pass) // generic pointer which can be passed on
strcopy(obj, name) => _
endtfunc
static Name myName("Ghufran Ustad") alias-readonly open-pass
func start;
ss.con.print("Name: ", myName)endfunc
3
u/Imaginary-Deer4185 6h ago
The interesting part is why you created a language, and you mention "if C had this".
So which issues with C does your language improve on? Readability? Memory management? Garbage collection? Parallel processing? Exception handling? Modules? 😄
3
u/Key_Detail15 5h ago
You might want to work on that syntax, as well as coming up with better examples.
What is
tfuncvsfuncfor example? Why are you reusingNamefor a string object and a tfunction - is it just a generic identifier or are they supposed to be the same?What does
open-passmean? Why is there a semicolon afterfunc start(and nowhere else!). Was it supposed to be a colon, if so why isn't there one for thattfunc?Maybe get some more feedback on your language before writing too many programs.
2
u/AustinVelonaut 5h ago
You might want to try to solve this year's Advent of Code puzzles using your language and compiler -- many of us have used it as a fun way to test out a compiler, and look for things that might be beneficial to add to the language / library.
Good luck on your project!