Consider the following grammar G: P → Q + R | Q – R | Q | R Q → q | r R → r | s where P, Q, and R are non-terminal symbols, and q, r, and s are terminal symbols. Which of the following statement(s) is/are correct? S1. LL(1) can parse all strings that are generated using grammar G S2. LR(1) can parse all strings that are generated using grammar G

Consider the following grammar G: P → Q + R | Q – R | Q | R Q → q | r R → r | s where P, Q, and R are non-terminal symbols, and q, r, and s are terminal symbols. Which of the following statement(s) is/are correct? S1. LL(1) can parse all strings that are generated using grammar G S2. LR(1) can parse all strings that are generated using grammar G Correct Answer Neither S1 nor S2

The correct answer is option 1.

Concept:

LL(1) parser:

A top-down parser that uses a one-token lookahead is called an LL(1) parser. The first L indicates that the input is read from left to right. The second L says that it produces a left-to-right derivation.

LR(1) parser:

a canonical LR parser or LR(1) parser is an LR(k) parser for k=1, i.e. with a single lookahead terminal. The special attribute of this parser is that any LR(k) grammar with k>1 can be transformed into an LR(1) grammar. LR(k) can handle all deterministic context-free languages.

P → Q + R / Q - R / Q / R

Q → q/r

R → r/s

First

Follow

 

{a, r, s}

$

P

{a, r}

+, -, $

Q

{r, s}

$

R

 

 

$

+

-

q

r

S

P

 

 

 

P → Q + R

P → Q – R

P → Q

P → Q + R

P → Q – R

P → Q

P → R

P → R

Q

 

 

 

Q → q

 

 

R

 

 

 

 

 

R → S

 

 

I0

P’ → .P, $

P → .Q + R, $

P → .Q – R, $

P → .Q, $

P → .R, $

Q → .q, +/-/$

Q → .r, +/-/$

R → .r, $

R → .s, $

P

Q

R

q

r

I1

I2

I3

I4

 

P’ → P.$

P → Q. + R, $

P → Q. – R, $

P → Q. , $

P → R., $

Q →q., +/-/$

Q → r., +/-/$

R → r., $

 

conflict operation on non terminal $

So Not LR(1)

or 

CLR (1)

Hence the correct answer is Neither S1 nor S2.

Related Questions

A polypeptide chain contains two terminals – one carboxyl-terminal (C terminal) and the other amino-terminal (N terminal). Which of the following is true?