the axiom's avatar
the axiom 2 weeks ago
people who create languages are not normal it would make more sense to write your compiler in another language and leave it like that, I don't see why not

Replies (3)

that's because you never read a textbook on compiler design and construction. i did, when i was like, idk, 13 or something, i should try to remember exactly. borrowed a book using my mother's university library card. never got arround to it quite yet, but it's on my list to build a slimmed down version of Go, which i'm working title "moxie" as in, the soda with gentian based flavor sold in USA) i've specced up the revised grammar, and mostly modified the yaegi go interpreter to run i tried to build an actual binary compiler first, but that proved to be very complex and claude couldn't do it. but the interpreter was relatively easy, and once implemented, can then allow me to write the compiler in moxie. the standard technique is to make a bootstrap compiler, which only has the parts implemented required for the compiler to work. then, with that compiler, you refactor it a bit so that you use the full version where you previously used more clumsy constructions to avoid making bootstrap 2 compiler difficult to build, and then you have the final compiler. i'm using the interpreter to do the bootstrap 1, and because it's just a small set of changes, and mostly removals, i will be at stage two, the second bootstrap, already, effectively, and with that write the full compiler, and add the execution environment and ABI targets to the code generator. Go has an extensive toolkit for building tools that edit go code, which makes up a large chunk of what the compiler actually has in it. the tokeniser, which identifies all the reserved words, operators, etc, and generates a linear list of tokens. then there is an AST generator (abstract syntax tree) which produces the more complex, tree structured, syntax and grammar containing information, types, comment blocks, etc, and then after that, the compiler feeds the AST into the code generator, which can either generate another programming language (less common) or directly generate binary code for the processor. i hope you enjoyed that explanation, about why language compilers are usually written in the language they compile. once you have one, you can then use it to build updated versions with bugfixes and add/remove language features.