0% found this document useful (0 votes)
25 views5 pages

MCQ'S

The document contains multiple-choice questions and answers related to Context-Free Grammar (CFG) and Parsing. It covers topics such as CFG components, derivation, ambiguity, associativity, recursion, elimination of left recursion, and various types of parsers including LL(1) parsing. Each section includes questions that test knowledge on the respective topics with correct answers provided.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views5 pages

MCQ'S

The document contains multiple-choice questions and answers related to Context-Free Grammar (CFG) and Parsing. It covers topics such as CFG components, derivation, ambiguity, associativity, recursion, elimination of left recursion, and various types of parsers including LL(1) parsing. Each section includes questions that test knowledge on the respective topics with correct answers provided.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Here are potential multiple-choice questions (MCQs) with answers for the topics listed:

1. Context-Free Grammar (CFG)


a. Introduction to CFG

Q1: What does a context-free grammar consist of?


a) Terminals
b) Non-terminals
c) Productions
d) All of the above
Answer: d) All of the above

Q2: Which of the following is a terminal?


a) AA
b) SS
c) aa
d) BB
Answer: c) aa

b. Derivation of CFG

Q3: In CFG, what is the process of generating strings called?


a) Parsing
b) Derivation
c) Compilation
d) Execution
Answer: b) Derivation

Q4: Which derivation generates a string step by step from leftmost non-terminal?
a) Leftmost derivation
b) Rightmost derivation
c) Ambiguous derivation
d) Precedence derivation
Answer: a) Leftmost derivation

c. Ambiguity in CFG

Q5: A grammar is ambiguous if:


a) It generates infinite strings
b) A string has more than one derivation tree
c) It has left recursion
d) It cannot generate a string
Answer: b) A string has more than one derivation tree

Q6: Which of the following is true for an unambiguous grammar?


a) It can have multiple parse trees for one string.
b) It has only one parse tree for every string.
c) It does not generate all strings of the language.
d) It cannot be converted into LL(1).
Answer: b) It has only one parse tree for every string.

d. Associativity & Precedence Problems

Q7: In the expression a+b×ca + b \times c, which operator is evaluated first if no parentheses are
given?
a) +
b) *
c) Both simultaneously
d) Depends on grammar
Answer: b) *

Q8: Left-associativity means:


a) Operations are grouped from right to left
b) Operations are grouped from left to right
c) Operators with higher precedence are evaluated first
d) None of the above
Answer: b) Operations are grouped from left to right

e. Recursion in CFG

Q9: What type of recursion occurs when a non-terminal appears on the leftmost side of its
production?
a) Right recursion
b) Indirect recursion
c) Left recursion
d) None of the above
Answer: c) Left recursion

Q10: Which of the following grammars is recursive?


a) A→BcA \rightarrow Bc
b) A→Aa∣bA \rightarrow Aa | b
c) A→aA \rightarrow a
d) None of the above
Answer: b) A→Aa∣bA \rightarrow Aa | b

f. Elimination of Left Recursion

Q11: Which of the following is the correct way to eliminate left recursion?
a) Remove the recursive rule entirely
b) Rewrite the grammar using new non-terminals
c) Use ambiguous grammar
d) None of the above
Answer: b) Rewrite the grammar using new non-terminals

2. Parsing
a. Introduction to Parsers

Q12: A parser is used to:


a) Generate tokens from input
b) Check the syntax of input against grammar
c) Optimize the code
d) Generate machine code
Answer: b) Check the syntax of input against grammar

Q13: What is the output of a parser?


a) Syntax tree
b) Tokens
c) Machine code
d) Assembly code
Answer: a) Syntax tree

b. Types of Parsers

Q14: Which parser starts with the input symbols and works backwards to derive the start
symbol?
a) Top-down parser
b) Bottom-up parser
c) Recursive descent parser
d) Predictive parser
Answer: b) Bottom-up parser
c. Backtracking Problem in Top-Down Parser

Q15: Backtracking in parsers occurs when:


a) A parser tries all possible productions to find a match
b) A parser fails to recognize input
c) The grammar is ambiguous
d) The grammar is LL(1)
Answer: a) A parser tries all possible productions to find a match

d. Non-Determinism Problem

Q16: Non-determinism in parsing occurs when:


a) Multiple rules can match the same input
b) Grammar has left recursion
c) Input is not in the language
d) Parsing table is LL(1)
Answer: a) Multiple rules can match the same input

e. Recursive Descent Parser

Q17: Recursive descent parsing is:


a) A bottom-up parsing technique
b) A top-down parsing technique
c) Used for ambiguous grammars
d) Used for left-recursive grammars
Answer: b) A top-down parsing technique

f. Predictive Parser

Q18: Predictive parsing eliminates backtracking by:


a) Using a parsing table
b) Using left recursion
c) Using multiple lookahead symbols
d) Generating ambiguous grammar
Answer: a) Using a parsing table
g. LL(1) Parser

Q19: In LL(1), what does the "1" signify?


a) One parsing table
b) One derivation tree
c) One lookahead symbol
d) One parse tree
Answer: c) One lookahead symbol

Q20: Which of the following is necessary for LL(1) parsing?


a) Ambiguous grammar
b) Left-recursive grammar
c) First and Follow functions
d) Right-recursive grammar
Answer: c) First and Follow functions

h. LL(1) Parsing Table

Q21: An LL(1) parsing table is used to:


a) Resolve conflicts in bottom-up parsing
b) Decide which production to apply
c) Eliminate ambiguity in grammar
d) Optimize the parse tree
Answer: b) Decide which production to apply

Q22: A conflict in the LL(1) parsing table indicates:


a) Grammar is ambiguous
b) Grammar is not LL(1)
c) Both a and b
d) None of the above
Answer: c) Both a and b

Let me know if you need further elaboration on any question or additional MCQs!

You might also like