我正在尝试使用pycparser解析c文件并找到switch语句 我使用https://github.com/eliben/pycparser/blob/master/examples/explore_ast.py这个链接生成了ast。 然后使用n=len(ast.ext)我找到了从ast生成的ext的长度。 现在我必须从ast中找到switch语句 我试过了 if re.findall(r'(开关(\s*),ast.ext) 并匹配正则表达式以查找开关大小写,但它没有发生。 由于我对pycparser完全陌生,对此一无所知,因此如何进行此操作
无法在pycparser AST上运行regexp匹配
pycparser存储库中有多个示例可以帮助您:
explore_ast.py
,您已经看到了它可以让您使用AST并探索其节点dump_ast.py
演示如何转储整个AST并查看代码中有哪些节点最后,
func_calls.py
演示了如何遍历AST以查找特定类型的节点:在本例中
FuncCall
节点,但您需要切换节点,因此您将创建一个名为visit_Switch
的方法,访问者将找到所有Switch
节点相关问题 更多 >
编程相关推荐