Compiler Design MCQ Quiz - Objective Question with Answer for Compiler Design - Download Free PDF

Compiler design is a field of computer science that focuses on the development of software tools known as compilers. A compiler is a program that translates source code written in a high-level programming language into a low-level language (such as machine code) that can be executed by a computer. It involves various stages, including lexical analysis, syntax analysis, semantic analysis, code generation, and code optimization. MCQs on compiler design cover topics such as lexical analysis, parsing techniques (such as LL and LR parsing), symbol table management, intermediate code generation, optimization techniques, and error handling. These MCQs assess knowledge of compiler architecture, compiler phases, compiler construction techniques, and compiler optimization strategies. Find out how much you know about this compiler and its uses by solving the given Compiler Design MCQs.

Latest Compiler Design MCQ Objective Questions

Compiler Design Question 1:

Phase 3 of a typical 6-phase compiler is _____.

  1. Intermediate Code Generation
  2. Syntax Analysis
  3. Semantic Analysis
  4. Code Optimization

Answer (Detailed Solution Below)

Option 3 : Semantic Analysis India's Super Teachers for all govt. exams Under One Roof Demo Classes Available* Enroll For Free Now

Compiler Design Question 1 Detailed Solution

The correct answer is Semantic Analysis.

Key Points

Additional Information

India’s #1 Learning Platform Start Complete Exam Preparation Daily Live MasterClasses Practice Question Bank Mock Tests & Quizzes Trusted by 6.1 Crore+ Students

Compiler Design Question 2:

Which of the following is not a token of C program
  1. 1.02e+2
  2. #define
  3. MAX
  4. "Testbook"
  5. Keyword

Answer (Detailed Solution Below)

Option 2 : #define

Compiler Design Question 2 Detailed Solution

A token is a sequence of characters that can be treated as a single logical entity. C tokens are the basic building blocks in C language which are constructed together to write a C program.

● Each and every smallest individual unit in a C program are known as C tokens.

● C tokens are of six types. They are,

1.Keywords (eg: int, while),

2.Identifiers (eg: main, total, MAX),

3.Constants (eg: 10, 20, 1.02e+2),

4.Strings (eg: “total”, “hello”, "Testbook"),

5.Special symbols (eg: (), <>),

#define is C Preprocessor, which is not part of the compiler but is a separate step in the compilation process. So it is not a token.

India’s #1 Learning Platform Start Complete Exam Preparation Daily Live MasterClasses Practice Question Bank Mock Tests & Quizzes Trusted by 6.1 Crore+ Students

Compiler Design Question 3:

Match List-I with List-II:
LIST - I LIST - II
A. P vs NP Problem I. Undecidable Problems
B. Chomsky Hierarchy II. Polynomial-Time Verification
C. Rice's Theorem III. Classes of Formal Grammars
D. Savitch's Theorem IV. Space Complexity
Choose the correct answer from the options given below:
  1. A - I, B - III, C - II, D - IV
  2. A - II, B - III, C - I, D - IV
  3. A - II, B - I, C - IV, D - III
  4. A - IV, B - II, C - I, D - III

Answer (Detailed Solution Below)

Option 2 : A - II, B - III, C - I, D - IV

Compiler Design Question 3 Detailed Solution

The correct answer is A - II, B - III, C - I, D - IV

Key Points

Therefore, the correct matching is: A - II, B - III, C - I, D - IV.

India’s #1 Learning Platform Start Complete Exam Preparation Daily Live MasterClasses Practice Question Bank Mock Tests & Quizzes Trusted by 6.1 Crore+ Students

Compiler Design Question 4:

The number of tokens in the following line: int main()
int a = 1, b = 2;
printf("Sum is:%d",a+b);
return 0;
>

Answer (Detailed Solution Below)

Option 2 : 27

Compiler Design Question 4 Detailed Solution

The correct answer is 27

Explanation:

Total number of tokens = 4 + 1 + 9 + 9 + 3 + 1 = 27 tokens

India’s #1 Learning Platform Start Complete Exam Preparation Daily Live MasterClasses Practice Question Bank Mock Tests & Quizzes Trusted by 6.1 Crore+ Students

Compiler Design Question 5:

Arrange the following stages of the lexical analysis process in the correct order: A. Token classification
B. Tokenization
C. Input preprocessing
D. Output generation
E. Token validation

  1. C, B, A, E, D
  2. B, C, A, E, D
  3. C, B, E, A, D
  4. A, B, C, E, D

Answer (Detailed Solution Below)

Option 1 : C, B, A, E, D

Compiler Design Question 5 Detailed Solution

The correct answer is C, B, A, E, D

Key Points

India’s #1 Learning Platform Start Complete Exam Preparation Daily Live MasterClasses Practice Question Bank Mock Tests & Quizzes Trusted by 6.1 Crore+ Students

Top Compiler Design MCQ Objective Questions

Compiler Design Question 6

A set of instructions executed directly by a computer's central processing unit is _____.
  1. Command Language
  2. Machine Language
  3. Markup Language
  4. Style Sheet Language

Answer (Detailed Solution Below)

Option 2 : Machine Language

Compiler Design Question 6 Detailed Solution

Programs written in high-level languages are translated into assembly language or machine language by a compiler. Every CPU has its unique machine language.

Share on Whatsapp

India’s #1 Learning Platform Start Complete Exam Preparation Daily Live MasterClasses Practice Question Bank Mock Tests & Quizzes Trusted by 6.1 Crore+ Students

Compiler Design Question 7

The number of tokens in the following C code segment is switch(inputvalue) < case 1 : b = c * d; break; default : b = b++; break; >

Answer (Detailed Solution Below)

Option 3 : 26

Compiler Design Question 7 Detailed Solution

Concept:

A token is a sequence of characters that can be treated as a unit in the grammar of the programming languages.

Lexical Analysis is the first phase of compiler also known as scanner. It converts the High level input program into a sequence of Tokens.

Explanation

Analysing the given code for tokens, we get

F1 Raju.S 23-04-2020 Savita D1

Counting all the boxes, the total number of tokens comes out to be 26.

Important Point:

For example, printf(“Testbook has tests for GATE, ISRO, etc.”); has 5 tokens.

printf, (, “Testbook has tests for GATE, ISRO, etc.”, ), and ;

Share on Whatsapp

India’s #1 Learning Platform Start Complete Exam Preparation Daily Live MasterClasses Practice Question Bank Mock Tests & Quizzes Trusted by 6.1 Crore+ Students

Compiler Design Question 8

Match the following:
(P) Lexical analysis (i) Leftmost derivation
(Q) Top down parsing (ii) Type checking
(R) Semantic analysis (iii) Regular expressions
(S) Runtime environments (iv) Activation records
  1. P – i, Q – ii, R – iv, S - iii
  2. P – iii, Q – i, R – ii, S - iv
  3. P – ii, Q – iii, R – I, S - iv
  4. P – iv, Q – I, R – ii, S - iii

Answer (Detailed Solution Below)

Option 2 : P – iii, Q – i, R – ii, S - iv

Compiler Design Question 8 Detailed Solution

Lexical analysis: Lexical analysis is the first phase of a compiler. It takes the modified source code from language pre-processors that are written in the form of sentences. Lexical analyser breaks these syntaxes into a series of tokens. Lexical analysis uses regular expression to recognize identifiers.

Top down parsing: Top down parsing technique parses the input by starts constructing a parse tree from the root node moving down to the leaf nodes. Top down parser uses the left most derivation to generate the string.

Semantic analysis: Semantic analysis is the task of ensuring that declarations and statements of a program are semantically correct. For this, it uses type casting.

Run time environments: Run time environment is a state of the target machine, which may include software libraries, environment variables etc. to provide services to the processes running in the system. Activation records of a function are loaded into stack at runtime.