I want to write a sort of translator which can translate the code of for loop to coresponding while.
for example if i have :
for(int i = 0 ; i < 10 ;i++)
Console.WriteLine("Hello");
it should translate like :
int i = 0;
while( i < 10)
{
Console.WriteLine("Hello");
i++;
}
Can some body help me creating a translator which translates for loop to while
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Michael32 pointsPosted Oct 10, 2005, 4:21 PM EDT
you could use an regular expression
change
for\({.+}\;{.+}\;{.+}\)\n*\{{(\n.*)*}\}
into
\1;\nwhile(\2)\{\4\3;\n\}