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

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter7: Arrays
Section: Chapter Questions
Problem 9PP: (Data processing) Your professor has asked you to write a C++ program that determines grades at the...
icon
Related questions
Question

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

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Problems on Dynamic Programming
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning