CParser
is a standalone C parser library written in C++, that can be easily embedded in other software projects. The library is contained of reusable set of classes.
See src/cformat.cpp
, include/GenCVisitor.h
and src/GenCVisitor.cpp
for the demo source which uses the C parser library. cformat
is an implementation of a simple C code style formatter.
To clone the project and build the demo, type:
$ git clone https://github.com/jkolek/cparser.git
$ cd cparser
$ make
To run the demo with example C file, type:
$ ./cformat test/example1.c
To use the library you can simply implement your own visitor class by inheriting TreeVisitor
class similarly like GenCVisitor
(used by the cformat
) does. Then with this visitor you can traverse abstract syntax tree generated by parser.
My current objectives are to make the parser to be able to parse preprocessed files
like for example test/cpp_out_example.c
, and to finish the GenCVisitor
implementation.
Thank you for your interest in my project. Any feedback would be highly appreciated!
http://www.quut.com/c/ANSI-C-grammar-l-2011.html
http://www.quut.com/c/ANSI-C-grammar-y.html
https://github.com/antlr/grammars-v4/blob/master/c/C.g4
https://github.com/antlr/grammars-v3/blob/master/ANSI-C/C.g