JNTU
JNTU B.Tech III COMPILER DESIGN Previous Question Paper (February/March - 2022 - R18)
Answer any five questions. All questions carry equal marks.
Main
Write down the steps in constructing DFA for the regular expression (a|b)*aab(a|b)*.
Answer
The construction of a Deterministic Finite Automaton (DFA) from the regular expression (a|b)*aab(a|b)* involves the following steps:
- 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.
- 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.
- Define the start state of the DFA as the epsilon-closure of the start state of the NFA.
- 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.
- Identify all DFA states that contain at least one accepting state from the original NFA as final states.
- 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.
Explain with an example how lex program perform lexical analysis for the arithmetic operators and identifiers in C?
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:
- The input stream is scanned to find the longest match for the defined patterns.
- 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.
- If an arithmetic operator (e.g., '+') is encountered, the operator rule matches, and the corresponding action executes.
- The lexer continues this process until the entire input is consumed or an error occurs.
Give the basic structure of a compiler and explain various components in brief.
Answer
Sign in to view the complete answer paper.
Describe the analysis-synthesis model of a compiler.
Answer
Sign in to view the complete answer paper.
What is left-factoring? Write the algorithm to eliminate left-factoring from a grammar. Explain the same with an example.
Answer
Sign in to view the complete answer paper.
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?
Answer
Sign in to view the complete answer paper.
Show that the following grammar is LALR(1): S→Aa | bAc | dc | bda; A→d
Answer
Sign in to view the complete answer paper.
What are the three forms of intermediate code representations? Explain them.
Answer
Sign in to view the complete answer paper.
Give the syntax-directed definition of a simple desk calculator and construct an annotated parse tree for the input expression (4*7+1)*2.
Answer
Sign in to view the complete answer paper.
Explain about syntax directed translation of Boolean expressions with and without back patching.
Answer
Sign in to view the complete answer paper.
What is an activation record? Describe various components in an activation record considering a sample c program.
Answer
Sign in to view the complete answer paper.
Write down the code generation algorithm and explain briefly.
Answer
Sign in to view the complete answer paper.
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
Answer
Sign in to view the complete answer paper.