- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 Articles
- Consider the ambiguous grammar.\nE → E + E\nE → E * E\nE → (E)\nE → id\n(a) Construct LR (0) items for above grammar.\n(b) Construct SLR parsing table for grammar.\n(c) Parse the input string id + id * id.
- Constructing LALR (1) Parsing table for a given grammar.\nProblem− Construct LALR (1) Parsing table for the grammar.\nS → A a|b A c|dc|bda\nA → d\nParse input string "bdc" using LALR Parsing Table.
- Construct a Predictive Parsing table for the following grammar & also check whether string \nid + id * id is accepted or not.
- Construct SLR (1) parsing table for the following grammar\nS → x A y |x B y |x A z\nA → q s | q\nB → q
- Verifying whether the string id * id + id is accepted by a given grammar using SLR parsing\nConsider the SLR parsing table for the Grammar\nE → E + T\nE → T\nT → T ∗ F\nT → F\nF → (E)\nF → id\nCheck whether the string id * id + id is accepted or not by using the SLR parsing table constructed in the example.
- Construct SLR (1) parsing table for the grammar\n1. E → E + T\n2. E → T\n3. T → T * F\n4. T → F\n5.F → (E)\n6.F → id
- Find Canonical Parsing Table (CLR) or LR (1) Parsing Table for Grammar.\nS → CC\nC → c C | d
- Consider the Grammar\nS → CC\nC → c C | d\nConstruct the parsing table for LALR (1) parser.
- Find FIRST & FOLLOW for the following Grammar.\nS → A a A | B b B\nA → b B\nB → ε
- Construct a histogram for the following data:\n
- Construct a ∈-NFA for the language L = (a* + b*)
- Construct a Finite Automata for the regular expression ((a+b)(a+b))*.
- Parse string date value input in Java
- Construct the derivation tree for the string aabbabba.
- Parse string date time value input in Java

Advertisements