Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Questions  >  Consider the context-free grammar E → E... Start Learning for Free
Consider the context-free grammar E → E + E E → (E * E) E → id
where E is the starting symbol, the set of terminals is {id, (,+,),*}, and the set of nonterminals is {E}.
Q. Which of the following terminal strings has more than one parse tree when parsed according to the above grammar?
  • a)
    id + id + id + id
  • b)
    id + (id* (id * id))
  • c)
    (id* (id * id)) + id
  • d)
    ((id * id + id) * id)
Correct answer is option 'A'. Can you explain this answer?
Verified Answer
Consider the context-free grammar E → E + E E → (E * E) E ...
According to leftmost derivation : 
E -> E + E (using E -> E + E) E -> E + E + E (using E -> E + E) E -> E + E + E + E (using E -> E + id) E -> id + E + E + E (using E -> id) E -> id + id + E + E (using E -> id) E -> id + id + id + E (using E -> id) E -> id + id + id + id 
 
According to rightmost derivation : 
E -> E + E (using E -> E + E) E -> E + E + E (using E -> E + E) E -> E + E + E + E (using E -> E + id) E -> E + E + E + id (using E -> id) E -> E + E + id + id (using E -> id) E -> E + id + id + E (using E -> id) E -> id + id + id + id 
 
Thus, option (A) is correct. 
 
Please comment below if you find anything wrong in the above post.
View all questions of this test
Most Upvoted Answer
Consider the context-free grammar E → E + E E → (E * E) E ...
Explanation:

The given context-free grammar consists of one nonterminal symbol E and four terminal symbols {id, (, ), *}.

The production rules of the grammar are:
1. E -> E E
2. E -> (E * E)
3. E -> id

The goal is to find a terminal string that has more than one parse tree when parsed according to the given grammar.

Parsing process:

Parsing is the process of analyzing a string of symbols according to the rules of a formal grammar.

To determine if a terminal string has more than one parse tree, we need to analyze the possible derivations of the string using the production rules of the grammar.

Let's analyze the given terminal strings:

a) id id id id

This string can be derived in multiple ways:
- E -> E E -> id E -> id id
- E -> E E -> E E E -> id E E -> id id E
- E -> E E -> E E E -> E E E E -> id E E E -> id id E E -> id id id

Therefore, the terminal string "id id id id" has multiple parse trees.

b) id (id* (id * id))

This string can be derived in only one way:
- E -> (E * E) -> (E * E) -> id * (E * E) -> id * (E * E) -> id * (id * (E * E)) -> id * (id * (id * (E * E))) -> id * (id * (id * id))

Therefore, the terminal string "id (id* (id * id))" has only one parse tree.

c) (id* (id * id)) id

This string can be derived in only one way:
- E -> (E * E) -> (E * E) -> (id * E) * E -> (id * (E * E)) * E -> (id * (id * E)) * E -> (id * (id * id)) * E -> (id * (id * id)) * id

Therefore, the terminal string "(id* (id * id)) id" has only one parse tree.

d) ((id * id id) * id)

This string can be derived in multiple ways:
- E -> (E * E) -> (E * E) -> (E * id) * E -> (E * id) * (E * E) -> (E * id) * (E * id) * E -> (E * id) * (E * id) * id -> (E * id) * (id * id) * id
- E -> (E * E) -> (E * E) -> (id * E) * E -> (id * (E * E)) * E -> (id * (E * id)) * E -> (id * (id * E)) * E -> (id * (id * id)) * E -> (id * (id * id)) * id

Therefore, the terminal string "((id * id id) * id)" has multiple parse trees.

Conclusion:

Among the given terminal strings, only the string "id id id id" has more than one parse tree when parsed according to the given grammar.
Explore Courses for Computer Science Engineering (CSE) exam

Similar Computer Science Engineering (CSE) Doubts

Top Courses for Computer Science Engineering (CSE)

Consider the context-free grammar E → E + E E → (E * E) E → idwhere E is the starting symbol, the set of terminals is {id, (,+,),*}, and the set of nonterminals is {E}.Q. Which of the following terminal strings has more than one parse tree when parsed according to the above grammar?a)id + id + id + idb)id + (id* (id * id))c)(id* (id * id)) + idd)((id * id + id) * id)Correct answer is option 'A'. Can you explain this answer?
Question Description
Consider the context-free grammar E → E + E E → (E * E) E → idwhere E is the starting symbol, the set of terminals is {id, (,+,),*}, and the set of nonterminals is {E}.Q. Which of the following terminal strings has more than one parse tree when parsed according to the above grammar?a)id + id + id + idb)id + (id* (id * id))c)(id* (id * id)) + idd)((id * id + id) * id)Correct answer is option 'A'. 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 Consider the context-free grammar E → E + E E → (E * E) E → idwhere E is the starting symbol, the set of terminals is {id, (,+,),*}, and the set of nonterminals is {E}.Q. Which of the following terminal strings has more than one parse tree when parsed according to the above grammar?a)id + id + id + idb)id + (id* (id * id))c)(id* (id * id)) + idd)((id * id + id) * id)Correct answer is option 'A'. 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 Consider the context-free grammar E → E + E E → (E * E) E → idwhere E is the starting symbol, the set of terminals is {id, (,+,),*}, and the set of nonterminals is {E}.Q. Which of the following terminal strings has more than one parse tree when parsed according to the above grammar?a)id + id + id + idb)id + (id* (id * id))c)(id* (id * id)) + idd)((id * id + id) * id)Correct answer is option 'A'. Can you explain this answer?.
Solutions for Consider the context-free grammar E → E + E E → (E * E) E → idwhere E is the starting symbol, the set of terminals is {id, (,+,),*}, and the set of nonterminals is {E}.Q. Which of the following terminal strings has more than one parse tree when parsed according to the above grammar?a)id + id + id + idb)id + (id* (id * id))c)(id* (id * id)) + idd)((id * id + id) * id)Correct answer is option 'A'. 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 Consider the context-free grammar E → E + E E → (E * E) E → idwhere E is the starting symbol, the set of terminals is {id, (,+,),*}, and the set of nonterminals is {E}.Q. Which of the following terminal strings has more than one parse tree when parsed according to the above grammar?a)id + id + id + idb)id + (id* (id * id))c)(id* (id * id)) + idd)((id * id + id) * id)Correct answer is option 'A'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of Consider the context-free grammar E → E + E E → (E * E) E → idwhere E is the starting symbol, the set of terminals is {id, (,+,),*}, and the set of nonterminals is {E}.Q. Which of the following terminal strings has more than one parse tree when parsed according to the above grammar?a)id + id + id + idb)id + (id* (id * id))c)(id* (id * id)) + idd)((id * id + id) * id)Correct answer is option 'A'. Can you explain this answer?, a detailed solution for Consider the context-free grammar E → E + E E → (E * E) E → idwhere E is the starting symbol, the set of terminals is {id, (,+,),*}, and the set of nonterminals is {E}.Q. Which of the following terminal strings has more than one parse tree when parsed according to the above grammar?a)id + id + id + idb)id + (id* (id * id))c)(id* (id * id)) + idd)((id * id + id) * id)Correct answer is option 'A'. Can you explain this answer? has been provided alongside types of Consider the context-free grammar E → E + E E → (E * E) E → idwhere E is the starting symbol, the set of terminals is {id, (,+,),*}, and the set of nonterminals is {E}.Q. Which of the following terminal strings has more than one parse tree when parsed according to the above grammar?a)id + id + id + idb)id + (id* (id * id))c)(id* (id * id)) + idd)((id * id + id) * id)Correct answer is option 'A'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice Consider the context-free grammar E → E + E E → (E * E) E → idwhere E is the starting symbol, the set of terminals is {id, (,+,),*}, and the set of nonterminals is {E}.Q. Which of the following terminal strings has more than one parse tree when parsed according to the above grammar?a)id + id + id + idb)id + (id* (id * id))c)(id* (id * id)) + idd)((id * id + id) * id)Correct answer is option 'A'. 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