English 中文(简体)
C方案中的可变定义和变量参照
原标题:Extract variable definitions and variable reference from a C program

我曾被派到大学进行奇怪的项目。 要求我从特定投入C方案中提取可变的定义和参考资料。

投入方案中的每一行都包含各自在开始时的线数,然后是空间,然后是实际代码。

Consider the following program..

1 int main()  
2 {  
3 int a,b,c;  
4 printf("Enter the values of a and b
");  
5 scanf("%d%d",&a,&b);  
6 c=a+b;  
7 printf("The sum of two numbers is %d",c);  
8 }  

And the input for the program which I m developing is a C program, in which single line consists of a single statement.. ie, we know that a whole program can be written in a single line. But not in my case, that is once there is a termination(semicolon), the lines following the semi colon is shifted to next line..

我工作的任何途径都是在投入C方案中摘录各种定义/声明以及可变的使用/参考。

Consider the above program, In line number 3, variables a,b and c are declared, hence it has to be printed under the "definition" column of the output..

同样,在表5中,a和b的数值正用扫描仪表加以初步计算,因此,a和b的变量应在产出的定义栏下印刷。

Now consider the statement 6, The value of variable c is being initialized/defined hence c must be printed under the definition column.. At the same time, values of a and b are being used to determine the value of c, hence variables a and b must be printed under the "reference" column of the output..

最后,表7提到/使用了变数c的价值,因此,变数c必须在参考栏下印刷。

The sample output of the program is as shown below..

Line Number          Defined Variable        Referenced Variable
_____________________________________________________________________
  1                       --                           --
  2                       --                           --
  3                     a,b,c                         --
  4                       --                           --
  5                      a,b                          --
  6                       c                           a,b
  7                       --                          c
  8                       --                          --

Can anyone tell me how to solve the problem???? Remember, I need to write a C/C++ program or even shell script is allowed for the project.. I need to consider the mathematical expressions, logical expressions, built in function calls, user defined function calls and function definitions as well..

Thanks in advance..

问题回答

要做的标准工作是写一个象征剂和一个教区,以部分汇编你们的投入方案。 然后,你知道每一行的表述。 为了完成这项任务,你可以就以下事项定期表达意见:

  1. variable definition
  2. variable reference

并且为每一行铺设捕获物。 例如,可变参考资料可能像“除有效C类数据外,任何地方的有效C识别”。 此处的捕获量是“有效的C识别器”,因此只是在“可参考文件”栏下打印。

You basically need to start with a full-blown C parser. You could write this yourself, but you re probably better off using something pre-existing, such as CLang.





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签