JNTU

JNTU B.Tech III COMPILER DESIGN Previous Question Paper (February/March - 2022 - R18)

B.Tech | III | II | R18 | February/March - 2022

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

Answer any five questions. All questions carry equal marks.

Main

115 marks
a

Write down the steps in constructing DFA for the regular expression (a|b)*aab(a|b)*.

7 marks

Answer

The construction of a Deterministic Finite Automaton (DFA) from the regular expression (a|b)*aab(a|b)* involves the following steps:

  1. Convert the regular expression into a Non-deterministic Finite Automaton (NFA) using Thompson's construction. This involves creating individual NFAs for each sub-expression and connecting them using epsilon transitions.
  2. Convert the NFA to a DFA using the Subset Construction (or Powerset Construction) algorithm. This process involves creating a new DFA state for every set of NFA states reachable by a specific input symbol.
  3. Define the start state of the DFA as the epsilon-closure of the start state of the NFA.
  4. For each DFA state and each input symbol in the alphabet, compute the set of reachable NFA states and mark these as a new DFA state if not already visited.
  5. Identify all DFA states that contain at least one accepting state from the original NFA as final states.
  6. Minimize the resulting DFA by merging equivalent states using the state minimization algorithm (e.g., Hopcroft's algorithm) to ensure the fewest number of states.
b

Explain with an example how lex program perform lexical analysis for the arithmetic operators and identifiers in C?

8 marks

Answer

A Lex program performs lexical analysis by matching input text against regular expression patterns and executing associated C code actions. The structure consists of three sections: definitions, rules, and user subroutines.

For identifying arithmetic operators and identifiers, the rules section defines patterns:

[a-zA-Z_][a-zA-Z0-9_]* { printf("Identifier: %s\n", yytext); }
[\+\-\*\/]          { printf("Operator: %s\n", yytext); }

When the lexer runs:

  1. The input stream is scanned to find the longest match for the defined patterns.
  2. If an identifier (e.g., 'count') is matched, the rule for identifiers triggers, and the action prints the token type and the matched string stored in the global variable yytext.
  3. If an arithmetic operator (e.g., '+') is encountered, the operator rule matches, and the corresponding action executes.
  4. The lexer continues this process until the entire input is consumed or an error occurs.
215 marks
a

Give the basic structure of a compiler and explain various components in brief.

7 marks

Answer

Sign in to view the complete answer paper.

b

Describe the analysis-synthesis model of a compiler.

8 marks

Answer

Sign in to view the complete answer paper.

315 marks
a

What is left-factoring? Write the algorithm to eliminate left-factoring from a grammar. Explain the same with an example.

7 marks

Answer

Sign in to view the complete answer paper.

b

Consider the following grammar: bexpr → bexpr or bterm | bterm; bterm → bterm and bfactor | bfactor; bfactor → not bfactor | ( bexpr) | true | false. i) Construct a parse tree for the sentence not (true or false). ii) Is this grammar ambiguous? Why?

8 marks

Answer

Sign in to view the complete answer paper.

4

Show that the following grammar is LALR(1): S→Aa | bAc | dc | bda; A→d

15 marks

Answer

Sign in to view the complete answer paper.

515 marks
a

What are the three forms of intermediate code representations? Explain them.

7 marks

Answer

Sign in to view the complete answer paper.

b

Give the syntax-directed definition of a simple desk calculator and construct an annotated parse tree for the input expression (4*7+1)*2.

8 marks

Answer

Sign in to view the complete answer paper.

6

Explain about syntax directed translation of Boolean expressions with and without back patching.

15 marks

Answer

Sign in to view the complete answer paper.

715 marks
a

What is an activation record? Describe various components in an activation record considering a sample c program.

8 marks

Answer

Sign in to view the complete answer paper.

b

Write down the code generation algorithm and explain briefly.

7 marks

Answer

Sign in to view the complete answer paper.

8

How to construct the basic block and compute DAG for the code fragment? Explain with the following code fragment: procedure fun(x,y,z) begin y=z+1; z=z+x; end fun; begin main(); a=2; b=3; fun(A+B,A,B); print(A); end main

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 JNTU for B.Tech CSE III II, February/March - 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...