Skip to main content

10 MCQs related to Lexical Analysis

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


1. What is the main function of the lexical analyzer in a compiler?

A) Syntax checking
B) Semantic checking
C) Token generation
D) Code optimization

Explanation:
The Lexical Analyzer scans the input program and converts it into tokens, which are the basic building blocks for syntax analysis.

Answer: C) Token generation


2. Which of the following is NOT performed during lexical analysis?

A) Removing white spaces
B) Removing comments
C) Checking for syntax errors
D) Identifying keywords and identifiers

Explanation:
Syntax error checking is done in the Syntax Analysis phase, not in Lexical Analysis.

Answer: C) Checking for syntax errors


3. What type of errors are detected in the lexical analysis phase?

A) Syntax errors
B) Lexical errors
C) Semantic errors
D) Logical errors

Explanation:
Lexical errors include invalid tokens, unrecognized characters, and illegal identifier names.

Answer: B) Lexical errors


4. Which data structure is commonly used by a lexical analyzer?

A) Stack
B) Queue
C) Symbol Table
D) Linked List

Explanation:
The Symbol Table stores information about tokens, such as identifiers and keywords.

Answer: C) Symbol Table


5. What is a token in lexical analysis?

A) A sequence of characters representing a unit of meaning
B) A parsed tree representation of the source code
C) A machine code equivalent of a program
D) An error message in lexical analysis

Explanation:
A token is the smallest unit of a program that has meaning, such as keywords, identifiers, operators, and literals.

Answer: A) A sequence of characters representing a unit of meaning


6. What is the role of a finite automaton in lexical analysis?

A) It parses syntax trees
B) It helps in recognizing tokens
C) It optimizes the generated code
D) It performs semantic checking

Explanation:
A Finite Automaton (FA) is used by a Lexical Analyzer to identify tokens based on regular expressions.

Answer: B) It helps in recognizing tokens


7. Which of the following tools is commonly used to implement lexical analysis?

A) YACC
B) Bison
C) Lex
D) Turbo C++

Explanation:
Lex is a lexical analyzer generator used for building token recognizers.

Answer: C) Lex


8. Which type of grammar is used to define the lexical structure of a programming language?

A) Regular Grammar
B) Context-Free Grammar
C) Context-Sensitive Grammar
D) Unrestricted Grammar

Explanation:
Lexical analysis uses regular expressions, which can be described by Regular Grammar.

Answer: A) Regular Grammar


9. In lexical analysis, keywords are classified as which type of token?

A) Identifier
B) Operator
C) Reserved Word
D) Literal

Explanation:
Keywords are reserved words with predefined meanings and cannot be used as identifiers.

Answer: C) Reserved Word


10. The output of a lexical analyzer is given to which phase of the compiler?

A) Syntax Analysis
B) Code Optimization
C) Code Generation
D) Semantic Analysis

Explanation:
The Lexical Analyzer sends tokens to the Syntax Analyzer, which checks grammatical structure.

Answer: A) Syntax Analysis

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 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...

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 ...