Can explain the execution of php programs, such as: & lt ;? Phpechohelloworld ..;? & Gt; can explain the execution of php programs, such:
Reply content:
1: lexical analyzer and syntax analyzer to obtain the syntax tree.
2: semantic analyzer is used to check whether the code is faulty. for example, 1 + null is not a legal program.
3: php has a table, and php is referenced by php. to solve the circular reference, you need to develop a garbage collector.
4: design a dynamic language instruction set and a stack-based VM (software simulation of this set of command-level CPU). This is the simplest practice and can quickly simulate the running process.
Then you get the result.
Do you want to use the PHP script language in your program or do you really want to be an interpreter?
If it is the former, reuse the existing interpreter.
Otherwise, go to @ vczh's answer. Obtain the token through lexical analysis-> obtain the AST through syntax analysis-> convert the AST to the IR intermediate instruction set-> and then run the IR intermediate instruction set on the vm.
Most interpreted scripting languages follow these steps. In fact, if you just run it, you can generate an AST and recursively traverse the AST. I did this a long time ago in alex1. However, in this case, the performance is poor, and GC is hard to do. A better way is to execute IR on a stack-based vm, as @ vczh said. Stack-based VMs are better than register-based VMs. The simplest method is to use regular expressions to perform brute force matching on the lexical unit, and then construct the abstract syntax tree. then, traverse the node and translate it into the C language syntax. For more information, see
Zend Engine source code ~