Semantic Analysis

What is the primary purpose of semantic analysis in a compiler? a) To check for syntax errors b) To ensure the program adheres to the rules of meaning and logic c) To generate machine code d) To optimize the program’s execution Answer: b) To ensure the program adheres to the rules of meaning and logic Which of the following is typically not a concern of semantic analysis? a) Type checking b) Scope resolution c) Syntax tree construction d) Variable declaration and initialization Answer: c) Syntax tree construction What does type checking involve in semantic analysis? a) Ensuring that operations are performed on compatible data types b) Verifying the syntax of the program c) Generating intermediate code d) Optimizing the code for performance Answer: a) Ensuring that operations are performed on compatible data types What is scope resolution in semantic analysis? a) Determining the visibility and lifetime of variables and functions b) Checking the syntax of function calls c) Generating machine code d) Optimizing memory usage Answer: a) Determining the visibility and lifetime of variables and functions Which of the following errors is detected during semantic analysis? a) Missing semicolons b) Mismatched parentheses c) Type mismatch d) Unexpected end-of-file Answer: c) Type mismatch In which phase of compilation does semantic analysis typically occur? a) Lexical analysis b) Syntax analysis c) Semantic analysis d) Code generation Answer: b) Syntax analysis What is the role of a symbol table in semantic analysis? a) To store information about variables, functions, and their attributes b) To store intermediate code c) To store syntax tree nodes d) To store machine code instructions Answer: a) To store information about variables, functions, and their attributes What is meant by “type inference” in semantic analysis? a) Determining the type of an expression or variable when it is not explicitly declared b) Checking for syntax errors in type declarations c) Optimizing type-related operations d) Generating type-specific code Answer: a) Determining the type of an expression or variable when it is not explicitly declared Which of the following is not typically a part of semantic analysis? a) Checking for undeclared variables b) Verifying the proper use of operators c) Parsing expressions to generate syntax trees d) Ensuring function arguments match their declarations Answer: c) Parsing expressions to generate syntax trees In semantic analysis, what is “name resolution”? a) Determining which variables or functions are being referred to in different scopes b) Checking for syntax errors in variable names c) Generating names for variables and functions d) Optimizing the names used in the code Answer: a) Determining which variables or functions are being referred to in different scopes What does “flow analysis” involve in semantic analysis? a) Analyzing the flow of control and data through the program b) Checking for syntax errors in control structures c) Generating control flow graphs d) Optimizing control flow statements Answer: a) Analyzing the flow of control and data through the program Which of the following is a common task in semantic analysis for functions? a) Checking for proper return types and arguments b) Parsing function definitions c) Generating function calls d) Optimizing function execution Answer: a) Checking for proper return types and arguments What is “context-sensitive analysis” in the context of semantic analysis? a) Analysis that requires understanding the context in which a construct is used b) Analysis that checks for syntax errors in context c) Analysis that generates context-specific code d) Analysis that optimizes context usage Answer: a) Analysis that requires understanding the context in which a construct is used Which semantic error occurs when a variable is used before it is initialized? a) Undefined variable error b) Uninitialized variable error c) Type mismatch error d) Scope resolution error Answer: b) Uninitialized variable error What is “type coercion” in semantic analysis? a) Automatically converting one data type to another b) Enforcing strict type rules c) Generating type-specific code d) Checking for type mismatches Answer: a) Automatically converting one data type to another Which of the following is an example of a semantic error? a) Using an undeclared variable b) Missing a semicolon c) Using a function with the wrong number of arguments d) Mismatched parentheses Answer: c) Using a function with the wrong number of arguments What is the purpose of “data flow analysis” in semantic analysis? a) To track how data values are propagated through the program b) To verify the syntax of data declarations c) To optimize data storage d) To generate data-related code Answer: a) To track how data values are propagated through the program Which of the following describes “static type checking”? a) Checking type correctness at compile-time b) Checking type correctness at runtime c) Generating type-specific code d) Optimizing type-related operations Answer: a) Checking type correctness at compile-time What is “dynamic typing”? a) Determining types at runtime rather than compile-time b) Enforcing strict type rules at compile-time c) Automatically converting types at compile-time d) Generating type-specific code at runtime Answer: a) Determining types at runtime rather than compile-time What is a “symbol table entry”? a) An entry in the symbol table that contains information about a variable or function b) A token representing a variable or function c) A node in the syntax tree d) An entry in the error log Answer: a) An entry in the symbol table that contains information about a variable or function What does “overloading” refer to in semantic analysis? a) Defining multiple functions or operators with the same name but different parameters b) Using a function with the wrong number of arguments c) Initializing variables multiple times d) Using operators with incompatible types Answer: a) Defining multiple functions or operators with the same name but different parameters What is “array bounds checking” in semantic analysis? a) Ensuring that array indices are within the valid range b) Verifying the syntax of array declarations c) Optimizing array usage d) Generating array-specific code Answer: a) Ensuring that array indices are within the valid range What is the purpose of “constant folding” in semantic analysis? a) Evaluating constant expressions at compile-time to improve performance b) Checking for syntax errors in constant declarations c) Generating constant-specific code d) Optimizing constant values at runtime Answer: a) Evaluating constant expressions at compile-time to improve performance Which of the following is typically checked during semantic analysis for functions? a) Function return types b) Function syntax c) Function definitions and declarations d) Function execution speed Answer: a) Function return types What is “recursive type checking” in semantic analysis? a) Checking types in a recursive manner for nested constructs b) Checking types at runtime c) Generating recursive type-specific code d) Optimizing recursive function calls Answer: a) Checking types in a recursive manner for nested constructs What does “unreachable code” refer to in semantic analysis? a) Code that can never be executed due to logical errors b) Code that is syntactically incorrect c) Code that is not used by the compiler d) Code that has been optimized out Answer: a) Code that can never be executed due to logical errors In semantic analysis, what is a “type checker”? a) A component that verifies type correctness throughout the program b) A tool that generates type-specific code c) A mechanism that converts types at runtime d) A utility for optimizing type-related operations Answer: a) A component that verifies type correctness throughout the program What does “type promotion” refer to in semantic analysis? a) Automatically converting a smaller type to a larger type to avoid loss of precision b) Enforcing strict type rules c) Generating type-specific code d) Checking for type mismatches Answer: a) Automatically converting a smaller type to a larger type to avoid loss of precision Which of the following errors is detected by semantic analysis but not by syntax analysis? a) Missing parentheses b) Misplaced keywords c) Variable used before declaration d) Missing semicolon Answer: c) Variable used before declaration What is “variable shadowing”? a) When a variable in an inner scope hides a variable in an outer scope with the same name b) When a variable is not initialized before use c) When a variable is declared multiple times d) When a variable is used with the wrong type Answer: a) When a variable in an inner scope hides a variable in an outer scope with the same name Which of the following best describes “late binding”? a) Resolving function or method calls at runtime rather than compile-time b) Resolving function or method calls at compile-time c) Generating function call code d) Optimizing function call execution Answer: a) Resolving function or method calls at runtime rather than compile-time What is the goal of “context-sensitive semantic analysis”? a) To analyze the meaning of constructs based on their context within the program b) To analyze syntax errors c) To optimize code execution d) To generate machine code Answer: a) To analyze the meaning of constructs based on their context within the program Which of the following is a common task in semantic analysis for control structures? a) Ensuring that all control paths terminate correctly b) Parsing control flow syntax c) Generating control flow graphs d) Optimizing control statements Answer: a) Ensuring that all control paths terminate correctly What does “initialization checking” involve in semantic analysis? a) Verifying that all variables are initialized before use b) Checking the syntax of initialization statements c) Generating initialization code d) Optimizing initialization performance Answer: a) Verifying that all variables are initialized before use What is “dead code elimination”? a) Removing code that cannot be executed due to logical errors b) Checking for syntax errors in code c) Generating code for unreachable sections d) Optimizing code execution Answer: a) Removing code that cannot be executed due to logical errors Which of the following is true about “dynamic type checking”? a) It occurs at runtime and checks for type errors b) It occurs at compile-time and checks for type errors c) It optimizes type-related operations d) It generates type-specific code Answer: a) It occurs at runtime and checks for type errors What is a “type mismatch error”? a) An error that occurs when operations are performed on incompatible types b) An error in the syntax of type declarations c) An error that occurs when types are not initialized d) An error related to variable scope Answer: a) An error that occurs when operations are performed on incompatible types What is “control flow analysis”? a) Analyzing the order in which statements and expressions are executed in a program b) Checking for syntax errors in control structures c) Generating control flow graphs d) Optimizing control flow Answer: a) Analyzing the order in which statements and expressions are executed in a program What does “strict type checking” enforce? a) Enforcing that all operations must be performed on compatible data types b) Enforcing dynamic type resolution c) Enforcing type conversion rules d) Generating type-specific code Answer: a) Enforcing that all operations must be performed on compatible data types Which of the following is typically not a part of semantic analysis? a) Checking for type correctness b) Verifying variable declarations c) Generating intermediate code d) Analyzing control flow Answer: c) Generating intermediate code What is “function overloading”? a) Defining multiple functions with the same name but different parameters b) Using a function with the wrong number of arguments c) Initializing functions multiple times d) Using functions with incompatible types Answer: a) Defining multiple functions with the same name but different parameters What is the purpose of “name binding” in semantic analysis? a) To associate names with their definitions and scopes b) To check the syntax of names c) To generate names for variables and functions d) To optimize name usage Answer: a) To associate names with their definitions and scopes What does “scope checking” ensure? a) That variables and functions are used within their valid scope b) That syntax rules for scopes are followed c) That scope names are unique d) That scopes are properly initialized Answer: a) That variables and functions are used within their valid scope Which of the following is not typically checked during semantic analysis? a) Syntax of declarations b) Type compatibility c) Variable initialization d) Control flow correctness Answer: a) Syntax of declarations What is “polymorphism” in the context of semantic analysis? a) Allowing multiple functions or operators to behave differently based on their arguments or types b) Ensuring all variables are initialized c) Optimizing function calls d) Checking for syntax errors in functions Answer: a) Allowing multiple functions or operators to behave differently based on their arguments or types What does “type checking for expressions” involve? a) Ensuring that all operands in an expression are of compatible types b) Generating type-specific code for expressions c) Checking the syntax of expression statements d) Optimizing expression evaluations Answer: a) Ensuring that all operands in an expression are of compatible types Which semantic error occurs when an operation is performed on incompatible data types? a) Type mismatch error b) Syntax error c) Variable scope error d) Control flow error Answer: a) Type mismatch error What is “inheritance” in object-oriented programming? a) A mechanism where a class derives properties and behaviors from another class b) Ensuring functions are correctly overloaded c) Initializing variables in derived classes d) Optimizing method calls in derived classes Answer: a) A mechanism where a class derives properties and behaviors from another class What does “parameter type checking” involve? a) Ensuring that function parameters match their declarations in type and order b) Generating parameter-specific code c) Checking the syntax of function parameter lists d) Optimizing parameter usage Answer: a) Ensuring that function parameters match their declarations in type and order Which of the following is true about “static vs. dynamic semantics”? a) Static semantics are checked at compile-time, while dynamic semantics are checked at runtime b) Static semantics are checked at runtime, while dynamic semantics are checked at compile-time c) Both static and dynamic semantics are checked at runtime d) Both static and dynamic semantics are checked at compile-time Answer: a) Static semantics are checked at compile-time, while dynamic semantics are checked at runtime
All Copyrights Reserved 2025 Reserved by T4Tutorials