eliben / pycparser

:snake: Complete C99 parser in pure Python
Other
3.21k stars 612 forks source link

is it possible to parse in-complete C code snippet? #508

Closed Absoler closed 1 year ago

Absoler commented 1 year ago

for example, I want to analyze a valid independent C expression such as "a->fld", and I hope to get the information that a is a struct of union variable and fld is one of its members, and the expression evaluate as the value of fld.

However, I found that pycparser seems only parse a complete statement or definition. Is there any way to parse a smaller part?

eliben commented 1 year ago

pycparser wasn't really designed for this - it was designed for parsing complete top-level nodes like declarations and function definitions.

It shouldn't be too hard to wrap a piece of code with void foo() { ... <code here> ...}, but the code still has to be reasonably self-contained. I know people hacked together such things before, so I suggest you try.