Given the C program: int prime(int n){ int sum = 0; int i,j,flag = 1; for(i = 2; i<=n; i++){ flag = 1; for(j = 2; j*j <= i; j++){ if(i%j == 0){ flag = 0; break; } } if(flag == 1){ sum ++; } } return sum; } int main(){ int res = n = 0; do{ res = prime(n); }while(n < 10); return 0; } (1) Please give the grammar description of do-while statement according to C specification. (2) Please give the syntax directed definition and translation scheme according to the grammar (3) Please show the AST for this segment of code (4) Please translate the AST to three address codes
Given the C program:
int prime(int n){
int sum = 0;
int i,j,flag = 1;
for(i = 2; i<=n; i++){
flag = 1;
for(j = 2; j*j <= i; j++){
if(i%j == 0){
flag = 0;
break;
}
}
if(flag == 1){
sum ++;
}
}
return sum;
}
int main(){
int res = n = 0;
do{
res = prime(n);
}while(n < 10);
return 0;
}
(1) Please give the grammar description of do-while statement according to C specification.
(2) Please give the syntax directed definition and translation scheme according to the grammar
(3) Please show the AST for this segment of code
(4) Please translate the AST to three address codes
Step by step
Solved in 2 steps