1.What is the main difference between static and dynamic semantics?
A) Static semantics refers to the syntax of a language, while dynamic semantics refers to the execution of a program.
B) Static semantics checks for syntactic errors, while dynamic semantics checks for logical errors.
C) Static semantics deals with the meanings of constructs at compile-time, while dynamic semantics deals with the meanings at runtime.
D) Static semantics is only concerned with variable declarations, while dynamic semantics is concerned with variable values.
Answer: C) Static semantics deals with the meanings of constructs at compile-time, while dynamic semantics deals with the meanings at runtime.
2. Which of the following is an example of static semantics?
A) Type checking during program execution
B) Variable assignment at runtime
C) Ensuring that a variable is declared before it is used
D) Memory allocation during program execution
Answer: C) Ensuring that a variable is declared before it is used
3. Which of the following issues is typically handled by static semantics?
A) The value of an expression during execution
B) Ensuring that variables are correctly typed and used
C) The flow of control in a program at runtime
D) The actual allocation of memory during execution
Answer: B) Ensuring that variables are correctly typed and used
4. Dynamic semantics deals with:
A) Syntax of a language
B) Execution behavior and meaning of the program
C) Type checking and variable declarations
D) Grammar rules of a language
Answer: B) Execution behavior and meaning of the program
5. Which of the following is NOT an example of dynamic semantics?
A) Handling how an assignment affects the value of a variable
B) Determining if a function call is valid during runtime
C) Checking if a variable is properly declared before use
D) Describing the behavior of expressions when evaluated
Answer: C) Checking if a variable is properly declared before use
6. Static semantics errors occur at:
A) During program execution
B) During the compilation phase, before execution
C) After program execution
D) Only when the program is run on different machines
Answer: B) During the compilation phase, before execution
7. Which of the following can be a result of static semantic analysis?
A) A program running out of memory due to excessive recursive calls
B) Detecting a mismatch between declared and used types of variables
C) A function producing incorrect results based on its input
D) A runtime exception due to an invalid array index
Answer: B) Detecting a mismatch between declared and used types of variables
8. Which of the following defines dynamic semantics?
A) Defining how an expression is evaluated in a specific machine
B) Describing how variables are allocated in memory
C) Checking if an expression has valid syntax
D) Checking if types match in an expression
Answer: A) Defining how an expression is evaluated in a specific machine
9. Which of the following is an example of a dynamic semantic error?
A) Using a variable that was not declared
B) Type mismatches in function arguments
C) Attempting to divide by zero during runtime
D) Incorrect variable scoping during compilation
Answer: C) Attempting to divide by zero during runtime
10. Which statement is true regarding static semantics?
A) It can be checked during runtime
B) It focuses on the meaning of a program’s execution
C) It checks whether a program adheres to a formal type system and other structural rules
D) It describes how values of expressions change during execution
Answer: C) It checks whether a program adheres to a formal type system and other structural rules