Context-Free Grammars and Parse Trees MCQs January 8, 2026December 14, 2024 by u930973931_answers 10 min Score: 0 Attempted: 0/10 Subscribe 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 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 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 4. What is the purpose of a parse tree in syntax analysis? (A) To represent the logical flow of the program (B) To optimize the program for performance (C) To generate machine code (D) 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 is an actual part of the compiled code. (C) A parse tree is used for debugging errors. (D) A parse tree represents how a sentence (program) is derived from the grammar. 6. In a Context-Free Grammar, the start symbol: (A) Is the symbol from which the derivation of a string begins (B) Is the only symbol that can appear on the right side of a production rule (C) Can be any terminal symbol (D) Is used to generate the non-terminal symbols only 7. Which of the following is an example of a valid production rule in a Context-Free Grammar? (A) S β ab + (B) S β a + b (C) S β aSb (D) S β a | b 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 not replaceable by any other symbol (C) A symbol that is used to represent data in the source code (D) A symbol that represents the start of the grammar 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 10. Which of the following does NOT result in a correct parse tree? (A) The tree includes recursive loops without terminal symbols (B) Each non-terminal symbol is replaced by a terminal or another non-terminal symbol (C) The root of the tree represents the start symbol (D) The leaf nodes represent the terminal symbols