简体   繁体   中英

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. 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.

You can use the LEX and the YACC tools for defining the grammar and for parsing the string. Lex and Yacc can read the source program and discover its structure.

The task of discovering the source structure again is decomposed into subtasks:

  • Split the source file into tokens (Lex).
  • Find the hierarchical structure of the program (Yacc).

Lex helps write programs whose control flow is directed by instances of regular expressions in the input stream. 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. 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. 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 .

Yacc provides a general tool for describing the input to a computer program. The Yacc user specifies the structures of his input, together with code to be invoked as each such structure is recognized. Yacc turns such a specification into a subroutine that han- dles the input process; 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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