JNTU
JNTU B.Tech III COMPILER DESIGN Previous Question Paper (October - 2020 - R13)
Answer any five questions. All questions carry equal marks.
Main
Write the need of dividing compilation process into various phases.
Answer
Dividing the compilation process into distinct phases is essential for managing the complexity of translating high-level source code into machine-executable code. This modular approach provides several key benefits:
- Simplicity and Manageability: Each phase handles a specific sub-task, such as lexical analysis, syntax analysis, or code generation, making the compiler easier to design, implement, and maintain.
- Portability: By separating the front-end (which deals with source language analysis) from the back-end (which deals with target machine code generation), the compiler can be retargeted to different machine architectures by replacing only the back-end phases.
- Optimization: Intermediate representations allow for machine-independent code optimizations to be performed effectively before translating to specific machine instructions.
- Error Detection and Reporting: Distinct phases allow for more precise identification of errors. Lexical errors are caught during scanning, syntax errors during parsing, and semantic errors during type checking, providing clearer feedback to the programmer.
- Efficiency: Modular design allows developers to optimize individual phases independently, improving the overall performance of the compilation process.
What is top down parsing? Explain difficulties arise in top down parsing.
Answer
Top-down parsing is a strategy where the parser attempts to construct a parse tree for the input string starting from the root (the start symbol) and working down to the leaves (the input tokens). It essentially performs a leftmost derivation of the input string.
Several difficulties arise in top-down parsing, primarily due to the limitations of predictive decision-making:
- Left Recursion: A grammar containing left-recursive productions (e.g., A → Aα | β) causes a top-down parser to enter an infinite loop, as it will repeatedly try to expand the same non-terminal without consuming any input.
- Backtracking: If a grammar is not predictive, the parser may choose the wrong production rule for a non-terminal. When it discovers that the chosen rule does not match the input, it must backtrack to a previous state and try an alternative, which is computationally expensive and inefficient.
- Left Factoring: When multiple productions for a non-terminal share a common prefix (e.g., A → αβ1 | αβ2), the parser cannot decide which rule to apply based on the current lookahead symbol. This ambiguity requires the grammar to be transformed to defer the decision until the common prefix is processed.
- Lookahead Limitations: Basic top-down parsers (like LL(1)) are restricted by the amount of lookahead available. If a grammar requires looking ahead more than one token to distinguish between productions, standard predictive parsing techniques fail.
Discuss about error handling mechanism in lexical analyzer.
Answer
Sign in to view the complete answer paper.
Write predicative parsing algorithm and construct parsing table the input id+id*id for the following grammar.
Answer
Sign in to view the complete answer paper.
Write LR parsing algorithm.
Answer
Sign in to view the complete answer paper.
Check the following grammar is SLR or not.
Answer
Sign in to view the complete answer paper.
Explain the steps in SLR parser construction.
Answer
Sign in to view the complete answer paper.
What is ambiguous grammar? How do you eliminate ambiguity in grammar?
Answer
Sign in to view the complete answer paper.
Explain heap storage allocation strategy.
Answer
Sign in to view the complete answer paper.
Explain three address codes and illustrate with examples.
Answer
Sign in to view the complete answer paper.
Explain different data structures used for constructing symbol table.
Answer
Sign in to view the complete answer paper.
Explain loop optimization techniques and illustrate with examples.
Answer
Sign in to view the complete answer paper.
Compare reducible Vs non reducible flow graphs.
Answer
Sign in to view the complete answer paper.
Construct DAG for a sub expression.
Answer
Sign in to view the complete answer paper.
Write the procedure for generating code from DAG and explain with example.
Answer
Sign in to view the complete answer paper.