JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD

JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD B.Tech III PRINCIPLES OF COMPILER CONSTRUCTION Previous Question Paper (August/September - 2021 - R18)

B.Tech | III | II | R18 | August/September - 2021

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

Answer any five questions. All questions carry equal marks.

Main

115 marks
a

Discuss various phases of compiler in detail. Give the output of each phase of the compiler for the statement.

8 marks

Answer

A compiler is a program that translates source code into machine code through several distinct phases. For the statement position = initial + rate * 60, the phases are:

  1. Lexical Analysis: Reads the source code and converts it into a stream of tokens. Output: <id, 1> <=> <id, 2> <+> <id, 3> <*> <60>
  2. Syntax Analysis: Groups tokens into a hierarchical structure, typically a parse tree. Output: A tree with an assignment node at the root, with 'position' on the left and an expression tree on the right.
  3. Semantic Analysis: Checks for semantic consistency, such as type checking. Output: The tree is updated, for example, by inserting a conversion node to change the integer 60 to a float.
  4. Intermediate Code Generation: Produces a machine-independent intermediate representation. Output: t1 = inttofloat(60); t2 = id3 * t1; t3 = id2 + t2; id1 = t3
  5. Code Optimization: Improves the intermediate code for efficiency. Output: t1 = id3 * 60.0; id1 = id2 + t1
  6. Code Generation: Translates the optimized code into target machine code. Output: MOVF id3, R2; MULF #60.0, R2; ADDF id2, R2; MOVF R2, id1

The Symbol Table Manager and Error Handler interact with all phases throughout the process.

b

Write briefly about the specification of tokens.

7 marks

Answer

The specification of tokens involves defining the patterns that identify valid lexemes in a source language. This is formally achieved using Regular Expressions, which provide a concise notation for describing sets of strings.

Key aspects include:

  • Alphabet: A finite set of symbols (e.g., ASCII characters).
  • Strings and Languages: Sequences of symbols from the alphabet; a language is a set of such strings.
  • Regular Definitions: Used to simplify complex patterns by giving names to regular expressions (e.g., defining 'letter' as [a-zA-Z] and 'digit' as [0-9]).
  • Token Patterns: Specific rules such as identifier = letter(letter|digit)* or number = digit+(.digit+)?(E(+|-)?digit+)?.

These specifications are used by the lexical analyzer generator (like Lex or Flex) to construct a deterministic finite automaton (DFA) that recognizes the tokens during the scanning process.

215 marks
a

Briefly explain about compiler construction tools.

7 marks

Answer

Sign in to view the complete answer paper.

b

Convert the following regular expression to DFA.

8 marks

Answer

Sign in to view the complete answer paper.

315 marks
a

Check whether the following grammar is LALR(1) or not?

7 marks

Answer

Sign in to view the complete answer paper.

b

What is FIRST and FOLLOW? Specify the steps to compute FIRST and FOLLOW with an example.

8 marks

Answer

Sign in to view the complete answer paper.

415 marks
a

What are the difficulties in top down parsing? And give solutions to overcome these difficulties.

7 marks

Answer

Sign in to view the complete answer paper.

b

Construct LR (0) parser for the following grammar.

8 marks

Answer

Sign in to view the complete answer paper.

515 marks
a

Create three address codes for the statements:

while a < b do
if c < d then
x := y + z
else
x := y - z
7 marks

Answer

Sign in to view the complete answer paper.

b

Construct the syntax directed definition for desk calculator.

8 marks

Answer

Sign in to view the complete answer paper.

615 marks
a

Explain what are semantic errors and how semantic analysis is performed?

7 marks

Answer

Sign in to view the complete answer paper.

b

Apply the S-attributed definition and construct syntax tree for a simple expression, grammar involving only the binary operators + and -. As usual, these operators are at the same precedence level and are jointly left associative. All non-terminals have one synthesized attribute node, which represents a node of the syntax tree.

8 marks

Answer

Sign in to view the complete answer paper.

715 marks
a

Distinguish the static and dynamic storage allocation.

7 marks

Answer

Sign in to view the complete answer paper.

b

For the following expression obtain optimal code using:

i) Only two registers

ii) Only one register

8 marks

Answer

Sign in to view the complete answer paper.

815 marks
a

Compare local optimization with global optimization. Give suitable examples.

7 marks

Answer

Sign in to view the complete answer paper.

b

Explain global data flow analysis with necessary equations.

8 marks

Answer

Sign in to view the complete answer paper.

About this paper

This page contains the question paper of PRINCIPLES OF COMPILER CONSTRUCTION from JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD for B.Tech IT III II, August/September - 2021, R18.

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

Other papers in PRINCIPLES OF COMPILER CONSTRUCTION

Loading Question Papers

Fetching data from database...