Reputation: 1206
I want to parse C program files (.c extension) using perl. I want the parsing to be done in such a fashion like a sample c program may contain statement like
printf ("%d => Hello",x);
let x be a integer variable in the program. So when i parse the above line, is there any way of getting x value. Remember, i want to parse only one line and get the value of x, i cant parse any previous lines to obtain the value of x. Is there any way to obtain the actual value of x dynamically or is it better to parse object files.
Upvotes: 2
Views: 810
Reputation: 19347
No. Think about it:
int x = rand();
printf("%d", x);
How could you possibly know what x
is without running the program?
Upvotes: 7
Reputation: 137322
There is no tool in the world that may reliably find the value of x using the line printf ("%d => Hello",x);
only. The value depends on previous lines, and maybe on user input, which is not in the source code at all.
Edit
On the other hand, there are a lot of tools that work with C code, such as static analyzers, debuggers, interpreters and so on. You might want to look for one of those options.
Upvotes: 10