The parse tree is program tokens stored in a structure that shows their nesting (which arguments belong to which function calls, which operators are inside which cycles, etc.), while bytecode is program code, Converted to binary notation for faster execution on a virtual machine. For example, if you had the following code in an imaginary language:
loop i from 1 to 10 { print i }
The parsing tree might look like this:
loop variable i integer 1 integer 10 block print variable i
Meanwhile, the bytecode in source and symbolic form compiled for the stack-oriented virtual machine might look like this:
0x01 0x01 PUSH 1 START: 0x02 DUP 0x03 PRINT 0x05 INCREMENT 0x02 DUP 0x01 0x0a PUSH 10 0x04 LESSTHAN 0x06 0xf9 JUMPCOND START
When compiling a program, you must first analyze the source code (usually by creating a parse tree), and then convert it to byte code. Itβs easier to skip the second step and execute directly from the parse tree. In addition, if the syntax of the language is very hairy (for example, it allows you to change the code), then creating byte code becomes more complicated. If a function of type eval exists to execute any code, the entire compiler must be distributed with the application to use the virtual machine for such code. Enabling only the parser is easier.
Perl 6, the next version of perl, assumes that code is compiled into bytecode and runs on a Parrot virtual machine. It is expected to improve performance. Bytecode is simple enough to compile additional processor instructions (this is called a JIT compiler) to approximate the speed of compiled languages ββsuch as C.
jjrv
source share