Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Questions  >  The grammar whose productions are-> if id... Start Learning for Free
The grammar whose productions are
-> if id then <stmt>
-> if id then <stmt> else <stmt>
-> id := id
is ambiguous because
  • a)
    the sentence
    if a then if b then c:= d
    has more than two parse trees
  • b)
    the left most and right most derivations of the sentence
    if a then if b then c:= d
    give rise to different parse trees
  • c)
    the sentence if a then
    if b then c:= d else c:= f
    has more than two parse trees
  • d)
    the sentenceif a then
    if b then c:= d else c:= f
    has two parse trees
Correct answer is option 'D'. Can you explain this answer?
Verified Answer
The grammar whose productions are-> if id then <stmt>->...
 if a then if b then c: = d else c:= f  has two parse trees as follows:
1. if a then (if b then c:= d) else c:= f 2. and if a then (if b then c:=d else c:= f)
View all questions of this test
Most Upvoted Answer
The grammar whose productions are-> if id then <stmt>->...
Explanation:
The given question is about an ambiguous grammar whose productions are:
1. if id then stmt
2. if id then stmt else stmt
3. id := id

Let's consider the sentence "if a then if b then c:= d else c:= f" to understand why the given grammar is ambiguous.

Definition of Ambiguity:
In the context of grammars, ambiguity refers to a situation where a single sentence can be parsed in more than one way, resulting in multiple parse trees.

Analysis:
When we apply the given grammar to the sentence "if a then if b then c:= d else c:= f", we can obtain two parse trees, which means the grammar is ambiguous.

Parse Tree 1:
if a then
/ \
if b then c := d
/ \
c := f NULL

Parse Tree 2:
if a then
/ \
if b then c := f
/ \
c := d NULL

Explanation:
In the given sentence, "if a then if b then c:= d else c:= f", we have two instances of the production "if id then stmt else stmt".

1. The leftmost derivation of the sentence would be:
- if a then if b then c:= d else c:= f
- if a then if b then c:= d else stmt
- if a then if b then c:= d else id := id
- if a then if b then c:= d else c:= f

2. The rightmost derivation of the sentence would be:
- if a then if b then c:= d else c:= f
- if a then if b then c:= d else stmt
- if a then if b then c:= d else id := id
- if a then if b then c:= f else id := id
- if a then if b then c:= f else c:= d

Thus, we can see that the leftmost and rightmost derivations of the sentence give rise to different parse trees, indicating the ambiguity of the grammar. Therefore, option 'D' is the correct answer.
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

The grammar whose productions are-> if id then <stmt>-> if id then <stmt> else <stmt>-> id := idis ambiguous becausea)the sentenceif a then if b then c:= dhas more than two parse treesb)the left most and right most derivations of the sentenceif a then if b then c:= dgive rise to different parse treesc)the sentenceif a thenif b then c:= d else c:= fhas more than two parse treesd)the sentenceif a thenif b then c:= d else c:= fhas two parse treesCorrect answer is option 'D'. Can you explain this answer?
Question Description
The grammar whose productions are-> if id then <stmt>-> if id then <stmt> else <stmt>-> id := idis ambiguous becausea)the sentenceif a then if b then c:= dhas more than two parse treesb)the left most and right most derivations of the sentenceif a then if b then c:= dgive rise to different parse treesc)the sentenceif a thenif b then c:= d else c:= fhas more than two parse treesd)the sentenceif a thenif b then c:= d else c:= fhas two parse treesCorrect answer is option 'D'. Can you explain this answer? for Computer Science Engineering (CSE) 2024 is part of Computer Science Engineering (CSE) preparation. The Question and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus. Information about The grammar whose productions are-> if id then <stmt>-> if id then <stmt> else <stmt>-> id := idis ambiguous becausea)the sentenceif a then if b then c:= dhas more than two parse treesb)the left most and right most derivations of the sentenceif a then if b then c:= dgive rise to different parse treesc)the sentenceif a thenif b then c:= d else c:= fhas more than two parse treesd)the sentenceif a thenif b then c:= d else c:= fhas two parse treesCorrect answer is option 'D'. Can you explain this answer? covers all topics & solutions for Computer Science Engineering (CSE) 2024 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for The grammar whose productions are-> if id then <stmt>-> if id then <stmt> else <stmt>-> id := idis ambiguous becausea)the sentenceif a then if b then c:= dhas more than two parse treesb)the left most and right most derivations of the sentenceif a then if b then c:= dgive rise to different parse treesc)the sentenceif a thenif b then c:= d else c:= fhas more than two parse treesd)the sentenceif a thenif b then c:= d else c:= fhas two parse treesCorrect answer is option 'D'. Can you explain this answer?.
Solutions for The grammar whose productions are-> if id then <stmt>-> if id then <stmt> else <stmt>-> id := idis ambiguous becausea)the sentenceif a then if b then c:= dhas more than two parse treesb)the left most and right most derivations of the sentenceif a then if b then c:= dgive rise to different parse treesc)the sentenceif a thenif b then c:= d else c:= fhas more than two parse treesd)the sentenceif a thenif b then c:= d else c:= fhas two parse treesCorrect answer is option 'D'. Can you explain this answer? in English & in Hindi are available as part of our courses for Computer Science Engineering (CSE). Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free.
Here you can find the meaning of The grammar whose productions are-> if id then <stmt>-> if id then <stmt> else <stmt>-> id := idis ambiguous becausea)the sentenceif a then if b then c:= dhas more than two parse treesb)the left most and right most derivations of the sentenceif a then if b then c:= dgive rise to different parse treesc)the sentenceif a thenif b then c:= d else c:= fhas more than two parse treesd)the sentenceif a thenif b then c:= d else c:= fhas two parse treesCorrect answer is option 'D'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of The grammar whose productions are-> if id then <stmt>-> if id then <stmt> else <stmt>-> id := idis ambiguous becausea)the sentenceif a then if b then c:= dhas more than two parse treesb)the left most and right most derivations of the sentenceif a then if b then c:= dgive rise to different parse treesc)the sentenceif a thenif b then c:= d else c:= fhas more than two parse treesd)the sentenceif a thenif b then c:= d else c:= fhas two parse treesCorrect answer is option 'D'. Can you explain this answer?, a detailed solution for The grammar whose productions are-> if id then <stmt>-> if id then <stmt> else <stmt>-> id := idis ambiguous becausea)the sentenceif a then if b then c:= dhas more than two parse treesb)the left most and right most derivations of the sentenceif a then if b then c:= dgive rise to different parse treesc)the sentenceif a thenif b then c:= d else c:= fhas more than two parse treesd)the sentenceif a thenif b then c:= d else c:= fhas two parse treesCorrect answer is option 'D'. Can you explain this answer? has been provided alongside types of The grammar whose productions are-> if id then <stmt>-> if id then <stmt> else <stmt>-> id := idis ambiguous becausea)the sentenceif a then if b then c:= dhas more than two parse treesb)the left most and right most derivations of the sentenceif a then if b then c:= dgive rise to different parse treesc)the sentenceif a thenif b then c:= d else c:= fhas more than two parse treesd)the sentenceif a thenif b then c:= d else c:= fhas two parse treesCorrect answer is option 'D'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice The grammar whose productions are-> if id then <stmt>-> if id then <stmt> else <stmt>-> id := idis ambiguous becausea)the sentenceif a then if b then c:= dhas more than two parse treesb)the left most and right most derivations of the sentenceif a then if b then c:= dgive rise to different parse treesc)the sentenceif a thenif b then c:= d else c:= fhas more than two parse treesd)the sentenceif a thenif b then c:= d else c:= fhas two parse treesCorrect answer is option 'D'. Can you explain this answer? tests, examples and also practice Computer Science Engineering (CSE) tests.
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Explore Courses
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev