简体   繁体   English

如何获取代码中使用的函数的名称

[英]How to get names of function use in code

I get body of C++ method as String and want to get list of all methods that were used in this code. 我将C ++方法的主体作为String获取,并希望获取此代码中使用的所有方法的列表。 What tool will be best to do such parsing? 哪种工具最适合进行此类解析?

It must support all situation: 它必须支持所有情况:

opSomeMethod();
someObject.someMethod();
someObject->someMethod();

Best if it will be in Java but it could be little c++ program that work from console. 最好是用Java编写,但它可能是可以从控制台运行的小型c ++程序。

You can use the LEX and the YACC tools for defining the grammar and for parsing the string. 您可以使用LEX和YACC工具来定义语法和解析字符串。 Lex and Yacc can read the source program and discover its structure. Lex和Yacc可以阅读源程序并发现其结构。

The task of discovering the source structure again is decomposed into subtasks: 再次发现源结构的任务被分解为子任务:

  • Split the source file into tokens (Lex). 将源文件拆分为令牌(Lex)。
  • Find the hierarchical structure of the program (Yacc). 查找程序的层次结构(Yacc)。

Lex helps write programs whose control flow is directed by instances of regular expressions in the input stream. Lex帮助编写程序,其控制流由输入流中的正则表达式实例控制。 It is well suited for editor-script type transformations and for segmenting input in preparation for a parsing routine. 它非常适用于编辑器脚本类型的转换以及分段输入以准备解析例程。 Lex source is a table of regular expressions and corresponding program fragments. Lex源是一个正则表达式和相应程序片段的表。 The table is translated to a program which reads an input stream, copying it to an output stream and partitioning the input into strings which match the given expressions. 该表被转换为程序,该程序读取输入流,将其复制到输出流,然后将输入划分为与给定表达式匹配的字符串。 As each such string is recognized the corresponding program fragment is executed. 识别出每个这样的字符串后,就会执行相应的程序片段。 The recognition of the expressions is performed by a deterministic finite automaton generated by Lex. 表达式的识别是由Lex生成的确定性有限自动机执行的。 The program fragments written by the user are executed in the order in which the corresponding regular expressions occur in the input stream. 由用户编写的程序片段按在输入流中出现相应正则表达式的顺序执行。

See the online manual for LEX for more details . 有关更多详细信息,请参见LEX的在线手册

Yacc provides a general tool for describing the input to a computer program. Yacc提供了一种通用工具,用于描述计算机程序的输入。 The Yacc user specifies the structures of his input, together with code to be invoked as each such structure is recognized. Yacc用户指定其输入的结构,以及在识别每个这样的结构时要调用的代码。 Yacc turns such a specification into a subroutine that han- dles the input process; Yacc将这样的规范转换为处理输入过程的子例程。 frequently, it is convenient and appropriate to have most of the flow of control in the user's application handled by this subroutine. 通常,由该子例程处理用户应用程序中的大多数控制流是方便且适当的。

See the online manual for YACC for more details . 有关更多详细信息,请参见YACC在线手册

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM