Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Extract variable definitions and variable use from a C program (http://www.go4expert.com/forums/extract-variable-definitions-variable-c-t25405/)

abk07 2Apr2011 15:03

Extract variable definitions and variable use from a C program
 
Hi! I’m trying to write a ‘C’ program to extract variable definitions and variable use in each line from a input ‘C’ program.
That is, a variable is said to be defined when its value changes(including declarations) and it is said to be ‘used’ when it is referenced. I need to consider this for all the cases and functions(built-in as well as user defined)..
For example consider the following input program

int main()
{
int a,b,c;
a=10;
b=20;
c=a+b;
printf(“c=%d”,c);
}

In the line 3, a,b,c are defined and nothing is referenced, hence in line number 3 under the ‘defined’ column a,b,c must be printed, and a mere ‘–‘ should be printed under the ‘used’ column.
Similarly in line 6, ‘a’ is defined and both ‘b’ and ‘c’ are used, hence in defined column a should be printed and under ‘used’ column ‘b,c’ should be printed.
I really don’t know how to start.. can anyone please give me an idea??
Thanks in advance..


All times are GMT +5.5. The time now is 06:40.