JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD

JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD B.Tech III COMPILER DESIGN Previous Question Paper (August - 2022 - R18)

B.Tech | III | II | R18 | August - 2022

Answer PaperPaper Code: 156AHMaximum Marks: 75Time: 3 Hours

Answer any five questions

All questions carry equal marks

Main

115 marks
a

What are the advantages of a compiler over an interpreter?

5 marks

Answer

Compilers offer several advantages over interpreters, primarily centered on execution efficiency and software distribution:

  • Execution Speed: Compilers translate the entire source code into machine code before execution, allowing the program to run significantly faster than interpreted code, which must be translated line-by-line during runtime.
  • Optimization: Compilers perform sophisticated global code optimizations, such as constant folding, loop unrolling, and register allocation, which are generally not feasible in interpreters.
  • Intellectual Property Protection: Compiled code is distributed as binary executables, making it difficult for end-users to view or modify the original source code, whereas interpreters typically require the source code to be present.
  • Error Detection: Compilers perform comprehensive static analysis, catching syntax and type errors across the entire program before execution begins.
  • Resource Efficiency: Once compiled, the program does not require the compiler or an interpreter to be present in memory during execution, reducing the overall system overhead.
b

Draw the structure of a compiler and describe various phases in the compilation process mention the output of the following statement: id1=id2+id3*50 at each phase.

10 marks

Answer

A compiler is structured as a series of phases that transform the source program into target machine code. The process is divided into the front-end (analysis) and back-end (synthesis).

Phases of Compilation:

  1. Lexical Analysis: Converts the stream of characters into tokens.
  2. Syntax Analysis: Checks the structure against grammar rules and builds a parse tree or abstract syntax tree.
  3. Semantic Analysis: Checks for type consistency and semantic correctness.
  4. Intermediate Code Generation: Produces a machine-independent representation (e.g., Three-Address Code).
  5. Code Optimization: Improves the intermediate code for speed and space.
  6. Code Generation: Translates the optimized intermediate code into target machine code.

Output for id1 = id2 + id3 * 50:

PhaseOutput
Lexical Analysis<id, 1> <=, > <id, 2> <+, > <id, 3> <*, > <num, 50>
Syntax AnalysisParse Tree (Hierarchical structure with * as child of +)
Semantic AnalysisAnnotated Parse Tree (Type checking: 50 treated as float if id3 is float)
Intermediate Codet1 = id3 * 50
t2 = id2 + t1
id1 = t2
Code Optimizationt1 = id3 * 50
id1 = id2 + t1
Code GenerationMOV R1, id3
MUL R1, 50
ADD R1, id2
MOV id1, R1
215 marks
a

Design the LEX program that recognizes the tokens of a C language and returns the token found.

7 marks

Answer

Sign in to view the complete answer paper.

b

Give the DFA and NFA to accept the strings containing a, b such that the string contains even number of a’s and odd number of b’s.

8 marks

Answer

Sign in to view the complete answer paper.

315 marks
a

Remove the left recursion for the following grammar and also find FIRSTS and FOLLOWs.

E → E + T | T
T → T * F | F
F → (E) | id
7 marks

Answer

Sign in to view the complete answer paper.

b

Write the steps/algorithm to construct the predictive parser table and explain with an example.

8 marks

Answer

Sign in to view the complete answer paper.

415 marks
a

Construct the Recursive Descent Parser with backtracking for the following grammar:

S → aSbS | bSaS | ε
7 marks

Answer

Sign in to view the complete answer paper.

b

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

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

Answer

Sign in to view the complete answer paper.

515 marks
a

Construct the syntax directed definition to convert infix notation into postfix notation.

8 marks

Answer

Sign in to view the complete answer paper.

b

Describe different ways of implementing intermediate code generation of a three-address statement.

7 marks

Answer

Sign in to view the complete answer paper.

615 marks
a

Explain how an L-attributed grammar is converted into a translation scheme.

8 marks

Answer

Sign in to view the complete answer paper.

b

Compare and contrast S-Attributed definitions with L-Attributed definitions.

7 marks

Answer

Sign in to view the complete answer paper.

7

How is stack storage allocation strategy different from heap allocation strategy? Describe them mentioning their merits and demerits.

15 marks

Answer

Sign in to view the complete answer paper.

8

Explain the foundations and basic notations used in data-flow analysis for optimizations with examples.

15 marks

Answer

Sign in to view the complete answer paper.

About this paper

This page contains the solved question paper with answers of COMPILER DESIGN from JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD for B.Tech CSE III II, August - 2022, R18.

For the question paper without answers, switch to the Question Paper tab.

Other papers in COMPILER DESIGN

Loading Question Papers

Fetching data from database...