Compiler Design MCQ (Multiple Choice Questions)

Here are 1000 MCQs on Compiler Design (Chapterwise).

1. What is a compiler?
a) system program that converts instructions to machine language
b) system program that converts machine language to high-level language
c) system program that writes instructions to perform
d) None of the mentioned
View Answer

Answer: a
Explanation: A compiler is a system program that converts instructions in form of code to machine understandable language.

2. Which of the following is a stage of compiler design?
a) Semantic analysis
b) Intermediate code generator
c) Code generator
d) All of the mentioned
View Answer

Answer: d
Explanation: The phases of a compiler are:
1. Lexical analysis
2. Syntax analysis
3. Semantic analysis
4. Intermediate code generator
5. Code optimizer
6. Code generator

3. What is the use of a symbol table in compiler design?
a) Finding name’s scope
b) Type checking
c) Keeping all of the names of all entities in one place
d) All of the mentioned
View Answer

Answer: d
Explanation: Both the analysis and synthesis components of a compiler use the symbol table.
i) To keep all of the names of all entities in one place in a systematic format.
ii) To determine whether or not a variable has been declared.
iii) Type checking is implemented by ensuring that assignments and expressions in source code are semantically accurate.
iv) To figure out what a name’s scope is (scope resolution).

4. Which of the following error can a compiler check?
a) Syntax Error
b) Logical Error
c) Both Logical and Syntax Error
d) Compiler cannot check errors
View Answer

Answer: a
Explanation: Logic flaws can never be checked by a compiler.

5. A programmer, writes a program to multiply two numbers instead of dividing them by mistake, how can this error be detected?
a) Compiler or interpreter
b) Compiler only
c) Interpreter only
d) None of the mentioned
View Answer

Answer: d
Explanation: This is a logical error that can’t be detected by any compiler or interpreter.
advertisement
advertisement

6. Who is responsible for the creation of the symbol table?
a) Assembler
b) Compiler
c) Interpreter
d) All of the mentioned
View Answer

Answer: b
Explanation: The compiler generates a symbol table, which contains a list of lexemes or tokens.

7. Which of the following is known as a compiler for a high-level language that runs on one machine and produces code for a different machine?
a) Cross compiler
b) Multipass compiler
c) Optimizing compiler
d) One pass compiler
View Answer

Answer: a
Explanation: So done by the definition.

8. Which of the following is a system program that integrates a program’s individually compiled modules into a form that can be executed?
a) Interpreter
b) Assembler
c) Compiler
d) Linking Loader
View Answer

Answer: d
Explanation: A loader that combines the functionality of a relocation loader with the ability to combine a number of independently compiled program segments.

9. Which of the following is a definition of compiler?
a) Acceptance of a program written in a high-level language and produces an object program
b) Program is put into memory and executes it
c) Translation of assembly language into machine language
d) None of the mentioned
View Answer

Answer: a
Explanation: A compiler is a software (or combination of programs) that converts source code written in one programming language (the source language) into code written in another programming language (the target language) (the target language, often having a binary form known as object code).

10. Which of the following phase of the compiler is Syntax Analysis?
a) Second
b) Third
c) First
d) All of the mentioned
View Answer

Answer: a
Explanation: It is the Second Phase of the Compiler after Lexical Analyzer. It is also called Hierarchical Analysis or Parsing.

11. Which of the following concept of FSA is used in the compiler?
a) Code optimization
b) Code generation
c) Lexical analysis
d) Parser
View Answer

Answer: c
Explanation: Because the lexer performs its analysis by going from one stage to another.

12. Which of the following is a part of a compiler that takes as input a stream of characters and produces as output a stream of words along with their associated syntactic categories?
a) Optimizer
b) Scanner
c) Parser
d) None of the mentioned
View Answer

Answer: b
Explanation: A compiler’s scanner scans a character-based input stream and creates a word-based output stream, with each word identified with its Syntactic category.

13. Let L1 = {w ∈ {0,1}∗ | w has at least as many occurrences
of (110)’s as (011)’s}.
Let L2 = { ∈ {0,1}∗ | w has at least as many occurrences
of (000)’s as (111)’s}.
Which of the following is correct?
a) L2 is regular
b) L1 and L2 are regular
c) L1 is regular but not L2
d) None of them are regular
View Answer

Answer: c
Explanation: Let’s look at the string 011011011011 to see if L1 is regular. The number of times 011 has occurred is four, however, it has also occurred three times. We can also produce a 110 if the string ends with 011. The following string is 110110110110, where 110 appears four times and 011 appears three times, already satisfying the.

14. What is CFG?
a) Regular Expression
b) Compiler
c) Language expression
d) All of the mentioned
View Answer

Answer: b
Explanation: They’re defined by the rule A->b, where A isn’t terminal and b is.
advertisement

15. Which of the following is a correct statement?
I. For some programming languages, there are parsing algorithms with an O(3) complexity.
II. A recursive programming language can be constructed with static storage allocation.
III. In the context of bottom-up parsing, no L-attributed definition can be evaluated.
IV. Code-improvement modifications can be carried out at both the intermediate and source code levels.
a) I and III
b) I and IV
c) I, II and IV
d) I, II, III and IV
View Answer

Answer: b
Explanation: In recursion, space is used but recursive calls can’t be calculated by the compiler.

16. Which of the following is correct regarding an optimizer Compiler?
a) Optimize the code
b) Is optimized to occupy less space
c) Both of the mentioned
d) None of the mentioned
View Answer

Answer: d
Explanation: An optimising compiler is a computer programme that strives to minimise or maximise specific characteristics of an executable programme.

17. Which of the following error can Compiler diagnose?
a) Logical errors only
b) Grammatical and logical errors
c) Grammatical errors only
d) All of the mentioned
View Answer

Answer: c
Explanation: Only syntactical errors can be detected by the compiler.

18. In which of the following phase of the compiler is Lexical Analyser?
a) Second
b) Third
c) First
d) All of the mentioned
View Answer

Answer: c
Explanation: Lexical Analyzer is the First Phase of the Compiler.

19. Which of the following does an address code involve?
a) No unary operators
b) Exactly 3 address
c) At most Three address
d) None of the mentioned
View Answer

Answer: d
Explanation: In computer science, three-address is an intermediate code used by optimizing compilers to aid in the implementation of code-improving transformations.
advertisement

20. An object module for a group of programs that were compiled separately is handed to a linker. Which of the following about an object module isn’t true?
a) Relocation bits
b) Names and locations of all external symbols denied in the object module
c) Absolute addresses of internal symbols
d) Object code
View Answer

Answer: c
Explanation: A linker, sometimes known as a link editor, is a computer program that merges one or more object files generated by a compiler into a single executable, library, or another object file.

21. Characters are grouped into tokens in which of the following phase of the compiler design?
a) Code generator
b) Lexical analyzer
c) Parser
d) Code optimization
View Answer

Answer: b
Explanation: Gives tokens as output

22. Why Generation of intermediate code based on an abstract machine model is useful in compilers?
a) Writing for intermediate code generation
b) Portability of the front end of the compiler
c) Implementation of lexical analysis and syntax analysis is made easier
d) All of the mentioned
View Answer

Answer: c
Explanation: Intermediate code generator receives input from its predecessor phase, semantic analyzer, in the form of an annotated syntax tree.

23. Why System program such as compiler are designed?
a) They are Serially usable
b) They are Re-enterable
c) They are Nonreusable
d) All of the mentioned
View Answer

Answer: b
Explanation: Re-enterable is the keyword for compiler being designed.

24. Which of the following technique is used for building cross compilers for other machines?
a) Canadian Cross
b) Mexican Cross
c) X-cross
d) Brazilian Cross
View Answer

Answer: a
Explanation: The Canadian Cross is a technique for building cross compilers for other machines. Given three machines X, Y, and Z, one uses machine X (e.g. running Windows XP on an IA-32 processor) to build a cross compiler that runs on machine Y (e.g. running Mac OS X on an x86-64 processor) to create executables for machine Z.

25. Which of the following can detect an error if a programmer by mistake writes multiplication instead of division?
a) Interpreter
b) Compiler or interpreter test
c) Compiler
d) None of the mentioned
View Answer

Answer: d
Explanation: No Logical errors can’t be detected.


Chapterwise Multiple Choice Questions on Compiler Design

Compiler Design MCQ - Multiple Choice Questions and Answers

Our 1000+ MCQs focus on all topics of the Compiler Design subject, covering 100+ topics. This will help you to prepare for exams, contests, online tests, quizzes, viva-voce, interviews, and certifications. You can practice these MCQs chapter by chapter starting from the 1st chapter or you can jump to any chapter of your choice.
  1. Compiler Introduction
  2. Finite Automata and Regular Expression
  3. Contextfree Grammar and Syntax Analysis
  4. Topdown Parsing
  5. Bottom Up Parsing
  6. Syntax Directed Definition and Translations
  7. Symbol Table
  8. Storage Management
  9. Error Handling
  10. Code Optimisation
  11. Code Generation

1. MCQ on Compiler Introduction

The section contains Compiler Design multiple choice questions and answers on finite automata and regular expressions, cross compilers, lexical analysis and relations.

  • Finite Automata and Regular Expressions – 1
  • Finite Automata and Regular Expressions – 2
  • Cross Compiler – 1
  • Cross Compiler – 2
  • Lexical Analysis – 1
  • Lexical Analysis – 2
  • Regular Expression – 1
  • Regular Expression – 2
  • Relations – 1
  • Relations – 2
  • 3. Compiler Design Multiple Choice Questions on Contextfree Grammar and Syntax Analysis

    The section contains Compiler Design MCQs on syntax analyser, context free grammar, regular grammar as well as right left grammar.

  • Syntax Analyser – 1
  • Syntax Analyser – 2
  • Context Free Grammar – 1
  • Context Free Grammar – 2
  • Regular Grammar – 1
  • Regular Grammar – 2
  • Right Left Linear Grammar – 1
  • Right Left Linear Grammar – 2
  • 4. Compiler Design MCQ on Topdown Parsing

    The section contains Compiler Design multiple choice questions and answers on top-down parsing with its predictives.

  • Top – Down Parsing – 1
  • Top – Down Parsing – 2
  • Predictive Top-Down Parsing
  • 5. Compiler Design Multiple Choice Questions on Bottom Up Parsing

    The section contains Compiler Design questions and answers on bottom-up parsing, right sentinel grammar, l-r parser and parsing table data structures.

  • Bottom – Up Parsing – 1
  • Bottom – Up Parsing – 2
  • Handle of Right Sentinel Grammar – 1
  • Handle of Right Sentinel Grammar – 2
  • LR Parser – 1
  • LR Parser – 2
  • Data Structure for Representing Parsing Table – 1
  • Data Structure for Representing Parsing Table – 2
  • 7. Compiler Design Multiple Choice Questions on Symbol Table

    The section contains Compiler Design multiple choice questions and answers on symbol table management as well as symbol table organization and run time storage.

  • Runtime Storage Location – 1
  • Runtime Storage Location – 2
  • Symbol Table Organization – 1
  • Symbol Table Organization – 2
  • Symbol Table Management – 1
  • Symbol Table Management – 2
  • 8. Compiler Design MCQ on Storage Management

    The section contains Compiler Design questions and answers on storage, stack and static allocations.

  • Storage Allocation – 1
  • Storage Allocation – 2
  • Activation of the Procedure and the Activation Record – 1
  • Activation of the Procedure and the Activation Record – 2
  • Static Allocation – 1
  • Static Allocation – 2
  • Stack Allocation – 1
  • Stack Allocation – 2
  • 9. Compiler Design Multiple Choice Questions on Error Handling

    The section contains Compiler Design MCQs on error handling, lexical phase errors, automatic error recovery with yacc and also l-r phase, predictive parsing error recovery.

  • Error Recovery in LR Phase – 1
  • Error Recovery in LR Phase – 2
  • Error Handling – 1
  • Error Handling – 2
  • Recovery from Lexical Phase Errors – 1
  • Recovery from Lexical Phase Errors – 2
  • Recovery from Syntactic Phase Errors – 1
  • Recovery from Syntactic Phase Errors – 2
  • Automatic Error Recovery in Yacc – 1
  • Automatic Error Recovery in Yacc – 2
  • Predictive Parsing Error Recovery – 1
  • Predictive Parsing Error Recovery – 2
  • Recovery from Semantic Errors – 1
  • Recovery from Semantic Errors – 2
  • 10. Compiler Design MCQ on Code Optimisation

    The section contains Compiler Design multiple choice questions and answers on code optimization, elimination of induction variables, eliminating global common subexpressions, loop optimization, unrolling and jamming.

  • Code Optimization – 1
  • Code Optimization – 2
  • Loop Optimization – 1
  • Loop Optimization – 2
  • Elimination of Induction Variables – 1
  • Elimination of Induction Variables – 2
  • Eliminating Local Common Subexpressions
  • Eliminating Global Common Subexpressions – 1
  • Eliminating Global Common Subexpressions – 2
  • Loop Unrolling – 1
  • Loop Unrolling – 2
  • Loop Jamming – 1
  • Loop Jamming – 2
  • Loop Jamming – 3
  • 11. Compiler Design Multiple Choice Questions on Code Generation

    The section contains Compiler Design questions and answers on code generation, machine model, using dag as code generation and peephole optimization.

  • Code Generation – 1
  • Code Generation – 2
  • Machine Model – 1
  • Machine Model – 2
  • Using Dag for Code Generation – 1
  • Using Dag for Code Generation – 2
  • Peephole Optimization – 1
  • Peephole Optimization – 2
  • If you would like to learn "Compilers" thoroughly, you should attempt to work on the complete set of 1000+ MCQs - multiple choice questions and answers mentioned above. It will immensely help anyone trying to crack an exam or an interview.

    Wish you the best in your endeavor to learn and master Compilers!

    advertisement
    Manish Bhojasia - Founder & CTO at Sanfoundry
    Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

    Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.