

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Construct the SLR Parsing table for the following grammar. Also, Parse the input string a * b + a.
Description − Consider the Grammar
E → E + T|T
T → TF|F
F → F*|a|b.
Solution
Step1 − Construct the augmented grammar and number the productions.
(0) E′ → E
(1) E → E + T
(2) E → T
(3) T → TF
(4) T → F
(5) F → F ∗
(6) F → a
(7) F → b.
Step2 − Find closure & goto Functions to construct LR (0) items.
Box represents the New states, and the circle represents the Repeating State.
Computation of FOLLOW
We can find out
FOLLOW(E) = {+, $}
FOLLOW(T) = {+, a, b, $}
FOLLOW(F) = {+,*, a, b, $}
Parsing for Input String a * b + a −
Stack | Input String | Action |
---|---|---|
0 | a * b + a $ | Shift |
0 a 4 | * b + a $ | Reduce by F → a. |
0 F 3 | * b + a $ | Shift |
0 F 3 * 8 | b + a $ | Reduce by F → F ∗ |
0 F 3 | b + a $ | Reduce by T → F |
0 T 2 | b + a $ | Shift |
0 T 2 b 5 | +a $ | Reduce by F → b |
0 T 2 F 7 | +a $ | Reduce by T → TF |
0 T 2 | +a $ | Reduce by E → T |
0 E 1 | +a $ | Shift |
0 E 1 + 6 | a$ | Shift |
0 E 1 + 6 a 4 | $ | Reduce by F → a |
0 E 1 + 6 F 3 | $ | Reduce by T → F |
0 E 1 + 6 T 9 | $ | Reduce by E → E + T |
0 E 1 | $ | Accept |
- Related Questions & Answers
- Construct SLR (1) parsing table for the following grammar S → x A y |x B y |x A z A → q s | q B → q
- Construct a Predictive Parsing table for the following grammar & also check whether string id + id * id is accepted or not.
- Consider the ambiguous grammar. E → E + E E → E * E E → (E) E → id (a) Construct LR (0) items for above grammar. (b) Construct SLR parsing table for grammar. (c) Parse the input string id + id * id.
- Constructing LALR (1) Parsing table for a given grammar. Problem− Construct LALR (1) Parsing table for the grammar. S → A a|b A c|dc|bda A → d Parse input string "bdc" using LALR Parsing Table.
- Find FIRST & FOLLOW for the following Grammar. S → A a A | B b B A → b B B → ε
- Verifying whether the string id * id + id is accepted by a given grammar using SLR parsing Consider the SLR parsing table for the Grammar E → E + T E → T T → T ∗ F T → F F → (E) F → id Check whether the string id * id + id is accepted or not by using the SLR parsing table constructed in the example.
- Consider the Grammar S → CC C → c C | d Construct the parsing table for LALR (1) parser.
- Construct a Finite Automata for the regular expression ((a+b)(a+b))*.
- Show that the following grammar is LR (1) S → A a |b A c |B c | b B a A → d B → d
- Construct a ∈-NFA for the language L = (a* + b*)
- Construct Quadruples, Triples, and Indirect Triples for the expression -(a + b) * (c + d) - (a + b + c)
- Construct SLR (1) parsing table for the grammar 1. E → E + T 2. E → T 3. T → T * F 4. T → F 5.F → (E) 6.F → id
- Construct the derivation tree for the string aabbabba.
- 8085 program to implement the following function (a*b) + (c*d)
- Find Canonical Parsing Table (CLR) or LR (1) Parsing Table for Grammar. S → CC C → c C | d
Advertisements