解析Java源代码code源代码、Java、code

2023-09-11 00:15:36 作者:我有故事你有酒么

有人问我开发一个软件,它应该能够创建流程图/输入Java源代码code控制流。于是我开始研究它,抵达以下解决方案:

I am asked to develop a software which should be able to create Flow chart/ Control Flow of the input Java source code. So I started researching on it and arrived at following solutions:

要创建流程图/控制流我必须承认控制在给定的源$ C ​​$ C发现在我已经认识到两种方式语句和函数调用:

To create flow chart/control flow I have to recognize controlling statements and function calls made in the given source code Now I have two ways of recognizing:

在写我自己的语法(一个复杂的解决方案,我认为)分析源$ C ​​$ C。我想用ANTLR的这一点。 在读取输入源$ C ​​$ C文件为文本,并搜索特定的模式(而有可能成为效率低下)

我说得对吗?还是我失去了一些东西很基本的,简单的?哪种方法将需要更少的时间,有效地做这项工作?在这方面任何其他建议将受到欢迎了。任何其他有效的方法将帮助,因为输入源$ C ​​$ C可能跨越多个文件,可以是相当复杂的。

Am I right here? Or I am missing something very fundamental and simple? Which approach would take less time and do the work efficiently? Any other suggestions in this regard will be welcome too. Any other efficient approach would help because the input source code may span multiple files and can be fairly complex.

我在.NET语言很好,但是这是在Java中我的第一个大项目。我有编译器设计的基本知识,所以写的语法不应该是不可能的,我。

I am good in .NET languages but this is my first big project in Java. I have basic knowledge of Compiler Design so writing grammars should not be impossible for me.

抱歉,如果我是不清楚。请询问任何澄清。

Sorry If I am being unclear. Please ask for any clarifications.

推荐答案

我会与 ANTLR的去使用现有的Java语法: https://github.com/antlr/grammars-v4

I'd go with Antlr and use an existing Java grammar: https://github.com/antlr/grammars-v4