hi all... i have a while,if,elseif statements in a file with multipe conditions inside it... it is a C language...the format is mentioned below is standard for all the multiple conditions.So no worries about the indendation.The only problem is to check how many conditions are there and list as per output format that i have described.... eg if my C file have a code...
while(
condition1 &&
condition2 ||
condition3
)
{
#statements;
}
i want to count how many conditions are there inside the while and my output should be
of like this...
while(
1 condition1 &&
2 condition2 ||
3 condition3
)
{
#statements;
}
i have written the code and it works fine for simple one.. my code....
open(A,"e:\\a\\a.txt")or die;
@a=<A>;
close(A);
$count=1;
for($i=0;$i<scalar@a;$i++)
{
if($a[$i]=~m/while/g)
{
$line=$i;
until($a[$line]=~/\{/g)
{
if($a[$line]=~/(.*)[\&&\||]/g){print"$count $a[$line]";$count++;}
elsif($a[$line]=~/\(.*\)[\&&\||]/g){print"$count $a[$line]";$count++;}
else{print$a[$line];}
$line++;
}
}
last if($a[$line]=~/\{/g);
}
but for complicated conditions like
while(
(
condition1 &&
condition2 &&
condition3
) ||
(
condition4 ||
condition5 &&
condition6
)
{
#statements;
}
am getting the output like
while(
(
1 condition1 &&
2 condition2 &&
condition3
3 ) ||
(
4 condition4 ||
5 condition5 &&
condition6
)
which is not desired.... my intension is to count all the conditions regarding however complicated it is..... please help me...
desired output may be
while( ( 1 condition1 && 2 condition2 && 3 condition3 ) || ( 4 condition4 || 5 condition5 && 6 condition6 ) ) since it has used 6 conditions inside... hence forth for any cases.