JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD

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

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

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

Answer any five questions. All questions carry equal marks.

Main

115 marks
a

State the reasons for separating Lexical analysis and Syntax analysis.

7 marks

Answer

Separating lexical analysis from syntax analysis provides several advantages in compiler design:

  • Simplicity of Design: Separating the phases simplifies the overall compiler architecture. The lexical analyzer handles low-level character stream processing, while the syntax analyzer focuses on structural hierarchy, making both easier to implement and maintain.
  • Improved Efficiency: Lexical analysis is specialized for character-level processing, often using buffering and specialized finite automata. Syntax analysis is more computationally expensive (parsing); isolating the lexical phase allows for performance optimizations like fast scanning without the overhead of the parser.
  • Portability: The lexical analyzer is often platform-dependent (handling character sets, line endings), while the parser is generally language-dependent. Separating them allows the parser to remain portable across different machine architectures.
  • Compiler Compiler Tools: Many compiler generation tools (like Lex and Yacc) are designed to work independently. Separating phases allows developers to use specialized tools for each, improving development speed and reliability.
b

Discuss how Finite Automata is used to recognize tokens and perform lexical analysis with example.

8 marks

Answer

Finite Automata (FA) serve as the mathematical model for lexical analysis by defining the patterns (regular expressions) of tokens. A lexical analyzer uses a Deterministic Finite Automaton (DFA) to transition between states based on input characters until a complete token is recognized.

The process involves:

  • Pattern Definition: Regular expressions are converted into Non-deterministic Finite Automata (NFA) and then into a DFA using subset construction.
  • State Transitions: The scanner starts at the initial state and consumes characters one by one. If the DFA reaches an accepting state, the sequence of consumed characters constitutes a valid token.
  • Longest Match Rule: The scanner continues to read characters until no further transitions are possible, ensuring the longest valid token is identified (e.g., distinguishing 'if' from 'identifier').

Example: To recognize an identifier defined as a letter followed by letters or digits, the DFA has two states: State 0 (start) and State 1 (accepting). On input 'a', it transitions from 0 to 1. On subsequent 'a' or '1', it loops in State 1. If a space or operator is encountered, it stops and returns the token 'identifier'.

215 marks
a

How to specify the Tokens? Differentiate Token, Lexeme and Pattern with suitable examples.

7 marks

Answer

Sign in to view the complete answer paper.

b

Explain various Error Recovery strategies in Lexical analysis.

8 marks

Answer

Sign in to view the complete answer paper.

315 marks
a

What do you mean by Ambiguous Grammar? Check whether the following grammar is Ambiguous or not:

S → aAB, A → bC/cd, C → cd, B → c/d
8 marks

Answer

Sign in to view the complete answer paper.

b

Write a note on Yacc.

7 marks

Answer

Sign in to view the complete answer paper.

4

Construct CLR parsing table for the following Grammar:

S → L=R, S → R, L → *R, L → id, R → L

(Write all necessary procedures).

15 marks

Answer

Sign in to view the complete answer paper.

515 marks
a

Give Syntax Directed Translation scheme for Simple Desk Circulator.

7 marks

Answer

Sign in to view the complete answer paper.

b

Convert the following arithmetic expression into Syntax Tree and Three Address Code:

b*3(a+b)

8 marks

Answer

Sign in to view the complete answer paper.

615 marks
a

Differentiate Synthesized and Inherited Attributes with example.

7 marks

Answer

Sign in to view the complete answer paper.

b

Generate Intermediate code for the following code segment along with the Syntax Directed Translation Scheme.

if (a > b) x = a + b; else x = a - b;

Where ‘a’ and ‘x’ are of real and ‘b’ of int type data.

8 marks

Answer

Sign in to view the complete answer paper.

715 marks
a

What is Flow-Graph? Explain how the given program can be converted into Flow-Graph?

8 marks

Answer

Sign in to view the complete answer paper.

b

Construct DAG for the following basic block:

d := b+c, e := a+b, b := b*c, a := e-d
7 marks

Answer

Sign in to view the complete answer paper.

815 marks
a

“Copy propagation Leads to Dead code” - Justify the statement.

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 solved question paper with answers of COMPILER DESIGN from JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD for B.Tech CSE III III-II, August/September - 2021, 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...