JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD

JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD B.Tech III COMPILER DESIGN Previous Question Paper (March - 2021 - R13/R15)

B.Tech | III | I | R13/R15 | March - 2021

Answer PaperPaper Code: 125AP/115APMaximum Marks: 75Time: 3 hours

Answer any five questions. All questions carry equal marks.

Main

115 marks
a

Write a LEX program to identify few reserved words of C language.

7 marks

Answer

The following LEX program identifies specific C reserved words such as if, else, while, and for:

%{ #include <stdio.h> %}
%%
if|else|while|for { printf("%s is a reserved word\n", yytext); }
[a-zA-Z_][a-zA-Z0-9_]* { printf("%s is an identifier\n", yytext); }
.|
 { ; }
%%
int yywrap() { return 1; }
int main() { yylex(); return 0; }
b

What is ambiguous grammar? How to eliminated left recursion from an ambiguous grammar? Explain.

8 marks

Answer

A grammar is ambiguous if there exists at least one string in its language that has more than one leftmost derivation, more than one rightmost derivation, or more than one parse tree. Ambiguity often arises in expressions where operator precedence or associativity is not defined.

Left recursion occurs when a non-terminal A can derive a string starting with itself, typically in the form

A → Aα | β
. While left recursion is not the same as ambiguity, it must be eliminated for top-down parsers like LL(1) to avoid infinite loops. To eliminate immediate left recursion, the production is transformed into:

A → βA'
A' → αA' | ε

Where A' is a new non-terminal and ε represents the empty string. If the grammar is ambiguous, it must first be rewritten to enforce precedence and associativity rules (e.g., by introducing new non-terminals for terms and factors) before applying the left recursion elimination algorithm.

2

Eliminate the left-recursion from the following grammar:

S → (L) | a
L → L,S | S

Determine whether a predictive parser can be constructed for this grammar or not. Also construct the parsing table.

15 marks

Answer

Sign in to view the complete answer paper.

3

Compute LR(0) items for the following grammar and construct SLR parsing table:

S → L=R | R
L → *R | id
R → L
15 marks

Answer

Sign in to view the complete answer paper.

415 marks
a

Write a YACC program to evaluate arithmetic expressions.

7 marks

Answer

Sign in to view the complete answer paper.

b

Write an algorithm for constructing LALR Parser table.

8 marks

Answer

Sign in to view the complete answer paper.

5

Explain briefly various data structures used to implement the symbol table.

15 marks

Answer

Sign in to view the complete answer paper.

6

Discuss various loop optimization and load optimization techniques with an illustrative example.

15 marks

Answer

Sign in to view the complete answer paper.

715 marks
a

Write the algorithm for gencode( ) procedure.

7 marks

Answer

Sign in to view the complete answer paper.

b

Explain the following peephole optimization techniques:

i) Algebraic Specification
ii) Strength Reduction

8 marks

Answer

Sign in to view the complete answer paper.

8

Explain the process of register allocation using graph coloring with an example.

15 marks

Answer

Sign in to view the complete answer paper.

About this paper

This page contains the question paper of COMPILER DESIGN from JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD for B.Tech CSE III I, March - 2021, R13/R15.

For the solved question paper with answers, switch to the Answer Paper tab.

Other papers in COMPILER DESIGN

Loading Question Papers

Fetching data from database...