Am 07.03.21 um 20:42 schrieb Peter J. Holzer:
The second part is converting a parse tree into code. I am quite sure
that it is possible to devise a formal language to specify the semantics
of any programming language and then to use this to generate the code.
However, I strongly suspect that such a language would be comparable in
expressiveness and ease of use to other programming languages - or in
other worlds it would be just another programming language.

As far as I understand the idea, Leigh (aka Mr Flibble) thinks that he can create a "library" of code translators that translate the individual pieces of the parse tree into some intermediate code, and by specifying these codelets within the grammar the semantics of a language can be fully described.

My argument against this whole thing is that the library would be enormous. He seems to think that big chunks can be reused for different languages, but I don't believe this. A simple example:

int a = -3
unsigned int b = 5;

in C: a < b is false. This is insane but follows from the type casting rules in C.

in Python or any other language with sane integers, -3 < 5 will always be true. For large enough values you must convert them to big integers. CPython simply uses big integers for everything, but that obviously slows down the whole thing. If you want to compile that to fast machine code, you need to do the computation in fixed integers and check for overflow *after every single step*.

And there are myriads of differences. Introducing JavaScript again will bring myriads of differences and so on. The closest thing to such a project I can think of is LLVM. It still requires you to write the actual code generator, but features many intrinsics and libriaries that could be reused and therefore it is easy to add a new language. The approximate value of LLVM is estimated here:

          https://chriscummins.cc/2019/llvm-cost/

It's over 5000 man years of work. There is no way a single developer, regardless how brilliant he may be, can recreate this in his lifetime. Maybe focussed to a single language or two, but not "universal" in any sense.


        Christian
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to