I am passed in a C file. The C file contains functions which contain local variables. Given any C file, i have to be able to find the local variables within a specific method (which the user specifies) and make them global. (specifications for another application which can only handle global variables)…
What is the easiest way to do this? Would it be through shell scripting or should it directly in C. Should i use regex? Am i thinking about doing this the wrong way?
Any help would be appreciated
You are looking for a specific context of variables, in your case the context is local variables declared inside of a function. A regular expression can be used to pull out a function definition, but some kind of token parser would be much better.
Using a simplified grammar for C it can be found that you can get the function strings themselves and from there you can find the local variables themselves.
But, if the C code passed in is in a specific format, IE local variables are at the top of the function definition then a simple regular expression can be used.