Is Parsing C header file using ANTLR possible?
I am new to compiler business and using ANTLR grammar (open source) to parse C source files th开发者_StackOverflowat have many external header files i.e. include files and library files etc.
What is the way the define grammar for these header files? Is there some way to parse these include files as simple source files?
Is it possible to integrate all these source +include files into a package and parse it using ANTLR or other C parser (JavaCC).
Waiting for your kind suggestions.
It won't be easy to implement a full chain of a preprocessor and a parser for C. But you can reuse the existing preprocessor (e.g., gcc -E
) and an existing parser (clang -Xclang -ast-print-xml
or gcc-xml are both good choices) and then parse a simple XML output instead.
精彩评论