Compiler Design - B.Tech. 6th Semester Examination, 2018
Compiler Design
Instructions:
- The marks are indicated in the right-hand margin.
- There are NINE questions in this paper.
- Attempt FIVE questions in all.
- Question No. 1 is compulsory.
-
What is the number of tokens in the following C statement? printf("I=%d and I=%x",I and I)
-
Consider the following two statements: P: Every regular grammar is LL(1). Q: Every regular set has LR(1) grammar. Which of the following is true?
-
What is the similarity between LR, LALR and SLR?
-
Consider the following grammar: \( S \rightarrow aSbS | bSaS | \epsilon \). How many different parse trees are possible for string ababab?
-
A shift reduce parser carries out the actions specified within braces immediately after reducing with the corresponding rule of grammar: \( S \rightarrow xxW \) {PRINT "1"}, \( S \rightarrow y \) {print "2"}, \( S \rightarrow Sz \) {print "3"}. What is the translation of xxxxyzz using the syntax directed translation scheme described by the above rules?
-
The most powerful parser is
-
In some programming languages, an identifier is permitted to be a letter followed by any number of letters or digits. If L and D denote the sets of letters and digits respectively, which of the following expressions defines an identifier?
-
In operator precedence parsing, precedence relations are defined
-
A bottom-up parser generates
-
A grammar that produces more than one parse tree for some sentence is called
-
What do you understand by left recursion and left factoring? How are these eliminated? Explain with the help of suitable example.
-
What do you understand by bootstrapping? Explain with the help of suitable example.
-
How can addressing modes be used for reducing the memory access time?
-
What are activation records? Explain its purpose in compilers.
-
What are the optimization techniques applied on procedures calls? Explain with an example.
-
Given the Syntax-Directed Definition below with the synthesized attribute val. Draw the annotated parse tree for the expression \( (3+4)*(5+6) \):
\( L \rightarrow E \) ; \( L.val = E.val \)
\( E \rightarrow T \) ; \( E.val = T.val \)
\( E \rightarrow E_1+T \) ; \( E.val = E_1.val+T.val \)
\( T \rightarrow F \) ; \( T.val = F.val \)
\( T \rightarrow T_1*F \) ; \( T.val = T_1.val*F.val \)
\( F \rightarrow (E) \) ; \( F.val = E.val \)
\( F \rightarrow digit \) ; \( F.val = digit.lexval \) -
Construct a Syntax-Directed Translation scheme that translates arithmetic expressions from infix into postfix notation. Your solution should include the context-free grammar, the semantic attributes for each of the grammar symbols, and semantic rules. Show the application of your scheme to the input "3*4+5*2".
-
What is the advantage of using machine independent intermediate representation during translation process?
-
Explain, with example, what three address codes are. Give some common three address statements.
-
Find the three address codes of the following program. There are four bytes per word:
Sum = 0
For(i = 1; i <= 20; i++)
Sum = Sum + a[i] + b[i];
-
Find the CNF (Chomsky Normal Form) for the following CFG:
\( S \rightarrow ABA \)
\( A \rightarrow aA | \epsilon \)
\( B \rightarrow bB | \epsilon \) -
Eliminate null productions from the following CFG:
\( S \rightarrow Xa \)
\( X \rightarrow aX | bX | \epsilon \) -
Convert the following grammar to GNF :
\( A_1 \rightarrow A_2A_3 \)
\( A_2 \rightarrow A_3A_1 | b \)
\( A_3 \rightarrow A_1A_2 | a \)
-
What are the advantages of LALR parsing over SLR and CLR methods?
-
Write the algorithm to compute FIRST and FOLLOW for a given grammar.
-
What is shift-reduce conflict?
-
What are intermediate codes in compilers? Why is it needed in compiler design? Discuss different types of intermediate codes generated by intermediate code generation phase.
-
What is parsing? What is the difference between Top-down parsing, Bottom-up parsing and Predictive parsing?
-
Explain the working of each phase of compiler in detail with an example.