使用c#识别C函数的开始和结束 [英] Identifying a C function start and end using c#

查看:139
本文介绍了使用c#识别C函数的开始和结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用C#编写的程序,当给出两个.C文件时,计算两个文件中的行,我想添加计算文件中有多少函数的能力,有多少行在这些函数以及文件1和文件2中的2个函数之间的区别。我无法弄清楚如何确定一行是否是函数(或方法)的开头。

解决方案

您必须解析 C 代码。

您可能会在Google中找到一些有趣的信息结果:解析C函数定义 [ ^ ]。

如果您的格式一致,您可能会发现函数的开始和结束括号始终在行的偏移零点。



 in tf(...)
{
...
}





然而,我怀疑你最好算上打开和关闭括号而不是信任格式。这取决于你想要的准确程度。另外请记住,行数是一个相当无用的指标,但它可能是一个值得的练习。







什么是

a

line?


I have a program, written in C#, that when given a tow .C files, counts the lines in the tow files, I want to add the ability to count how many functions are in the files , how many lines are in those functions and the difference between the 2 functions in file 1 and file 2. I can't figure out how to determine whether a line is the start of a function (or method).

解决方案

You have to parse the C code.
You may find some interesting info in Google results: "parsing C functions definitions"[^].


If you have been consistent in your formatting, you may find that a function's beginning and ending braces are always at offset zero on the line.

int f ( ... )
{
  ...
}



However, I suspect you would do well to count open and closing braces rather than trust the formatting. It just depends on how accurate you want to be. Also bear in mind that a count of lines is a fairly useless metric, but it can be a worthwhile exercise.


And
what's
a
line?


这篇关于使用c#识别C函数的开始和结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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