ircmaxell / php-c-parser
Parse C when using PHP
Installs: 9 581
Dependents: 3
Suggesters: 0
Security: 0
Stars: 40
Watchers: 6
Forks: 7
Open Issues: 4
Requires
- php: >=7.4
Requires (Dev)
- ircmaxell/php-yacc: dev-master
- phpunit/phpunit: ^8.0
This package is auto-updated.
Last update: 2024-10-14 18:24:12 UTC
README
This is a library to parse C code into an AST. Using PHP.
Yes, this is an extraordinarily bad idea...
Example
$parser = new PHPCParser\CParser; $ast = $parser->parse('path/to/file');
Note that pre-processor directives are all correctly resolved.
If you need to set a pre-processor define, you can use a context;
$parser = new PHPCParser\CParser; $context = new PHPCParser\Context; // #define A 42 $context->defineInt('A', 42); // #define B "testing" $context->defineString('B', "testing"); // #define C testing $context->defineIdentifier('C', 'testing'); // etc... $ast = $parser->parse('path/to/file', $context);
And that's all there is to it (until it is working that is...)...
Generating AST from clang
$ clang -cc1 -ast-dump test.c