JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD
JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD B.Tech III COMPILER DESIGN Previous Question Paper (January/February - 2021 - R16)
Answer any five questions. All questions carry equal marks.
Main
Give the structure of a compiler and explain various phases of compilation.
Answer
A compiler is a complex software system that translates source code written in a high-level programming language into target machine code. The compilation process is organized into two main parts: the Analysis phase (front-end), which breaks the source program into constituent parts and creates an intermediate representation, and the Synthesis phase (back-end), which constructs the target program from the intermediate representation.
The phases of compilation are as follows:
- Lexical Analysis (Scanning): The lexer reads the stream of characters from the source code and groups them into meaningful sequences called lexemes, which are then categorized into tokens (e.g., keywords, identifiers, operators).
- Syntax Analysis (Parsing): The parser takes the tokens and arranges them into a hierarchical structure, typically a Syntax Tree or Abstract Syntax Tree (AST), to ensure the code adheres to the grammatical rules of the language.
- Semantic Analysis: This phase checks the source program for semantic consistency, such as type checking (ensuring operands are compatible with operators) and scope resolution.
- Intermediate Code Generation: The compiler generates a machine-independent intermediate representation, such as Three-Address Code, which facilitates optimization and simplifies the translation to different target architectures.
- Code Optimization: This phase improves the intermediate code to produce a more efficient target program, focusing on reducing execution time and memory usage without altering the program's meaning.
- Code Generation: The final phase maps the optimized intermediate code into the target machine language or assembly code, involving register allocation and instruction selection.
Additionally, the Symbol Table Manager and Error Handler interact with all phases to maintain information about identifiers and report syntax or semantic errors encountered during the process.
Compute Firsts and Follows and construct LL(1) parser table for the following grammar after eliminating ambiguity.
Answer
The given grammar is ambiguous due to left recursion and operator precedence issues. To construct an LL(1) parser, we must first eliminate ambiguity and left recursion. The transformed grammar is:
R' → +TR' | *TR' | /TR' | ε
T → (R) | id
First and Follow Sets:
| Non-Terminal | First | Follow |
|---|---|---|
| R | {(, id} | {$, ), +, *, /} |
| R' | {+, *, /, ε} | {$, )} |
| T | {(, id} | {+, *, /, $, )} |
LL(1) Parsing Table:
| id | + | * | / | ( | ) | $ | |
|---|---|---|---|---|---|---|---|
| R | R → TR' | R → TR' | |||||
| R' | R' → +TR' | R' → *TR' | R' → /TR' | R' → ε | R' → ε | ||
| T | T → id | T → (R) |
How are inherited attributes differ from synthesized attributes?
Answer
Sign in to view the complete answer paper.
Construct the SDD to convert infix notation to postfix notation.
Answer
Sign in to view the complete answer paper.
What is a type checker? Give the specification of a simple type checker.
Answer
Sign in to view the complete answer paper.
Write the quadruples, triples and indirect triples for the expression:
Answer
Sign in to view the complete answer paper.
Explain various storage allocation strategies and also mention their merits and demerits.
Answer
Sign in to view the complete answer paper.
What is a Basic Block? How to construct a Basic block?
Answer
Sign in to view the complete answer paper.
Explain Peephole optimization with an illustrative example.
Answer
Sign in to view the complete answer paper.
Explain the principal sources of code optimization with merits and demerits of each.
Answer
Sign in to view the complete answer paper.
Explain the following:
Basic elements of Data-Flow Analysis.
Answer
Sign in to view the complete answer paper.
Register Allocation.
Answer
Sign in to view the complete answer paper.