Compiler Design Banner

Compiler Design Multiple Choice Questions (MCQs) and Answers

Master Compiler Design with Practice MCQs. Explore our curated collection of Multiple Choice Questions. Ideal for placement and interview preparation, our questions range from basic to advanced, ensuring comprehensive coverage of Compiler Design concepts. Begin your placement preparation journey now!

Q31

Q31 During tokenization, the lexical analyzer identifies an identifier starting with a digit. What type of error is this?

A

Logical error

B

Syntax error

C

Lexical error

D

Type error

Q32

Q32 What is the main role of syntax analysis in a compiler?

A

To check lexical rules

B

To validate grammatical structure

C

To optimize code

D

To generate machine code

Q33

Q33 Which data structure is used in top-down parsing to manage recursive calls?

A

Queue

B

Stack

C

Linked List

D

Binary Tree

Q34

Q34 What does an LR parser stand for in parsing techniques?

A

Left-to-right, rightmost derivation

B

Leftmost derivation, recursive

C

Right-to-left, leftmost derivation

D

Left-to-right, leftmost derivation

Q35

Q35 What is the primary difference between LL and LR parsers?

A

LL parsers use top-down parsing, LR parsers use bottom-up parsing

B

LL parsers handle left recursion, LR parsers cannot

C

LR parsers use recursive descent, LL parsers use shift-reduce

D

Both are identical

Q36

Q36 Which of the following is NOT a type of parsing algorithm?

A

Top-down parsing

B

Bottom-up parsing

C

Lexical parsing

D

Predictive parsing

Q37

Q37 Why is lookahead used in parsing?

A

To optimize parsing

B

To resolve ambiguities

C

To simplify grammar rules

D

To identify lexical errors

Q38

Q38 What is the FIRST step in constructing a parse tree?

A

Start with the root symbol

B

Expand all terminal nodes

C

Collapse all non-terminals

D

Evaluate leaf nodes

Q39

Q39 Given the grammar S → AA, A → aA | b, what is the language generated by the grammar?

A

All strings of 'a's followed by a single 'b'

B

All strings of 'a's and 'b's

C

All strings with even length

D

All strings with no 'a's or 'b's

Q40

Q40 What is the output of applying shift-reduce parsing to 'id + id' using the grammar E → E + E

A

A parse tree

B

A syntax error

C

Shift-reduce conflict

D

A leftmost derivation

Q41

Q41 Using recursive descent parsing, which grammar rule can cause an infinite loop?

A

Right-recursive grammar

B

Ambiguous grammar

C

Left-recursive grammar

D

Non-recursive grammar

Q42

Q42 A parser encounters an unexpected token '}' in the input. What type of error is this?

A

Lexical error

B

Syntax error

C

Semantic error

D

Logical error

Q43

Q43 How can shift-reduce conflicts in parsing be resolved?

A

By simplifying grammar

B

By using a larger lookahead

C

By using recursive parsing

D

By removing recursion

Q44

Q44 What is the primary challenge in implementing an LR parser for ambiguous grammars?

A

Shift-reduce conflicts

B

Excessive memory usage

C

Incorrect syntax trees

D

Infinite recursion

Q45

Q45 What is the main purpose of semantic analysis in a compiler?

A

To optimize the code

B

To check logical correctness

C

To generate machine code

D

To parse input

Q46

Q46 Which error is typically detected during semantic analysis?

A

Syntax error

B

Type mismatch

C

Undefined symbol

D

Memory overflow

Q47

Q47 What is the role of a symbol table in semantic analysis?

A

To store lexical tokens

B

To store grammar rules

C

To store information about program identifiers

D

To store intermediate code

Q48

Q48 How does semantic analysis handle function overloading?

A

By ignoring overloaded functions

B

By checking parameter types and counts

C

By generating syntax trees

D

By creating machine code

Q49

Q49 Which of the following is NOT a task of semantic analysis?

A

Type checking

B

Scope resolution

C

Error recovery

D

Code generation

Q50

Q50 Why is semantic analysis essential for detecting dynamic type errors?

A

To ensure optimized code

B

To ensure runtime safety

C

To ensure static correctness

D

To parse ambiguous grammar

Q51

Q51 Which type of error will occur if a variable is used before declaration?

A

Syntax error

B

Logical error

C

Semantic error

D

Lexical error

Q52

Q52 What will semantic analysis identify in the expression: int x = 5.5;?

A

Syntax error

B

Type mismatch error

C

Logical error

D

Lexical error

Q53

Q53 Which semantic rule ensures that variables are declared before use in a block?

A

Scope checking

B

Type checking

C

Binding rules

D

Declaration rules

Q54

Q54 What error will semantic analysis detect in the function call foo(5, 'a', true) if foo is defined as foo(int, char)?

A

Type mismatch

B

Logical error

C

Scope error

D

Syntax error

Q55

Q55 What is the likely error if a compiler reports 'undefined symbol' during semantic analysis?

A

Variable used before declaration

B

Invalid syntax

C

Memory allocation failure

D

Runtime error

Q56

Q56 What is the most probable cause of a 'duplicate declaration' error during semantic analysis?

A

Redeclaring a variable in the same scope

B

Using an undeclared variable

C

Assigning wrong types

D

Syntax mismatch

Q57

Q57 How does semantic analysis handle conflicting types in a single expression?

A

By ignoring conflicts

B

By type casting automatically

C

By reporting a type mismatch

D

By optimizing the expression

Q58

Q58 What is the primary purpose of intermediate code generation in a compiler?

A

To generate machine code

B

To check for logical errors

C

To create an intermediate representation

D

To parse the input

Q59

Q59 Which form of intermediate code uses a stack for its representation?

A

Three-address code

B

Postfix notation

C

Quadruples

D

Direct machine code

Q60

Q60 Which of the following is a commonly used intermediate representation?

A

Syntax tree

B

Abstract syntax tree (AST)

C

Control flow graph

D

Three-address code

ad verticalad vertical
ad