- 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

# Show that the following grammar is LR (1) S → A a |b A c |B c | b B a A → d B → d

**Solution**

**Step1** − Construct Augment Grammar

(0) S′ → S

(1) S → A a

(2) S → b A c

(3) S → B c

(4) S → b B a

(5) A → d

(6) B → d

**Step2** − Find Closure & goto. Construct a set of LR (1) items. Here all the boxes represent new states.

**LR (1) Parsing Table**

So, the LR (1) Parsing Table has no several entries. Grammar is LR (1).

**Construction of LR (1) or Canonical LR Parsing Table**

**Input** − An Augmented Grammar G’.

**Output** − The Canonical LR (1) Parsing Table

**Method**

**Filling the "shift" Entries(s) − Apply Rule (2a) of construction of CLR Parsing Table.**

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

∴ Action[0, c] = shift 3

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

Similarly, consider another entry.

i.e., I_{7} = goto(I2, d)

∴ Action[2, d] = shift 7

∴ Write s7 in front of Row State 2 and column d. Similarly, other entries of shift are filled onto the Action table.

**Filling the "reduce" Entries (r)**

Apply rule (2b) of construction of CLR parsing Table. Consider productions of the form A → α ∙ , a

For example, Consider

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

C → d ∙, c | d

Here, C → d ∙, c | d is of form A → α ∙ , a. So, set Action [4, c] and Action [4, d] to r3.

Since C → d is production number 3 in the given Question.

∴ Write r3 in front of Row State 4 and column c and d.

Because c, d looks ahead symbols in production C → d ∙ , c | d.

Consider another example

I_{9} = goto(I_{9}, C)

C → c C ∙, $

Since C → c C is production number (2) in the given question.

∴ Write r2 in front of Row State 9 and column $, because $ is the lookahead symbol attached to the production.

∴ Action [9, $] = r2

Similarly, fill all entries of reducing into the Parsing Table.

**Filling of goto Entries**

In goto, only Non-Terminal are seen column-wise,

For example

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

∴ Action [3, C] = 8

i.e., write 8 in front of Row state 3 and column C.

**Filling of "accept" Entry**

Apply Rule (2c) of CLR Parsing Table

Find the state in which production of form S′ → S ∙, $ lies

∴ It is state I_{1}

∴ Write accept in front of Row state 1 & column $.

- Related Questions & Answers
- Find FIRST & FOLLOW for the following Grammar. S → A a A | B b B A → b B B → ε
- Find four elements a, b, c and d in an array such that a+b = c+d in C++
- 8085 program to implement the following function (a*b) + (c*d)
- Larger of a^b or b^a in C++
- Count number of pairs (A <= N, B <= N) such that gcd (A , B) is B in C++
- Construct Quadruples, Triples, and Indirect Triples for the expression -(a + b) * (c + d) - (a + b + c)
- Python a += b is not always a = a + b
- Count number of triplets (a, b, c) such that a^2 + b^2 = c^2 and 1<=a<=b<=c<= n in C++
- 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
- Show that the whole compilation process for statement A = B * C + 20, where A, B, C are of real types
- Find a palindromic string B such that given String A is a subsequence of B in C++
- Find largest d in array such that a + b + c = d in C++
- Find all pairs (a, b) in an array such that a % b = k in C++
- C Program to construct DFA for Regular Expression (a+aa*b)*
- Construct a Finite Automata for the regular expression ((a+b)(a+b))*.