I'm using pycparser to parse some C code. Specifically, I need certain portions of the code, included in pycparser are some visitors like visit_If to visit "If" sections of the code. However, I'm having problem visiting 'else' part of an if-else statement.
Example 1:
if (x == 0)
{
// some statements
}
else
{
// some statements -> I only need all codes under else
}
Example 2:
if (x == 0)
// a statement
else
// a statement -> I only need all codes under else
How is this possible in pycparser?
The
If
node has aniffalse
child node which is theelse
clause from the original code. For example, see the C code generator (part ofpycparser
):This is a good example of visiting an
If
node and accessing all its child nodes.