4 ms·
It's not bytecode! There is no bytecode involved at all. It's just a representation of the source program text. For example (in some pseudo-code): a = x + 1
by gdp 17y ago
It's not bytecode! There is no bytecode involved at all. It's just a representation of the source program text.
For example (in some pseudo-code):
a = x + 10
Perl 5 builds a tree from this (e.g. Assign(a, Add(x, 10))) and then executes it. Even the traversal of the tree proceeds according to the results of executing the program up to that point.
If we were to take the tree I generated above, we could get the exact same program out of it. I agree that this would be difficult with Perl - not because the parse tree is substantially different from the program text, but rather because it is ambiguous.
We could also target some arbitrary language. This is not the case in Perl, because it can't. The tree has absolutely no meaning other than that given to it through execution. It's not even an abstract syntax tree - it's just a parse tree! The semantics of the tree are exactly the same as the Perl code from which the tree was derived. And I don't mean "semantically equivalent", I mean, "identical by definition", because the source only has meaning because the tree is executed.
In a compiler setting, we can take an arbitrary (valid) program and give its meaning in terms of the target language. An abstract syntax tree has its own semantics, into which the original program text (or parse tree) is translated. The AST is given a semantics by a code generator, which translates constructs in the AST into constructs in the target language (which has yet another set of semantics).
- calcnerd256 17y agoSomeone should rewrite Perl in Lisp.
- phaylon 17y agoI'm sorry if I was unclear, but I still don't see any problem with this being called a compilation of one format into another.
- scott_s 17y agogdp's objection to calling this compilation, which I share, is that there is only one form.
- phaylon 17y agoNo, there isn't. There is the source, and there is the prepared and executed optree. The building of this is in Perl called the compile time phase. Which makes sense to me. I can't see how the source file and the parsed optree can be the same form. They do the same things, yes. But most source code and compiled forms have that in common.
- scott_s 17y agoAs I understand it, the "executed optree" is just the parse tree. The building of that tree is the lexing and parsing phase, not compilation. The parse tree is never translated into another form - neither an abstract syntax tree, nor another language with the same semantics. http://en.wikipedia.org/wiki/Parse_tree http://en.wikipedia.org/wiki/Parse_tree http://en.wikipedia.org/wiki/Abstract_syntax_tree http://en.wikipedia.org/wiki/Abstract_syntax_tree If the parse tree is never translated to another form, then I think it's fair to say Perl is interpreted, not compiled.
- pbiggar 17y agoWords mean what they mean. You could call any interpreter a compiler if you twisted it, and you'd sort of be right, but you'd be a lot more wrong. Same in this instance. Its an interpreter! And yes, it sort of does a job close enough to compilation that you wouldn't _really_ be incorrect calling it a compiler, but its not a compiler dammit!!
- 17y ago