I need to translate a for loop from C to Matlab. I have the following grammar:
stmt : stmt_while
| stmt_for
|...
;
stmt_for : FOR '(' for_exp ')' stmt { }
;
for_exp : exp ';' exp ';' exp { }
| exp ';' exp ';' { }
| exp ';' ';' exp { }
| exp ';' ';' { }
| ';' exp ';' exp { }
| ';' exp ';' { }
| ';' ';' exp { }
| ';' ';' { }
;
The for loops in Matlab have a completely different syntax so I do not know how to implement the translation. The simplest solution seems to me to translate it in a while:
exp1;
for(exp1; exp2; exp3){ while(exp2){
for_body... ==> for_body...
} exp3;
}
You have other solutions? Thank you all.