在任何C文件中查找功能名称的问题 [英] Problem of finding funtion names in any C file

查看:59
本文介绍了在任何C文件中查找功能名称的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一种方法来解析出现在几个
C文件中的所有函数名。

当解析逻辑在文件中找到函数名时,它应打印

函数名称,行号和文件中找到函数




应该采用什么方法我跟着解决了这个问题?

gcc编译器中是否有打印出这个

信息的选项?

I want a way to parse out all function names that appear in a couple of
C files.
When the parsing logic finds a function name in a file, it should print
out the Function name, line number and file in which the Function was
found.

What approach should i follow to tackle this problem ?
Is there any option in the gcc compiler that prints out this
information ?

推荐答案

athiane写道:
athiane wrote:
我想要一种方法来解析出现在几个C文件中的所有函数名。
当解析逻辑在文件中找到函数名时,它应该打印出找到
函数的函数名,行号和文件。

应该采用什么方法我跟着解决了这个问题?
gcc编译器中是否有打印出这个
信息的选项?
I want a way to parse out all function names that appear in a couple
of C files.
When the parsing logic finds a function name in a file, it should
print out the Function name, line number and file in which the
Function was found.

What approach should i follow to tackle this problem ?
Is there any option in the gcc compiler that prints out this
information ?




D不知道你的意思''解析'' - 在控制台中显示,提供

输出/代码''家庭作业''?

-

==============

*不是学生*

======= =======



Don''t know what you mean by ''parse out'' - display in a console, provide
output/code for ''homework''?
--
==============
*Not a pedant*
==============


" pemo" <我们*********** @ gmail.com>写道:
"pemo" <us***********@gmail.com> writes:
athiane写道:
athiane wrote:
我想要一种解析出现在几个C文件中的所有函数名的方法。当解析逻辑在文件中找到一个函数名时,它应该打印出函数名,行号和找到
函数的文件。

什么我应该采取什么方法来解决这个问题?
gcc编译器中是否有打印出这个
信息的选项?
I want a way to parse out all function names that appear in a couple
of C files.
When the parsing logic finds a function name in a file, it should
print out the Function name, line number and file in which the
Function was found.

What approach should i follow to tackle this problem ?
Is there any option in the gcc compiler that prints out this
information ?



不知道你是什么通过解析来表示 - 在控制台中显示,为作业提供输出/代码?



Don''t know what you mean by ''parse out'' - display in a console, provide
output/code for ''homework''?




''解析' '有一个非常明确的含义,恕我直言。这意味着除了文件中的其他内容之外还要识别它。


回答OP的问题:这不是一个小问题。为了做你想做的事情,你必须编写一个理解C的程序:

你需要一个预处理器,一个词法扫描器和一个语法

解析器。虽然像lex和yacc(flex / bison)这样的工具可以让这更容易,但它有点矫枉过正。


这是家庭作业吗?如果是这样,请提供更多背景信息:如上所述,

问题太难以仅仅是作业。

源文件是否必须符合某些额外限制?


如果这仅仅是为了您自己的利益,我强烈建议您查看

用于已经执行此操作的程序(为什么重新发明轮子?)。

标准ctags程序可以做一些非常接近的事情,如果不是你需要的b $ b。查看 http://ctags.sourceforge.net/ 。你

应该能够使用grep,也许与sed或awk结合使用,以便

使它成为/完全/你想要的。有关

这些工具(所有这些都是本新闻组的主题)的更多信息,请

在comp.unix.programmer上询问。


HTH。



''parse out'' has a pretty clear meaning, IMHO. It means to recognize it
apart from everything else in the file in question.

To answer the OP''s question: this is not a trivial problem. In order
to do what you want, you have to write a program that understands C:
you''ll need a preprocessor, a lexical scanner, and a grammar
parser. While tools like lex and yacc (flex/bison) make this easier,
it''s overkill.

Is this a homework assignment? If so, please provide more context: the
problem as stated is far too difficult to be mere homework. Does the
source file have to conform to certain additional restrictions?

If this is solely for your own benefit, I strongly suggest you look
for programs that already do this (why reinvent the wheel?). The
standard "ctags" program can do something awfully close to, if not
exactly what you need. Check out http://ctags.sourceforge.net/. You
should be able to use grep, perhaps in combination with sed or awk, to
make it do /exactly/ what you want. For more information on any of
those tools (all of which are off-topic for this newsgroup), please
ask at comp.unix.programmer.

HTH.


2006-03-09,Micah Cowan< mi *** @ cowan.name>写道:
On 2006-03-09, Micah Cowan <mi***@cowan.name> wrote:
athiane写道:
athiane wrote:
>我想要一种解析出现在一对中的所有函数名的方法
> C档案。
>当解析逻辑在文件中找到函数名时,它应该是
>打印出函数名称,行号和文件,其中
>功能被发现。
>
>我应该采取什么方法来解决这个问题?
> gcc编译器中有没有打印出来的选项
>信息?
> I want a way to parse out all function names that appear in a couple
> of C files.
> When the parsing logic finds a function name in a file, it should
> print out the Function name, line number and file in which the
> Function was found.
>
> What approach should i follow to tackle this problem ?
> Is there any option in the gcc compiler that prints out this
> information ?


回答OP的问题:这不是一个小问题。为了做你想做的事,你必须编写一个理解C的程序:
你需要一个预处理器,一个词法扫描器和一个语法解析器。虽然像lex和yacc(flex / bison)这样的工具使这更容易,但它有点过分。

To answer the OP''s question: this is not a trivial problem. In order
to do what you want, you have to write a program that understands C:
you''ll need a preprocessor, a lexical scanner, and a grammar
parser. While tools like lex and yacc (flex/bison) make this easier,
it''s overkill.




我可能会遗漏一些东西,因为我没有对于

问题,我们已经考虑过很多,但我相信检测功能应该很简单。我记得我为C ++做过类似的事情并且它没有工作,因为我的简单算法也是匹配构造函数。 (所以我

然后做一个预处理阶段来收集文件中的所有后跟

class关键字,并排除这些,但现在就是OT)。


所以我的想法是首先从预处理器传递源来获取宏,然后匹配每个有效符号(序列角色

和从一个角色开始的数字),然后是''(''。


我错过了一些明显会破坏这个的东西吗? />
-

John Tsiombikas(核/ Mindlapse)
nu *** **@siggraph.org
http://nuclear.demoscene.gr /


这篇关于在任何C文件中查找功能名称的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆