1. What is a Context-Free Grammar (CFG)?
A) A set of production rules that describe the syntax of a programming language
B) A type of grammar used for natural language processing
C) A mathematical model for regular expressions
D) A method of optimizing code for better performance
Answer: A) A set of production rules that describe the syntax of a programming language
2. Which of the following components make up a Context-Free Grammar?
A) Non-terminal symbols, terminal symbols, and a start symbol
B) Non-terminal symbols and terminals only
C) A start symbol and a list of terminals
D) A list of rules and syntax errors
Answer: A) Non-terminal symbols, terminal symbols, and a start symbol
3. In a Context-Free Grammar, which of the following is always replaced by a non-terminal symbol?
A) Terminal symbol
B) Start symbol
C) Production rule
D) Non-terminal symbol
Answer: D) Non-terminal symbol
4. What is the purpose of a parse tree in syntax analysis?
A) To represent the logical flow of the program
B) To visualize the hierarchy of program statements according to the grammar
C) To generate machine code
D) To optimize the program for performance
Answer: B) To visualize the hierarchy of program statements according to the grammar
5. Which of the following is true about a parse tree?
A) A parse tree represents a program’s execution sequence.
B) A parse tree represents how a sentence (program) is derived from the grammar.
C) A parse tree is used for debugging errors.
D) A parse tree is an actual part of the compiled code.
Answer: B) A parse tree represents how a sentence (program) is derived from the grammar.
6. In a Context-Free Grammar, the start symbol:
A) Can be any terminal symbol
B) Is the only symbol that can appear on the right side of a production rule
C) Is the symbol from which the derivation of a string begins
D) Is used to generate the non-terminal symbols only
Answer: C) Is the symbol from which the derivation of a string begins
7. Which of the following is an example of a valid production rule in a Context-Free Grammar?
A) S → aSb
B) S → a + b
C) S → ab +
D) S → a | b
Answer: A) S → aSb
8. In a Context-Free Grammar, what is a terminal symbol?
A) A symbol that can be replaced by another non-terminal symbol
B) A symbol that is used to represent data in the source code
C) A symbol that is not replaceable by any other symbol
D) A symbol that represents the start of the grammar
Answer: B) A symbol that is used to represent data in the source code
9. What is the maximum depth of a parse tree in terms of the grammar rules?
A) It depends on the complexity of the grammar rules and the input string
B) It is always equal to the number of non-terminal symbols in the grammar
C) It is determined by the number of terminal symbols
D) It is the number of production rules in the grammar
Answer: A) It depends on the complexity of the grammar rules and the input string
10. Which of the following does NOT result in a correct parse tree?
A) The root of the tree represents the start symbol
B) Each non-terminal symbol is replaced by a terminal or another non-terminal symbol
C) The tree includes recursive loops without terminal symbols
D) The leaf nodes represent the terminal symbols
Answer: C) The tree includes recursive loops without terminal symbols