Skip to main content

10 MCQs related to Syntax Analysis

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


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

A) Checking token validity
B) Checking grammatical structure
C) Optimizing code
D) Allocating memory

Explanation:
Syntax Analysis (Parsing) ensures that the sequence of tokens follows the grammar of the programming language.

Answer: B) Checking grammatical structure


2. Which data structure is commonly used in syntax analysis?

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

Explanation:
Parsers use a stack to keep track of grammar rules and parsing states.

Answer: B) Stack


3. Which type of grammar is used for syntax analysis?

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

Explanation:
Context-Free Grammar (CFG) is used in syntax analysis to define language structure.

Answer: B) Context-Free Grammar


4. Which of the following is NOT a type of parser?

A) LL Parser
B) LR Parser
C) Recursive Descent Parser
D) Regular Expression Parser

Explanation:
Regular Expressions are used in Lexical Analysis, not in Syntax Analysis.

Answer: D) Regular Expression Parser


5. What is the role of a parse tree in syntax analysis?

A) It represents the sequence of tokens
B) It represents the hierarchical structure of the code
C) It stores symbol table information
D) It generates machine code

Explanation:
A parse tree shows the hierarchical structure of a program based on grammar rules.

Answer: B) It represents the hierarchical structure of the code


6. Which parsing technique uses a top-down approach?

A) LL Parsing
B) LR Parsing
C) Operator Precedence Parsing
D) Shift-Reduce Parsing

Explanation:
LL Parsing (Left-to-right, Leftmost derivation) is a top-down parsing technique.

Answer: A) LL Parsing


7. In bottom-up parsing, which action is performed first?

A) Deriving the start symbol
B) Expanding non-terminals
C) Shifting tokens onto the stack
D) Applying semantic rules

Explanation:
Bottom-up parsing starts with shifting tokens onto the stack, then reduces them to grammar rules.

Answer: C) Shifting tokens onto the stack


8. Which of the following parsers is used in YACC (Yet Another Compiler Compiler)?

A) LL Parser
B) LR Parser
C) Recursive Descent Parser
D) Operator Precedence Parser

Explanation:
YACC uses LR parsing techniques for bottom-up parsing.

Answer: B) LR Parser


9. Which of the following is NOT a bottom-up parsing method?

A) Shift-Reduce Parsing
B) LR Parsing
C) Operator Precedence Parsing
D) Recursive Descent Parsing

Explanation:
Recursive Descent Parsing is a top-down parsing method.

Answer: D) Recursive Descent Parsing


10. What is the worst-case time complexity of LR parsing?

A) O(n)
B) O(n²)
C) O(log n)
D) O(1)

Explanation:
LR parsing operates in O(n) time complexity, where n is the length of the input.

Answer: A) O(n)

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