Ambiguity in grammars MCQs

By: Prof. Dr. Fazal Rehman Shamil | Last updated: September 23, 2024

MCQs on Ambiguity in Grammars
What does it mean for a grammar to be ambiguous?

A) It has more than one production rule for each non-terminal symbol.
B) It generates an infinite number of strings.
C) It can derive at least one string in more than one way.
D) It has no start symbol.
Answer: C) It can derive at least one string in more than one way.

Which of the following statements about ambiguous grammars is true?

A) An ambiguous grammar always leads to an infinite number of strings.
B) An ambiguous grammar cannot be parsed.
C) Ambiguity in grammars can lead to multiple parse trees for a single sentence.
D) Ambiguity in grammars is necessary for them to be context-free.
Answer: C) Ambiguity in grammars can lead to multiple parse trees for a single sentence.

Which type of ambiguity involves different interpretations of the meaning of a sentence?

A) Syntactic ambiguity
B) Semantic ambiguity
C) Lexical ambiguity
D) Structural ambiguity
Answer: B) Semantic ambiguity

In context-free grammars, ambiguity is primarily related to:

A) The number of production rules.
B) The structure of parse trees.
C) The use of epsilon productions.
D) The number of terminals and non-terminals.
Answer: B) The structure of parse trees.

Which of the following methods is used to resolve ambiguity in grammars?

A) Adding more production rules
B) Revising the grammar to include more non-terminals
C) Restructuring the grammar to ensure a unique parse tree for each sentence
D) Increasing the number of terminals in the language
Answer: C) Restructuring the grammar to ensure a unique parse tree for each sentence

True or False: Every ambiguous grammar can be converted into an unambiguous grammar.

A) True
B) False
Answer: A) True

Which of the following languages cannot be generated by an unambiguous grammar?

A)
{
𝑎
𝑛
𝑏
𝑛

𝑛

0
}
{a
n
b
n
∣n≥0}
B)
{
𝑎
𝑛
𝑏
𝑚

𝑛
,
𝑚

0
}
{a
n
b
m
∣n,m≥0}
C)
{
𝑎

𝑏

}
{a

b

}
D)
{
𝑎
𝑛

𝑛

0
}
{a
n
∣n≥0}
Answer: A)
{
𝑎
𝑛
𝑏
𝑛

𝑛

0
}
{a
n
b
n
∣n≥0}

Which of the following statements is NOT true about ambiguity in grammars?

A) Ambiguity can lead to multiple interpretations of a sentence.
B) Ambiguity is always desirable in language processing.
C) Ambiguity can arise in both natural and formal languages.
D) Ambiguity can complicate language parsing.
Answer: B) Ambiguity is always desirable in language processing.

Which type of ambiguity in grammars involves multiple ways of interpreting the syntactic structure of a sentence?

A) Lexical ambiguity
B) Syntactic ambiguity
C) Semantic ambiguity
D) Structural ambiguity
Answer: B) Syntactic ambiguity

In the context of programming languages, why is ambiguity in grammars particularly problematic?

A) It leads to faster compilation times.
B) It can cause unintended behavior and errors during parsing.
C) It simplifies the process of writing code.
D) It ensures compatibility with older programming standards.
Answer: B) It can cause unintended behavior and errors during parsing.

These questions cover various aspects of ambiguity in grammars, including types of ambiguity, implications for parsing, and methods to address ambiguity.