edited by
26,989 views
48 48 votes

Which of the following statements is false?

  1. An unambiguous grammar has same leftmost and rightmost derivation
  2. An LL(1) parser is a top-down parser
  3. LALR is more powerful than SLR
  4. An ambiguous grammar can never be LR(k) for any k

6 Answers

Best answer
60 60 votes

Correct Option: A
(A) We can not have different Left Most Derivation and Right Most Derivation parse trees BUT we can certainly have different LMD and RMD for a given string. (LMD and RMD here refer to the order of various productions used for derivation which could be different.)

(D) is wrong w.r.t. question because IT IS TRUE that any LR(k) IS NEVER AMBIGUOUS, so an ambiguous can never be an LR(K) for any k, no matter how large k becomes.

(B) and (C) can not be the answer because LL(1) is a top-down parser, and LALR is more powerful than SLR. So both are TRUE.

edited by
48 48 votes

A) An unambiguous grammar has same leftmost and rightmost derivation

This statement is false, let me take an example, suppose given unambiguous gammer is

S -> AB
A -> a
B -> b

Suppose our input string is ab

Left Most Derivation
S -> AB -> aB -> ab

Right Most Derivation
S -> AB -> Ab -> ab

Notice Left Most derivation and Right most derivation are not same, still gammer is unambiguous.

Here is the Derivation Tree

So for a given gammer, we can have same Left most derivation Tree and Right most derivation tree, but left most derivation and right most derivation may vary.

B) An LL(1) parser is a top-down parser : True

C) LALR is more powerful than SLR  : True

D) An ambiguous grammar can never be LR(k) for any k : True

So only False option is (a).

11 11 votes
We know that the LL(1) parser is top down parser. Option B is true.
Order of strength is LR < SLR < LALR.
So (B) and (C) are, true.
But an ambiguous grammar can’t be LR(K) for any K so option D is true.
So option (A) is false since an unambiguous grammar has unique right most derivation & left most derivations but both are not same.
Hence (A) is correct option
edited by
2 2 votes
0 0 votes
For option D

An ambiguous grammar can never be LR(k) for any k, because LR(k) algorithm aren’t designed to handle ambiguous grammars. It would get stuck into undecidability problem, if employed upon an ambiguous grammar, no matter how large the constant k is.
Answer:
Position:
Show:

Related questions

26 26 votes
3 answers 3 answers
5.9k
5.9k views
Kathleen asked Sep 14, 2014
5,926 views
Remove left-recursion from the following grammar: $S \rightarrow Sa \mid Sb \mid a \mid b$Consider the following grammar: $S \rightarrow aSbS\mid bSaS \mid \...
14 14 votes
2 answers 2 answers
3.4k
3.4k views
Kathleen asked Sep 14, 2014
3,354 views
The syntax of the repeat-until statement is given by the following grammar$S \rightarrow\text{ repeat }S_1\text{ until }E$where E stands for expressions, $S$ and $S_1$ st...
32 32 votes
2 answers 2 answers
7.4k
7.4k views
Kathleen asked Sep 14, 2014
7,425 views
Consider the following grammar with terminal alphabet $\Sigma =\{a,(,),+,* \}$ and start symbol $E$. The production rules of the grammar are:$ E \rightarrow aA$$ E \right...
99 99 votes
3 answers 3 answers
39.6k
39.6k views
Kathleen asked Sep 14, 2014
39,621 views
Consider the following three C functions:$[P1]$ int *g(void) { int x = 10; return (&x); }$[P2]$ int *g(void) { int *px; *px = 10; return px; }$[P3]$ int *g(void) { int *p...