How can I parse a syntactically correct C file containing a single function but with non-defined types? The file is automatically indented (4 spaces) using this service with brackets below each block keyword, i.e. something like
if ( condition1 )
{
func1( int hi );
unktype foo;
do
{
if ( condition2 )
goto LABEL_1;
}
while ( condition3 );
}
else
{
float a = bar(baz, 0);
LABEL_1:
int foobar = (int)a;
}
The first line is the prototype, the second is a "{". All the lines end with \n. The last line is simply "}\n" There are lots of many-to-one gotos, and the labels are often out of their block (awful, I know :D ) I only care about structural information, i.e. blocks and statement types. Here what I'd like to get (when printed, indent added for clarity):
[If(condition = [condition1],
bodytrue = ["func1( int hi );",
"unktype foo;"
DoWhile(condition = [condition3],
body = [
SingleLineIf(condition = [condition2],
bodytrue =["goto LABEL_1;"],
bodyelse = []
)
]
)
]
bodyelse = ["float a = bar(baz, 0);",
"int foobar = (int)a;"
]
)]
with condition1, condition2 and condition 3 strings. Other constructs would work the same.
The labels can be discarded. I also need to include blocks not associated with any special statement, like Block([...]).
Standard C language Python parsers dond't work (for instance pycparser gives syntax error) because of the unknown types
(a)&ba bitwise operation or a pointer cast? Who knows!