- 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 I_{3} and I_{6} can be merged because they have the same core or first component but a different second component of Look Ahead.

Similarly, states I_{4} and I_{7} are the same.

Similarly, states I_{8} and I_{9} are the same.

So, I_{3} and I_{6} can be combined to make I_{36}.

I_{4} and I_{7} combined to make I_{47}.

I_{8} and I_{9} combined to make I_{89}.

So, the states will be

∴ I_{3} = goto (I_{0}, c)

But I_{3} , I_{6} combined to make I_{36}

∴ I_{36} = goto (I_{0}, c)

∴ I_{4} = goto (I_{0}, d)

But I_{4} , I_{7} combined to make I_{47}

∴ I_{47} = goto (I_{0}, d)

∴ I_{6} = goto (I_{2}, c)

∴ I_{36} = goto (I_{2}, c)

∴ I_{7} = goto (I_{2}, d)

∴ I_{47} = goto (I_{2}, d)

∴ goto (I_{3}, C) = I_{8}

But I_{8} is now part of I_{89}

∴ goto (I_{36}, C) = I_{89}

Similarly,goto (I_{3}, d) = I_{4}, goto (I_{6}, d) = I_{7} ∴ goto (I_{36}, d) = I_{47}

**Construction of LALR Parsing Table**

**Filling of "𝐬𝐡𝐢𝐟𝐭" Entries(s)**

Consider goto(I_{0}, c) = I_{36}

∴ Action[0, c] = s36

∴ Write s36 in front of Row state 0 and column c.

Similarly, consider

goto(I_{2}, d) = I_{47}

∴ 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

I_{47} = goto(I_{0}, 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(I_{0}, S) = I_{1}

∴ goto [0, S] = 1

**Filling of "𝐀𝐜𝐜𝐞𝐩𝐭" Entry**

Since, S′ → S ∙ , $ is in I_{1}

∴ 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++