Syntax-directed translation(MCQs)

What is the primary purpose of Syntax-Directed Translation (SDT)? a) To check the syntax of a program b) To translate source code into intermediate or target code using syntax rules c) To optimize the execution of the program d) To parse the source code for syntax errors Answer: b) To translate source code into intermediate or target code using syntax rules In SDT, what does an attribute represent? a) A piece of information associated with a syntax tree node b) A syntax error in the source code c) A type of parsing technique d) A code optimization technique Answer: a) A piece of information associated with a syntax tree node Which of the following is a key component of SDT? a) Attribute grammar b) Syntax tree construction c) Syntax error recovery d) Code generation Answer: a) Attribute grammar What is the role of semantic rules in SDT? a) To define how attributes are computed and propagated through the syntax tree b) To check the syntax of the program c) To optimize the program code d) To generate machine code Answer: a) To define how attributes are computed and propagated through the syntax tree In SDT, what does an “attribute grammar” define? a) A formalism that specifies how attributes are assigned and propagated b) The syntax of the source code c) The optimization techniques for the code d) The parsing strategy used Answer: a) A formalism that specifies how attributes are assigned and propagated What is an “SDT rule”? a) A rule that defines how attributes are assigned to syntax tree nodes b) A rule that checks the syntax of the program c) A rule for optimizing code d) A rule for generating intermediate code Answer: a) A rule that defines how attributes are assigned to syntax tree nodes Which of the following types of attributes can be used in SDT? a) Synthesized attributes b) Inherited attributes c) Both synthesized and inherited attributes d) Syntax attributes Answer: c) Both synthesized and inherited attributes What is a synthesized attribute in SDT? a) An attribute whose value is computed from the values of its children nodes b) An attribute whose value is computed from the values of its parent node c) An attribute that is inherited from the parent node d) An attribute that is used for syntax checking Answer: a) An attribute whose value is computed from the values of its children nodes What is an inherited attribute in SDT? a) An attribute whose value is passed down from parent nodes to child nodes b) An attribute whose value is computed from the values of its child nodes c) An attribute used for semantic checking d) An attribute that is only used for code optimization Answer: a) An attribute whose value is passed down from parent nodes to child nodes In SDT, what is a “translation scheme”? a) A set of production rules and associated semantic actions for translating source code b) A set of rules for syntax checking c) A set of optimization techniques d) A set of code generation strategies Answer: a) A set of production rules and associated semantic actions for translating source code Which of the following is true about SDT? a) It combines syntax analysis with semantic analysis b) It is used only for syntax error detection c) It focuses solely on code optimization d) It is used only for intermediate code generation Answer: a) It combines syntax analysis with semantic analysis In SDT, what is meant by “semantic action”? a) An action that performs operations based on attribute values during translation b) An action that checks for syntax errors c) An action that generates intermediate code d) An action that optimizes the program code Answer: a) An action that performs operations based on attribute values during translation What is the purpose of a “syntax tree” in SDT? a) To represent the hierarchical structure of the source code and support attribute computation b) To store intermediate code c) To check for syntax errors d) To optimize code execution Answer: a) To represent the hierarchical structure of the source code and support attribute computation Which of the following describes a “semantic error”? a) An error related to the meaning of constructs in the source code b) An error related to the syntax of the source code c) An error in code optimization d) An error in code generation Answer: a) An error related to the meaning of constructs in the source code What is a “syntax-directed definition”? a) A set of grammar rules along with semantic rules for translation b) A set of syntax rules for parsing c) A set of code optimization techniques d) A set of code generation strategies Answer: a) A set of grammar rules along with semantic rules for translation What role does “attribute propagation” play in SDT? a) It involves passing attribute values between nodes in the syntax tree b) It involves checking for syntax errors c) It involves generating intermediate code d) It involves optimizing code execution Answer: a) It involves passing attribute values between nodes in the syntax tree Which of the following best describes “context-free grammar” in the context of SDT? a) A formal grammar that describes the syntax of a language without considering semantic rules b) A grammar that includes semantic rules for translation c) A grammar that focuses on code optimization d) A grammar that generates intermediate code Answer: a) A formal grammar that describes the syntax of a language without considering semantic rules What is the primary goal of “syntax-directed translation”? a) To generate target code based on syntax and semantic rules b) To parse the source code for syntax errors c) To optimize the code execution d) To check for semantic errors Answer: a) To generate target code based on syntax and semantic rules What is a “semantic rule” in SDT? a) A rule that specifies how to compute attributes and propagate them through the syntax tree b) A rule that checks for syntax errors c) A rule that generates intermediate code d) A rule that optimizes code execution Answer: a) A rule that specifies how to compute attributes and propagate them through the syntax tree In SDT, what is the purpose of “attribute evaluation”? a) To compute the values of attributes based on the syntax and semantic rules b) To check for syntax errors c) To generate machine code d) To optimize code execution Answer: a) To compute the values of attributes based on the syntax and semantic rules What is the difference between synthesized and inherited attributes in SDT? a) Synthesized attributes are computed from child nodes, while inherited attributes are passed down from parent nodes b) Synthesized attributes are passed down from parent nodes, while inherited attributes are computed from child nodes c) Synthesized attributes are used for syntax checking, while inherited attributes are used for semantic checking d) Synthesized attributes are used for code optimization, while inherited attributes are used for code generation Answer: a) Synthesized attributes are computed from child nodes, while inherited attributes are passed down from parent nodes Which of the following best describes a “translation scheme” in SDT? a) A combination of syntax rules and associated semantic actions for translating source code b) A set of syntax checking rules c) A set of code optimization techniques d) A set of code generation strategies Answer: a) A combination of syntax rules and associated semantic actions for translating source code What is the purpose of “syntax-directed translation” in a compiler? a) To translate source code into intermediate or target code based on syntax and semantic rules b) To check for syntax errors c) To generate machine code d) To optimize the execution of the program Answer: a) To translate source code into intermediate or target code based on syntax and semantic rules In SDT, what does “attribute propagation” involve? a) Passing attribute values from one node to another in the syntax tree b) Checking the syntax of attributes c) Generating code for attributes d) Optimizing attribute usage Answer: a) Passing attribute values from one node to another in the syntax tree Which of the following is a characteristic of “context-sensitive” attributes in SDT? a) Attributes whose values depend on the context within which they are used b) Attributes that are computed from child nodes c) Attributes that are inherited from parent nodes d) Attributes used for syntax checking Answer: a) Attributes whose values depend on the context within which they are used What is the role of “semantic actions” in SDT? a) To perform operations based on attribute values during translation b) To check for syntax errors c) To generate intermediate code d) To optimize the program code Answer: a) To perform operations based on attribute values during translation Which type of attribute is computed based on the values of its children nodes? a) Synthesized attribute b) Inherited attribute c) Context-sensitive attribute d) Semantic attribute Answer: a) Synthesized attribute Which type of attribute is passed down from parent nodes to child nodes? a) Inherited attribute b) Synthesized attribute c) Context-sensitive attribute d) Semantic attribute Answer: a) Inherited attribute In SDT, what is the purpose of “semantic analysis”? a) To ensure that the attributes are correctly computed and propagated through the syntax tree b) To check for syntax errors c) To generate intermediate code d) To optimize code execution Answer: a) To ensure that the attributes are correctly computed and propagated through the syntax tree What is a “syntax-directed definition” in SDT? a) A grammar that includes both syntax rules and semantic rules for translation b) A grammar that describes the syntax of a language without semantic rules c) A set of optimization techniques d) A set of code generation strategies Answer: a) A grammar that includes both syntax rules and semantic rules for translation Which of the following is a common use of SDT in compilers? a) Translating source code into intermediate code or target code b) Checking for syntax errors c) Generating machine code d) Optimizing code execution Answer: a) Translating source code into intermediate code or target code What does “attribute evaluation” involve in SDT? a) Computing the values of attributes based on semantic rules b) Checking the syntax of attributes c) Generating intermediate code for attributes d) Optimizing attribute usage Answer: a) Computing the values of attributes based on semantic rules Which of the following describes a “translation scheme” in SDT? a) A combination of grammar rules and associated semantic actions for translating source code b) A set of syntax checking rules c) A set of optimization techniques d) A set of code generation strategies Answer: a) A combination of grammar rules and associated semantic actions for translating source code What is the purpose of “semantic rules” in SDT? a) To define how attributes are assigned and propagated through the syntax tree b) To check for syntax errors c) To generate intermediate code d) To optimize code execution Answer: a) To define how attributes are assigned and propagated through the syntax tree In SDT, what is the role of a “syntax tree”? a) To represent the hierarchical structure of the source code and support attribute computation b) To store intermediate code c) To check for syntax errors d) To optimize code execution Answer: a) To represent the hierarchical structure of the source code and support attribute computation Which type of attribute is used to pass information from parent nodes to child nodes? a) Inherited attribute b) Synthesized attribute c) Context-sensitive attribute d) Semantic attribute Answer: a) Inherited attribute What does “attribute propagation” involve in SDT? a) Passing attribute values between nodes in the syntax tree b) Checking the syntax of attributes c) Generating code for attributes d) Optimizing attribute usage Answer: a) Passing attribute values between nodes in the syntax tree Which of the following best describes “context-free grammar” in SDT? a) A formalism for defining the syntax of a language without semantic rules b) A grammar that includes semantic rules for translation c) A grammar that focuses on code optimization d) A grammar that generates intermediate code Answer: a) A formalism for defining the syntax of a language without semantic rules What is the primary goal of “syntax-directed translation” in a compiler? a) To generate target code based on syntax and semantic rules b) To parse the source code for syntax errors c) To generate machine code d) To optimize the execution of the program Answer: a) To generate target code based on syntax and semantic rules Which of the following is true about “semantic actions” in SDT? a) They are operations performed based on attribute values during translation b) They are actions that check for syntax errors c) They are actions that generate intermediate code d) They are actions that optimize the program code Answer: a) They are operations performed based on attribute values during translation Which of the following is a common application of SDT in compilers? a) Translating source code into intermediate code or target code b) Checking for syntax errors c) Generating machine code d) Optimizing code execution Answer: a) Translating source code into intermediate code or target code What is the role of “semantic analysis” in SDT? a) To ensure attributes are correctly computed and propagated through the syntax tree b) To check for syntax errors c) To generate intermediate code d) To optimize code execution Answer: a) To ensure attributes are correctly computed and propagated through the syntax tree In SDT, what does “attribute evaluation” involve? a) Computing the values of attributes based on semantic rules b) Checking the syntax of attributes c) Generating intermediate code for attributes d) Optimizing attribute usage Answer: a) Computing the values of attributes based on semantic rules Which type of attribute in SDT is computed from child nodes? a) Synthesized attribute b) Inherited attribute c) Context-sensitive attribute d) Semantic attribute Answer: a) Synthesized attribute Which type of attribute is passed down from parent nodes in SDT? a) Inherited attribute b) Synthesized attribute c) Context-sensitive attribute d) Semantic attribute Answer: a) Inherited attribute What is the purpose of “attribute propagation” in SDT? a) Passing attribute values between nodes in the syntax tree b) Checking the syntax of attributes c) Generating code for attributes d) Optimizing attribute usage Answer: a) Passing attribute values between nodes in the syntax tree Which of the following describes a “translation scheme” in SDT? a) A combination of syntax rules and semantic actions for translating source code b) A set of syntax checking rules c) A set of code optimization techniques d) A set of code generation strategies Answer: a) A combination of syntax rules and semantic actions for translating source code What is the role of “semantic rules” in SDT? a) Defining how attributes are assigned and propagated through the syntax tree b) Checking for syntax errors c) Generating intermediate code d) Optimizing code execution Answer: a) Defining how attributes are assigned and propagated through the syntax tree In SDT, what is the purpose of the “syntax tree”? a) To represent the hierarchical structure of the source code and support attribute computation b) To store intermediate code c) To check for syntax errors d) To optimize code execution Answer: a) To represent the hierarchical structure of the source code and support attribute computation Which of the following best describes “context-free grammar” in SDT? a) A formalism for defining the syntax of a language without semantic rules b) A grammar that includes semantic rules for translation c) A grammar that focuses on code optimization d) A grammar that generates intermediate code Answer: a) A formalism for defining the syntax of a language without semantic rules
All Copyrights Reserved 2025 Reserved by T4Tutorials