Re: c header file parser
- Posted by ghaberek (admin) Oct 13, 2015
- 1703 views
Parsing C is hard. A lot of the syntax in C depends on its context.
typedef int foo; foo * bar; // 'bar' is a pointer to a variable of type 'foo' int foo, baz, bar; baz = foo * bar; // baz equals foo times bar
So the expression foo * bar changes meaning based on whether foo is a type or a variable.
It's also really hard to parse macros correctly. Static macros, which are typically used as constants in C, are pretty simple to translate. But some macros merely exist and contain no value, and those should translate to a with define statement for use with ifdef. There are also macro functions, which, among other factors, can get horribly complicated because of the way they can concatenate and "stringify" their parameter names.
-Greg