# GATE | GATE CS 2008 | Question 55

An LALR(1) parser for a grammar G can have shift-reduce (S-R) conflicts if and only if

**(A)** the SLR(1) parser for G has S-R conflicts

**(B)** the LR(1) parser for G has S-R conflicts

**(C)** the LR(0) parser for G has S-R conflicts

**(D)** the LALR(1) parser for G has reduce-reduce conflicts

**Answer:** **(B)** **Explanation:**

Both LALR(1) and LR(1) parser uses LR(1) set of items to form their parsing tables. And LALR(1) states can be find by merging LR(1) states of LR(1) parser that have the same set of first components of their items.

i.e. if LR(1) parser has 2 states I and J with items A->a.bP,x and A->a.bP,y respectively, where x and y are look ahead symbols, then as these items are same with respect to their first component, they can be merged together and form one single state, let’s say K. Here we have to take union of look ahead symbols. After merging, State K will have one single item as A->a.bP,x,y . This way LALR(1) states are formed ( i.e. after merging the states of LR(1) ).

Now, S-R conflict in LR(1) items can be there whenever a state has items of the form :

A-> a.bB , p C-> d. , b i.e. it is getting both shift and reduce at symbol b, hence a conflict.

Now, as LALR(1) have items similar to LR(1) in terms of their first component, shift-reduce form will only take place if it is already there in LR(1) states. If there is no S-R conflict in LR(1) state it will never be reflected in the LALR(1) state obtained by combining LR(1) states.

Note: But this process of merging may introduce R-R conflict, and then the Grammar won’t be LALR(1).

Quiz of this Question

## Recommended Posts:

- GATE | GATE CS 2008 | Question 52
- GATE | GATE CS 2008 | Question 53
- GATE | GATE CS 2008 | Question 54
- GATE | GATE CS 2008 | Question 56
- GATE | GATE CS 2008 | Question 85
- GATE | GATE CS 2008 | Question 58
- GATE | GATE CS 2008 | Question 59
- GATE | GATE CS 2008 | Question 85
- GATE | GATE CS 2008 | Question 61
- GATE | GATE CS 2008 | Question 62
- GATE | GATE CS 2008 | Question 64
- GATE | GATE CS 2008 | Question 85
- GATE | Gate IT 2008 | Question 82
- GATE | Gate IT 2008 | Question 81
- GATE | GATE CS 2008 | Question 50