Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^3: A Perl interpreter written in Perl?

by bliako (Abbot)
on Apr 16, 2025 at 15:17 UTC ( [id://11164740]=note: print w/replies, xml ) Need Help??


in reply to Re^2: A Perl interpreter written in Perl?
in thread A Perl interpreter written in Perl?

A compiler can be written in a "slow" language and still be producing fast/efficient binaries, slowly. Whereas, with an interpreter things are a bit different because the speed of the running script is determined by both the script's efficiency and the interpreter's efficiency. You can get rid of the compiler once your program is compiled but you can never get rid of the interpreter, you need it every time and you suffer its inefficiencies every time you run your script. I am not sure whether Perl is strictly interpreting the script or it compiles (parts of?) it somehow. For this reason, it is logical to write your compiler in as high-level language there is available/you are familiar with. And write your interpreter in as "fast" a language there is. C IMO was the sweet spot for speed/efficiency/high-level. Perhaps not any more. But it works well for the Perl interpreter, it is fast.

I believe a C compiler starts as an assembly program or as a program in another language preceding C for which there is a compiler available. Then, once you have the C compiler binary, you write the compiler in C and compile that. And then you don't depend on other languages in order to maintain/evolve your C compiler, assuming you already have a C compiler binary. If all the C compiler binaries of the world disappear one day (here is a grand SciFi scenario!) perhaps because antivirii gone mad, then we need to start from assembly again. Or modula-2 or whatever language for which there is a compiler available. The higher level the easier it would be.

A compiler also depends on a parser to parse the input program. And that can get really complex if in assembly (in fact that's how Yacc was developed). But once you have a basic C compiler then you can write the parser (aka compiler-compiler) in C and compile that. The benefit being the higher level language will be helpful in adding more features/complexity to your parser. In fact a parser acts as a rudimentary compiler (omitting the efficiency heuristics a fullfledge modern compiler has) therefore it can be said that "a compiler is written in its "grammar"", which the parser parses, as opposed to "a compiler is written in C", for example.

I do not know what other reasons there are for writing a C compiler in C. But do not discount these: it would be a good test for the language and the compiler program. Plus, the whole exercise has a turing-complete kind of sound to it. Oh, and because Computer Science curriculum was really nerdy at some point in time and the students loved it immensely, despite the famous book cover being a red Godzilla (dinosaur?).

Of course all the above do not apply for Python. For Python there must be one and only one reason: the perversity of a sect of Conformists.

  • Comment on Re^3: A Perl interpreter written in Perl?

Replies are listed 'Best First'.
Re^4: A Perl interpreter written in Perl?
by LanX (Saint) on Apr 16, 2025 at 18:05 UTC
    I'm not aware of any real interpreter languages anymore. That's a distinction from the 80s or 90s, reality evolved faster than terminology.¹

    Perl has a compiler creating optimized op-codes, you can even precompile .pl to .plc code.

    The engine running this code is roughly kind of like the JVM, but not as flexible because of many idiosyncracies.

    The real difference nowadays is not interpreted vs compiled, but dynamic typing vs static typing.

    Compare JavaScript vs TypeScript.²

    In this light, it's hard to answer the OP because I don't know what he thinks an interpreter does.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery

    ¹) Microsoft BASIC was interpreted, the source for almost all BASIC dialects back then. But even here the source code was normalized internally to 2 letter mnemonics to optimize space and speed.

    ²) That's a fair comparison, since JS was heavily influenced by Perl.

      I'm not aware of any real interpreter languages anymore.

      Pretty much all of the shells (bash, ash, zsh, etc.) are still real interpreters, AFAIAA.


      🦛

        Yes, I remember Emacs Lisp also having this fine differences depending on interpretation vs compilation.

        So these very old languages still hanging around are candidates for real interpretation.

        Update

        Found this interesting comparison between bash and perl execution on SO

        is-bash-compiled-or-interpreted

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        see Wikisyntax for the Monastery

        Update

        Maybe I was biased to consider bash etc as not real languages, because the idea of writing apps with several thousand LOCs gives me shivers.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11164740]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2025-07-13 11:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.