With B.Tech AKTU Quantum Book, you can delve into the complexities of Compiler Design. Access key notes, frequently asked questions, and helpful insights for understanding this critical area. Unit-2 Basic Parsing Techniques
Dudes 🤔.. You want more useful details regarding this subject. Please keep in mind this as well. Important Questions For Compiler Design: *Quantum *B.tech-Syllabus *Circulars *B.tech AKTU RESULT * Btech 3rd Year * Aktu Solved Question Paper
Q1. Explain about basie parsing techniques. What is top-down parsing? Explain in detail.
Ans. A parser for any grammar is a program that takes as input string w and produces as output a parse tree for ω.
Role of parser:
- 1. The role of parsing is to determine the syntactic validity of a source string.
- 2. Parser helps to report any syntax errors and recover from those errors.
- 3. Parser helps to construct parse tree and passes it to rest of phases of compiler.
There are basically two type of parsing techniques:
- 1. Top-down parsing:
- a. Top-down parsing attempts to find the left-most derivation for an input string ω, that start from the root (or start symbol), and create the nodes in pre-defined order.
- b. In top-down parsing, the input string ω is scanned by the parser from left to right, one symbol token at a time.
- c. The left-most derivation generates the leaves of parse tree in left to right order, which matches to the input scan order.
- d. In the top-down parsing, parsing decisions are based on the lookahead symbol (or sequence of symbols).
- 2 Bottom-up parsing:
- a. Bottom-up parsing can be defined as an attempt to reduce the input string ω to the start symbol of a grammar by finding out the right most derivation of ω in reverse.
- b. Parsing involves searching for the substring that matches the right side of any of the productions of the grammar.
- c. This substring is replaced by the left hand side non-terminal of the production
- d. Process of replacing the right side of the production by the left side non-terminal is called “reduction”.
Q2. What are the common conflicts that can be encountered in shift-reduce parser ?
Ans. There are two most common conflict encountered in shift-reduce parser:
- 1. Shift-reduce conflict:
- a. The shift-reduce conflict is the most common type of conflict found in grammars.
- b. This conflict occurs because some production rule in the grammar is shifted and reduced for the particular token at the same time.
- c. This error is often caused by recursive grammar definitions where the system cannot determine when one rule is complete and another is just started.
- 2. Reduce-reduce conflict:
- a. A reduce-reduce conflict is caused when a grammar allows two or more different rules to be reduced at the same time, for the same token.
- b. When this happens, the grammar becomes ambiguous since a program can be interpreted more than one way.
- c. This error can be caused when the same rule is reached by more than one path.
Q3. Eliminate left recursion from the following grammar
![Eliminate left recursion from the following grammar](https://bachelorexam.com/wp-content/uploads/2023/10/image-284.png)
![Eliminate left recursion from the following grammar](https://bachelorexam.com/wp-content/uploads/2023/10/image-284.png)
Ans.
![Eliminate left recursion from the following grammar Compiler Design](https://bachelorexam.com/wp-content/uploads/2023/10/image-285.png)
![Eliminate left recursion from the following grammar Compiler Design](https://bachelorexam.com/wp-content/uploads/2023/10/image-285.png)
![Eliminate left recursion from the following grammar Btech Aktu](https://bachelorexam.com/wp-content/uploads/2023/10/image-286.png)
![Eliminate left recursion from the following grammar Btech Aktu](https://bachelorexam.com/wp-content/uploads/2023/10/image-286.png)
The production after left recursion is
![Eliminate left recursion from the following grammar Compiler Design Btech](https://bachelorexam.com/wp-content/uploads/2023/10/image-287.png)
![Eliminate left recursion from the following grammar Compiler Design Btech](https://bachelorexam.com/wp-content/uploads/2023/10/image-287.png)
![Eliminate left recursion from the following grammar Aktu Btech Compiler Design](https://bachelorexam.com/wp-content/uploads/2023/10/image-288.png)
![Eliminate left recursion from the following grammar Aktu Btech Compiler Design](https://bachelorexam.com/wp-content/uploads/2023/10/image-288.png)
Q4. Differentiate between top-down and bottom-up parser. Under which conditions predictive parsing can be constructed fora grammar ?
Ans.
S. No. | Top-down parser | Bottom-up parser |
1. | In top-down parser left recursion is done. | In bottom-up parser right-most derivation is done. |
2. | Backtracking is possible. | Backtracking is not possible. |
3. | In this, input token are popped off the stack. | In this, input token are pushed on the stack. |
4. | First and follow are defined in top-down parser. | First and follow are used in bottom-up parser. |
5. | Predictive parser and recursive descent parser are top-down parsing techniques. | Shift-reduce parser, operator precedence parser, and LR parser are bottom-up parsing technique. |
Predictive parsing can be constructed if the following condition holds:
- 1. Every grammar must be recursive in nature.
- 2. Each grammar must be left factored.
Q5. Construct an SLR(1) parsing table for the following grammar:
![Construct an SLR(1) parsing table for the following grammar:](https://bachelorexam.com/wp-content/uploads/2023/10/image-295.png)
![Construct an SLR(1) parsing table for the following grammar:](https://bachelorexam.com/wp-content/uploads/2023/10/image-295.png)
Ans. The augmented grammar G’ for the above grammar G is:
![Construct an SLR(1) parsing table for the following grammar: Compiler Design](https://bachelorexam.com/wp-content/uploads/2023/10/image-294.png)
![Construct an SLR(1) parsing table for the following grammar: Compiler Design](https://bachelorexam.com/wp-content/uploads/2023/10/image-294.png)
The canonical collection of sets of LR(0) item for grammar are as follows:
![Construct an SLR(1) parsing table for the following grammar: Compiler Design Aktu](https://bachelorexam.com/wp-content/uploads/2023/10/image-293.png)
![Construct an SLR(1) parsing table for the following grammar: Compiler Design Aktu](https://bachelorexam.com/wp-content/uploads/2023/10/image-293.png)
![Construct an SLR(1) parsing table for the following grammar: Compiler Design Btech](https://bachelorexam.com/wp-content/uploads/2023/10/image-292.png)
![Construct an SLR(1) parsing table for the following grammar: Compiler Design Btech](https://bachelorexam.com/wp-content/uploads/2023/10/image-292.png)
![Construct an SLR(1) parsing table for the following grammar: Compiler Design Aktu Btech](https://bachelorexam.com/wp-content/uploads/2023/10/image-291.png)
![Construct an SLR(1) parsing table for the following grammar: Compiler Design Aktu Btech](https://bachelorexam.com/wp-content/uploads/2023/10/image-291.png)
![Construct an SLR(1) parsing table for the following grammar: Compiler Design Aktu](https://bachelorexam.com/wp-content/uploads/2023/10/image-290.png)
![Construct an SLR(1) parsing table for the following grammar: Compiler Design Aktu](https://bachelorexam.com/wp-content/uploads/2023/10/image-290.png)
![Construct an SLR(1) parsing table for the following grammar: Aktu Btech Compiler Design](https://bachelorexam.com/wp-content/uploads/2023/10/image-289.png)
![Construct an SLR(1) parsing table for the following grammar: Aktu Btech Compiler Design](https://bachelorexam.com/wp-content/uploads/2023/10/image-289.png)
Q6. Eliminate left recursion from the following grammar S → (L) |aL → L, S|S
i. (a,(a, a)) ii. (a,a)
Ans. i.
![Eliminate left recursion from the following grammar S → (L) |aL → L, S|S Compiler Design](https://bachelorexam.com/wp-content/uploads/2023/10/image-296.png)
![Eliminate left recursion from the following grammar S → (L) |aL → L, S|S Compiler Design](https://bachelorexam.com/wp-content/uploads/2023/10/image-296.png)
ii.
![Eliminate left recursion from the following grammar S → (L) |aL → L, S|S Aktu Btech](https://bachelorexam.com/wp-content/uploads/2023/10/image-297.png)
![Eliminate left recursion from the following grammar S → (L) |aL → L, S|S Aktu Btech](https://bachelorexam.com/wp-content/uploads/2023/10/image-297.png)
![bachelor exam preparation all question paper with solution important questions with solution](http://bachelorexam.com/wp-content/uploads/2023/01/cute-teddy1.png)
![bachelor exam preparation all question paper with solution important questions with solution](http://bachelorexam.com/wp-content/uploads/2023/01/cute-teddy1.png)
Important Question with solutions | AKTU Quantums | Syllabus | Short Questions
Compiler Design Btech Quantum PDF, Syllabus, Important Questions
Label | Link |
---|---|
Subject Syllabus | Syllabus |
Short Questions | Short-question |
Question paper – 2021-22 | 2021-22 |
Compiler Design Quantum PDF | AKTU Quantum PDF:
Quantum Series | Links |
Quantum -2022-23 | 2022-23 |
AKTU Important Links | Btech Syllabus
Link Name | Links |
---|---|
Btech AKTU Circulars | Links |
Btech AKTU Syllabus | Links |
Btech AKTU Student Dashboard | Student Dashboard |
AKTU RESULT (One VIew) | Student Result |