in reply to A Perl interpreter written in Perl?

> but that's not what I mean

So what do you mean?

A pure interpreter would

  1. parse
  2. immediately execute

Perl code inside the perl engine.

So how should Perl interpret a map or printf other than using map or printf?

If you are talking about compiling Perl to other engines...

Yes this was attempted, like with perlito

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

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

Replies are listed 'Best First'.
Re^2: A Perl interpreter written in Perl?
by harangzsolt33 (Deacon) on Apr 20, 2025 at 04:44 UTC
    I have never heard of Perlito. Wow. That is some amazing project!!!

    So how should Perl interpret a map or printf other than using map or printf?

    The print function should be called directly, because we cannot reduce it any further, but printf can be, because of the formatting. In fact, JavaScript does not have a builtin printf() function, and I decided to write one. And it's not as easy as it first sounds... The printf function could be broken down into smaller units, or it could be just a call to the builtin printf(). But I don't think this is a big issue, because there are much larger issues. For example, when the perl parser sees a line like this, it has to figure out where to even begin: $J = A() + B() * C(D(F() - 1) - E() / 2 + 1);

    Then where do we stop? The perl parser could use a single variable and assume that that's the computer's memory. So, one could implement a memory manager, garbage collector, reference counters, etc. The problem is that perl is relatively new to me, so I don't even know what parts it has. I'm still at the point where I don't even know how much I don't know about perl. lol

    I wrote a little program in Perl that emulates 64-bit integer math on 32-bit processors. Of course, it's terribly slow, but it's interesting. Writing that thing was as exciting as building an artificial engine made of glass. Of course, such an engine would never be used in a car; it's for show only. But still, it's fun to build!

    I typed this yesterday, but I couldn't send it because the PerlMonks website was down. Even now I have trouble accessing it sometimes. It's super unreliable...

      As already mentioned, there are already alternative parsers available, like PPI

      For running that source exactly like in the original you'd need to compile the source to OP-Code (and namespaces, etc.)

      How this OP-code is interpreted (here the usage of the word is correct), i.e. either from Perl's runtime engine in full speed or by an emulation implemented in Perl, is another question.

      Parser, compiler and runtime interpreter are very different beasts, which IMHO should be approached independently.

      Keep in mind that Perl's compile and runtime are interwoven.

      Every BEGIN-block is injecting a run into compilation, and every eval is triggering a compilation while running.

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