Closed Absoler closed 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.
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 andfld
is one of its members, and the expression evaluate as the value offld
.However, I found that pycparser seems only parse a complete statement or definition. Is there any way to parse a smaller part?