Translating the Translator with the Translated Translator
For some reason, compiler writers and computer language developers
以下正文同步自 Hacker News 最新,版权归原站所有,已转换为易读排版。
; }
Pep and Nom
home | blog | all blog posts
7 feb 2025
Things that compile themselves
For some reason, compiler writers and computer language developers take considerable pleasure in announcing, as soon as possible, that their language is now, officially, self hosting . There was a time when this idea was considered strange and exciting, so much so that somebody like Brian Kernighan (a c and Unix luminary) wrote a paper about it. These days its considered a fairly humdrum idea.
I think something similar can be said about the idea of “recursion” in programs; that is, a function or procedure which calls itself. For a brief period, programmers and language designers thought that this idea could provide some kind of “transcendental” self-referentiality. They don't anymore.
In light of all this, I don't expect any wild excitement (also because probably no-one reads this blog) when I say that the Nom language is self-hosting. That is to say, that the compiler for nom is written in nom. To generate a new compiler, I can just write:
pep -f compile.pss compile.pss > asm.new.pp
and then copy asm.new.pp to asm.pp It's probably a good idea to check that asm.new.pp actually works as hoped before you do that.
But Nom is capable of even more wildly confusing self-referentiality. That is because not just the compiler can compile itself, but many other Nom scripts can also compile/transpile/translate themselves (choose whichever word you prefer). So all the Nom scripts in the translation folder can compile themselves, and this actually has a practical purpose.
create a java program that can compile Nom scripts to java
pep -f translate.java.pss translate.java.pss > Machine.java javac Machine.java
So, in the code above the java nom “translator” has been used to translate the translator to java! I don't blame you if you feel slightly dizzy trying to think about that. But it works. Effectively we now have a Pep/Nom system which does not interpret but compiles (via the Java Virtual Machine).
now use this java compiler to compile a expression parser script to java
cat eg/exp.tolisp.pss | java Machine > Machine.java javac Machine.java echo
正文由 探How 从来源站点 RSS 同步,内容未经改写;遇到排版缺失或需要图片、视频时请以原文为准。