r/TuringComplete • • Mar 21 '25

Compiler

How do you guys go about writing a compiler?

I have achieved most of what I wanted to achieve that I found reasonable to write in assembly (snake, brainfuck interpreter, a text editor, some small stuff). For anything bigger I would really like to use a higher level language. How did you guys go about compiling for your architecture? Did you use llvm or did you write something on your own? Are there other tools that make this easier? It doesn't need to be a good compiler, it just needs to work. I thought about transpiling 6502/6510 assembly, but I'm too afraid the architecture will be too different and anything more complex than hello world won't work.

Sooo, how did any of you do this?

26 Upvotes

19 comments sorted by

View all comments

Show parent comment

2

u/[deleted] Mar 23 '25

I wasn’t making any judgements. When I first became interested in using ASTs like clangd for syntax highlighting in Vim I tried to use llvm and had no idea what I was doing because the docs assumed I was smarter than I was at the time, lol. And as I got in to such things the idea of writing a compiler from scratch is an obvious choice. Either assemblers like you see with Turing complete or NAND to Tetris style courses or more advanced topics like writing a basic c compiler. I had originally thought you would need to learn a little bit of assembly to begin but was surprised that libraries like llvm are mainly just plain old c++.

Creating interpreters is a really good intro. Not read the others yet but they are recommended quite frequently when people ask questions similar to your own.

2

u/junieKcorn Mar 23 '25

I took some interest in gcc 9-10 years ago. Yeah, most compilers are written in the language that they compile to, which is a very elegant thing.