The php-ast repository is a PHP extension that exposes the internal Abstract Syntax Tree (AST) used by PHP 7 and 8. It provides functions to parse PHP code into an inspectable AST structure that mirrors PHP's internal compiler representation, enabling static analysis, code transformation, refactoring tools, and other metaprogramming tasks. Unlike pure-PHP AST parsers, this extension leverages PHP's own parser for maximum performance and accuracy. The extension implements a sophisticated versioning system to maintain compatibility across PHP releases. Rather than breaking when PHP introduces new language features, it defines AST versions (currently 50 through 120) and can represent newer constructs using older node types when necessary for backward compatibility. This allows developers to write analysis tools that work across multiple PHP versions without constantly updating for each new release. Key architectural components include the C-based extension core that interfaces with Zend's parser, a comprehensive metadata system describing node kinds and their associated flags, and utility functions for AST inspection. The extension handles the full PHP grammar including recent additions like attributes, match expressions, nullsafe operators, constructor property promotion, and enum support. In production use, this extension serves as the foundation for many PHP static analysis tools, enabling them to operate with near-native performance by avoiding the overhead of pure-PHP parsing while providing a stable, versioned interface to PHP's AST structure.
Spoon is a comprehensive, open-source Java library for source code analysis, transformation, and generation. Developed at INRIA, it provides a complete AST metamodel covering all modern Java constructs (up to Java 25), along with powerful APIs for pattern matching, template-based code generation, static dataflow analysis (with Z3 integration), control flow graph construction, Javadoc parsing, and decompilation. The architecture is modular with submodules for specific tasks (e.g., spoon-dataflow, spoon-smpl for semantic patches, spoon-visualisation). Spoon is used both as a research platform for program analysis and as a practical tool for building custom code transformations, linters, and refactoring tools. The codebase demonstrates high engineering quality with clean separation of interfaces and implementations, extensive use of visitor and factory patterns, and a sophisticated query API.