- 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
Consider the GrammarnS → CCnC → c C | dnConstruct the parsing table for LALR (1) parser.
Solution
Step1 − Construct LR (1) Set of items. First of all, all the LR (1) set of items should be generated.
In these states, states I3 and I6 can be merged because they have the same core or first component but a different second component of Look Ahead.
Similarly, states I4 and I7 are the same.
Similarly, states I8 and I9 are the same.
So, I3 and I6 can be combined to make I36.
I4 and I7 combined to make I47.
I8 and I9 combined to make I89.
So, the states will be
∴ I3 = goto (I0, c)
But I3 , I6 combined to make I36
∴ I36 = goto (I0, c)
∴ I4 = goto (I0, d)
But I4 , I7 combined to make I47
∴ I47 = goto (I0, d)
∴ I6 = goto (I2, c)
∴ I36 = goto (I2, c)
∴ I7 = goto (I2, d)
∴ I47 = goto (I2, d)
∴ goto (I3, C) = I8
But I8 is now part of I89
∴ goto (I36, C) = I89
Similarly,goto (I3, d) = I4, goto (I6, d) = I7 ∴ goto (I36, d) = I47
Construction of LALR Parsing Table
Filling of "𝐬𝐡𝐢𝐟𝐭" Entries(s)
Consider goto(I0, c) = I36
∴ Action[0, c] = s36
∴ Write s36 in front of Row state 0 and column c.
Similarly, consider
goto(I2, d) = I47
∴ Action[2, d] = 47
∴ Write s47 in front of Row State 2 and column d.
Filling the "𝐫𝐞𝐝𝐮𝐜𝐞" Entries (r)
Consider productions of the form A → α ∙ ,
For example, Consider State
I47 = goto(I0, d)
C → d ∙, c |d |$
∴ C → d ∙, c |d |$ is of form A → α ∙ , a.
Since C → d is production number (3) in given Question.
∴ Write r3 in front of Row State 47 and column c, d, $.
Because c, d looks ahead symbols in production C → d ∙ , c | d.
Filling of goto Entries
It can found out only for Non-Terminal.
For example, Consider
goto(I0, S) = I1
∴ goto [0, S] = 1
Filling of "𝐀𝐜𝐜𝐞𝐩𝐭" Entry
Since, S′ → S ∙ , $ is in I1
∴ Write accept in front of Row state 1 & column $.
LALR Parsing table can also be obtained by merging the rows of combined states of CLR parsing, i.e., Merge Row corresponding to 3, 6, then 4, 7 and then 8, 9.
The resulting LALR Parsing table will be −
- Related Articles
- 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.
- Find Canonical Parsing Table (CLR) or LR (1) Parsing Table for Grammar.\nS → CC\nC → c C | d
- 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.
- What is LALR (1) Parser?
- Construct the SLR Parsing table for the following grammar. Also, Parse the input string a * b + a.
- 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
- 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 grammar\n1. E → E + T\n2. E → T\n3. T → T * F\n4. T → F\n5.F → (E)\n6.F → id
- What is the difference between SLR, CLR, and LALR Parser in compiler design?
- Show that the following grammar is LR (1)\nS → A a |b A c |B c | b B a\nA → d\nB → d
- Construct Quadruples, Triples, and Indirect Triples for the expression\n-(a + b) * (c + d) - (a + b + c)
- What are the default rules used by the parser for parsing names of built-in functions?
- C-style parser for command line options in Python
- Ternary Expression Parser in C++
- HTML Entity Parser in C++
