Skip to main content

10 MCQs related to Semantic Analysis

10 Multiple Choice Questions (MCQs) related to Semantic Analysis, useful for UGC NET, SET, and GATE exams:


1. What is the primary function of semantic analysis in a compiler?

A) Checking syntax errors
B) Checking logical errors
C) Checking type mismatches and undefined variables
D) Optimizing the code

Explanation:
Semantic analysis ensures that the program is meaningfully correct by checking type mismatches, undeclared variables, and function usage.

Answer: C) Checking type mismatches and undefined variables


2. Which of the following errors is detected during semantic analysis?

A) Missing semicolons
B) Type mismatches
C) Unrecognized tokens
D) Invalid operator precedence

Explanation:
Semantic analysis checks for type mismatches, undeclared variables, and incompatible function calls.

Answer: B) Type mismatches


3. What is the primary data structure used in semantic analysis?

A) Parse Tree
B) Symbol Table
C) Stack
D) Linked List

Explanation:
The Symbol Table stores information about variables, functions, and types, which is used in semantic analysis.

Answer: B) Symbol Table


4. Which of the following phases directly precedes semantic analysis?

A) Lexical Analysis
B) Syntax Analysis
C) Intermediate Code Generation
D) Code Optimization

Explanation:
Semantic analysis occurs after syntax analysis, ensuring the parsed structure follows semantic rules.

Answer: B) Syntax Analysis


5. What is type checking in semantic analysis?

A) Checking if all variables are initialized
B) Ensuring that operations are performed on compatible data types
C) Detecting syntax errors
D) Converting high-level code into assembly language

Explanation:
Type checking ensures that operations involve compatible data types (e.g., adding an integer to a string is invalid).

Answer: B) Ensuring that operations are performed on compatible data types


6. Which of the following is NOT a part of semantic analysis?

A) Type checking
B) Scope resolution
C) Checking for undeclared variables
D) Parsing tokens

Explanation:
Parsing tokens is part of syntax analysis, not semantic analysis.

Answer: D) Parsing tokens


7. What is scope resolution in semantic analysis?

A) Determining where variables and functions are accessible
B) Checking if brackets are properly closed
C) Finding the execution order of statements
D) Converting source code to machine code

Explanation:
Scope resolution ensures that variables and functions are used within their declared scope.

Answer: A) Determining where variables and functions are accessible


8. What is the role of attribute grammar in semantic analysis?

A) Defines how code is optimized
B) Specifies rules for associating additional information with syntax trees
C) Determines memory allocation for variables
D) Converts source code into an abstract syntax tree

Explanation:
Attribute Grammar extends context-free grammar by adding semantic rules for meaning validation.

Answer: B) Specifies rules for associating additional information with syntax trees


9. Which technique is commonly used for semantic error detection?

A) Finite State Automata
B) Symbol Table Lookup
C) Shift-Reduce Parsing
D) Regular Expressions

Explanation:
Symbol Table Lookup helps check variable declarations, function signatures, and type consistency.

Answer: B) Symbol Table Lookup


10. Which of the following is an example of a semantic error?

A) Using an undefined variable
B) Misspelling a keyword
C) Missing a closing parenthesis
D) Incorrect indentation in Python

Explanation:
Using an undefined variable is a semantic error because it violates program meaning but is syntactically correct.

Answer: A) Using an undefined variable

Comments

Popular posts from this blog

Top 5 Safe Chat Apps for Kids with Parental Controls

Now a days kids are growing up with technology at their fingertips. While communication apps help children stay connected with family and friends, safety remains a top concern for parents. Unregulated platforms can expose children to inappropriate content, online predators, and cyberbullying. That’s why choosing a kid-friendly chat app with parental controls is essential. To help parents find the best options, we’ve compiled a list of the top five safest chat apps for kids that offer safe and controlled environment. 1. Messenger Kids (By Meta) Best for: Safe video calls and text messaging with parental supervision Features: Parents approve all contacts No ads or in-app purchases Fun filters, stickers, and games Monitored messaging and activity reports Why It’s Safe: Messenger Kids is designed for children under 13 and requires parental approval for every contact. Parents can monitor chats and control screen time through the Parent Dashboard. Download Messenger Kids 2...

10 Distance Vector and Link-State Routing MCQ

  10 multiple-choice questions  on  Distance Vector and Link-State Routing with explanations, useful for  UGC NET, SET, GATE, ISRO, and other competitive exams . Question 1: Basic Concept of Distance Vector Routing Q1: In a distance vector routing protocol, how do routers share routing information? A) By flooding the entire network with routing updates B) By periodically exchanging routing tables with their immediate neighbors C) By using a link-state database to determine the shortest path D) By dynamically updating paths based on link failure reports Answer: B) By periodically exchanging routing tables with their immediate neighbors Explanation: In Distance Vector Routing, routers share their routing tables with neighbors at regular intervals, leading to a simple but slow convergence mechanism. Question 2: Example of Distance Vector Routing Protocol Q2: Which of the following is an example of a Distance Vector routing protocol? A) OSPF ...

10 Routing Protocol MCQ

10 multiple-choice questions on Routing protocol s  with explanations, useful for UGC NET, SET, GATE, ISRO, and other competitive exams . Question 1: Purpose of Routing Protocols Q1: What is the primary purpose of a routing protocol? A) To assign IP addresses to devices B) To determine the best path for data packets to reach their destination C) To encrypt data during transmission D) To physically connect different networks Answer: B) To determine the best path for data packets to reach their destination Explanation: Routing protocols help routers determine the most efficient path for data transmission across a network, ensuring fast and reliable communication. Question 2: Classification of Routing Protocols Q2: Routing protocols can be broadly classified into which two main categories? A) TCP and UDP B) Distance Vector and Link-State C) IPv4 and IPv6 D) Static and Dynamic Answer: B) Distance Vector and Link-State Explanation: Routing prot...