Skip to content

jkolek/cparser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CParser

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.

Demo usage of the library

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

How to use the library

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.

Current work

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!

References

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