JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD

JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD B.Tech III COMPILER DESIGN Previous Question Paper (January/February - 2021 - R16)

B.Tech | III | II | R16 | January/February - 2021

Answer PaperPaper Code: 136AQMaximum Marks: 75Time: 2 Hours

Answer any five questions. All questions carry equal marks.

Main

1

Give the structure of a compiler and explain various phases of compilation.

15 marks

Answer

A compiler is a complex software system that translates source code written in a high-level programming language into target machine code. The compilation process is organized into two main parts: the Analysis phase (front-end), which breaks the source program into constituent parts and creates an intermediate representation, and the Synthesis phase (back-end), which constructs the target program from the intermediate representation.

The phases of compilation are as follows:

  1. Lexical Analysis (Scanning): The lexer reads the stream of characters from the source code and groups them into meaningful sequences called lexemes, which are then categorized into tokens (e.g., keywords, identifiers, operators).
  2. Syntax Analysis (Parsing): The parser takes the tokens and arranges them into a hierarchical structure, typically a Syntax Tree or Abstract Syntax Tree (AST), to ensure the code adheres to the grammatical rules of the language.
  3. Semantic Analysis: This phase checks the source program for semantic consistency, such as type checking (ensuring operands are compatible with operators) and scope resolution.
  4. Intermediate Code Generation: The compiler generates a machine-independent intermediate representation, such as Three-Address Code, which facilitates optimization and simplifies the translation to different target architectures.
  5. Code Optimization: This phase improves the intermediate code to produce a more efficient target program, focusing on reducing execution time and memory usage without altering the program's meaning.
  6. Code Generation: The final phase maps the optimized intermediate code into the target machine language or assembly code, involving register allocation and instruction selection.

Additionally, the Symbol Table Manager and Error Handler interact with all phases to maintain information about identifiers and report syntax or semantic errors encountered during the process.

2

Compute Firsts and Follows and construct LL(1) parser table for the following grammar after eliminating ambiguity.

R → R + R, R → R * R, R → R / R, R → (R), R → id
15 marks

Answer

The given grammar is ambiguous due to left recursion and operator precedence issues. To construct an LL(1) parser, we must first eliminate ambiguity and left recursion. The transformed grammar is:

R → TR'
R' → +TR' | *TR' | /TR' | ε
T → (R) | id

First and Follow Sets:

Non-TerminalFirstFollow
R{(, id}{$, ), +, *, /}
R'{+, *, /, ε}{$, )}
T{(, id}{+, *, /, $, )}

LL(1) Parsing Table:

id+*/()$
RR → TR'R → TR'
R'R' → +TR'R' → *TR'R' → /TR'R' → εR' → ε
TT → idT → (R)
315 marks
a

How are inherited attributes differ from synthesized attributes?

5 marks

Answer

Sign in to view the complete answer paper.

b

Construct the SDD to convert infix notation to postfix notation.

10 marks

Answer

Sign in to view the complete answer paper.

415 marks
a

What is a type checker? Give the specification of a simple type checker.

7 marks

Answer

Sign in to view the complete answer paper.

b

Write the quadruples, triples and indirect triples for the expression:

a * b – (c – d) + b * a – (c – d)
8 marks

Answer

Sign in to view the complete answer paper.

5

Explain various storage allocation strategies and also mention their merits and demerits.

15 marks

Answer

Sign in to view the complete answer paper.

615 marks
a

What is a Basic Block? How to construct a Basic block?

7 marks

Answer

Sign in to view the complete answer paper.

b

Explain Peephole optimization with an illustrative example.

8 marks

Answer

Sign in to view the complete answer paper.

7

Explain the principal sources of code optimization with merits and demerits of each.

15 marks

Answer

Sign in to view the complete answer paper.

8

Explain the following:

15 marks
a

Basic elements of Data-Flow Analysis.

8 marks

Answer

Sign in to view the complete answer paper.

b

Register Allocation.

7 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 II, January/February - 2021, R16.

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...