Skip to content

A C parser built in and for PHP (yes, it's a bad idea)...

License

Notifications You must be signed in to change notification settings

Fantom409/php-c-parser

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHPCParser

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 workting that is...)...

Generating AST from clang

$ clang -cc1 -ast-dump test.c

About

A C parser built in and for PHP (yes, it's a bad idea)...

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 89.9%
  • Yacc 9.9%
  • C 0.2%