JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD
JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD B.Tech III COMPILER DESIGN Previous Question Paper (March - 2021 - R13/R15)
Answer any five questions. All questions carry equal marks.
Main
Write a LEX program to identify few reserved words of C language.
Answer
The following LEX program identifies specific C reserved words such as if, else, while, and for:
%{ #include <stdio.h> %}
%%
if|else|while|for { printf("%s is a reserved word\n", yytext); }
[a-zA-Z_][a-zA-Z0-9_]* { printf("%s is an identifier\n", yytext); }
.|
{ ; }
%%
int yywrap() { return 1; }
int main() { yylex(); return 0; }What is ambiguous grammar? How to eliminated left recursion from an ambiguous grammar? Explain.
Answer
A grammar is ambiguous if there exists at least one string in its language that has more than one leftmost derivation, more than one rightmost derivation, or more than one parse tree. Ambiguity often arises in expressions where operator precedence or associativity is not defined.
Left recursion occurs when a non-terminal A can derive a string starting with itself, typically in the form
Where A' is a new non-terminal and ε represents the empty string. If the grammar is ambiguous, it must first be rewritten to enforce precedence and associativity rules (e.g., by introducing new non-terminals for terms and factors) before applying the left recursion elimination algorithm.
Eliminate the left-recursion from the following grammar:
L → L,S | S
Determine whether a predictive parser can be constructed for this grammar or not. Also construct the parsing table.
Answer
Sign in to view the complete answer paper.
Compute LR(0) items for the following grammar and construct SLR parsing table:
L → *R | id
R → L
Answer
Sign in to view the complete answer paper.
Write a YACC program to evaluate arithmetic expressions.
Answer
Sign in to view the complete answer paper.
Write an algorithm for constructing LALR Parser table.
Answer
Sign in to view the complete answer paper.
Explain briefly various data structures used to implement the symbol table.
Answer
Sign in to view the complete answer paper.
Discuss various loop optimization and load optimization techniques with an illustrative example.
Answer
Sign in to view the complete answer paper.
Write the algorithm for gencode( ) procedure.
Answer
Sign in to view the complete answer paper.
Explain the following peephole optimization techniques:
i) Algebraic Specification
ii) Strength Reduction
Answer
Sign in to view the complete answer paper.
Explain the process of register allocation using graph coloring with an example.
Answer
Sign in to view the complete answer paper.