我正在尝试解析cflow的输出,然后将其用于构建控制流的 3D 图。cflow 的输出如下所示:
main() <int main (int argc, char *argv[]) at sort.c:3>:
strcmp()
printf()
malloc()
getline() <char *getline (int max) at sort.c:62>:
isspace()
getchar()
ungetc()
malloc()
qsort()
free()
我正在使用正则表达式来提取函数名和括号——我想得到main()
,strcmp()
等。我的代码如下:
String line = input.nextLine(); // input is a Scanner reading from a file
Pattern p = Pattern.compile("[a-zA-Z0-9_]+\\(\\)"); // the important part
Matcher m = p.matcher(line);
现在,我使用的模式使用 Emacs 的 regexp-builder 模式。然而,当我运行这个程序时,我没有得到任何匹配。我可能只是不了解 Java 的正则表达式函数。
此外,我意识到显而易见的解决方案是不使用 Java……我更喜欢那样,但我将使用 Processing 绘制图形,所以我真的别无选择。