I am a beginner in TCL and trying to write a TCL script to parse and print out all lines in a C++ code file which is used for variable declarations. Till Now I am able to detect and print all statements inside a block {}. Now I understand that the different variable declarations format in Ansi C++ modules could be:
int x;
int y=9;
int x,y;
int x,y=0;
int x,y=0,c;
short const x=9;
int* x,y,c=null;
short const *x=NULL;
MyObj aobj();
MyObj aobj(x,y);
Myobj * a = dynamic_cast<A *>(b);
String x = "test";
I am not sure if I missed any.
What I am doing is that I am splitting the line :
if { [ string equal $lineType "statement" ] == 1 } {
puts $lineValue
set wordList [regexp -inline -all -- {\S+} $lineValue]
}
to verify the below format by different values at its list index:
qualifier varaiablename = value;
qualifier varaiablename;
qualifier varaiablename = value, variablename;
But I am not able to achieve it. I believe that TCL regexp would help us here to achieve the objective. However I am unable to conclude of what regexp expression I should use / code here.
I want to avoid looking for C++ defined data types / keywords but look for a specific format in string which is actually a C++ statement:
qualifier type name;
qualifier type name, name2;
qualifier type name = value;
or rather
word word word;
word word word, word;
word word word = integer, word = word;
As per the declarations format mentioned above.
Please provide your valuable thoughts / input.