Climbing the Abstract Syntax Tree
summary
PHP 7 replaces direct parser-to-opcode generation with an AST that decouples parser and compiler, cutting the compilation step by about 10–15% in measurements and enabling source manipulation. Examples show a toy compiler: a regex lexer, shunting‑yard to RPN, AST builder and tiny VM that executes correctly. Practical tools demonstrated include the php‑ast extension, PHP‑Parser (pure PHP) and BetterReflection for monkey‑patching and static analysis; the approach works and is already underpinning tools like PHPStan and Psalm.
AI-written summary · about
