Parsing and generating C code

Hello,

I have a very small task to solve and want to do it with Julia:
Removing curtain functions from a C code module. The names of the functions to remove are given as string list, there is an input file and an output file.

How would you approach this problem?

Finding the start of a function should be easy, but how to find the end?

Uwe

I guess you could always keep count of how many { and } braces you encounter after the beginning of a function.

Thanks, I will try that.

So there is no library for parsing C/C++ code that I could use?

In Python there is pycparser for example.
https://github.com/eliben/pycparser

You need to ignore comments and solve problems with conditional #ifdef-s as well

There could be also evil #include-s and evil macros with odd numbers of braces

1 Like

http://nbviewer.jupyter.org/github/ihnorton/Clang.jl/blob/master/examples/parsing_c_with_clangjl/notebook.ipynb

Thanks for the link!

One more question: Any idea to obtain the line number of a function, using Clang.jl?

https://clang.llvm.org/doxygen/group__CINDEX__CURSOR__SOURCE.html