JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD
JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD B.Tech III COMPILER DESIGN Previous Question Paper (August/September - 2021 - R18)
Answer any five questions. All questions carry equal marks.
Main
State the reasons for separating Lexical analysis and Syntax analysis.
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.
Discuss how Finite Automata is used to recognize tokens and perform lexical analysis with example.
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'.
How to specify the Tokens? Differentiate Token, Lexeme and Pattern with suitable examples.
Answer
Sign in to view the complete answer paper.
Explain various Error Recovery strategies in Lexical analysis.
Answer
Sign in to view the complete answer paper.
What do you mean by Ambiguous Grammar? Check whether the following grammar is Ambiguous or not:
Answer
Sign in to view the complete answer paper.
Write a note on Yacc.
Answer
Sign in to view the complete answer paper.
Construct CLR parsing table for the following Grammar:
(Write all necessary procedures).
Answer
Sign in to view the complete answer paper.
Give Syntax Directed Translation scheme for Simple Desk Circulator.
Answer
Sign in to view the complete answer paper.
Convert the following arithmetic expression into Syntax Tree and Three Address Code:
Answer
Sign in to view the complete answer paper.
Differentiate Synthesized and Inherited Attributes with example.
Answer
Sign in to view the complete answer paper.
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.
Answer
Sign in to view the complete answer paper.
What is Flow-Graph? Explain how the given program can be converted into Flow-Graph?
Answer
Sign in to view the complete answer paper.
Construct DAG for the following basic block:
Answer
Sign in to view the complete answer paper.
“Copy propagation Leads to Dead code” - Justify the statement.
Answer
Sign in to view the complete answer paper.
Explain Global Data Flow analysis with necessary equations.
Answer
Sign in to view the complete answer paper.