Javatpoint Logo
Javatpoint Logo

Compiler Design MCQ

1) Users write the programs in which language?

  1. Low-level Language
  2. High-Level Language
  3. Decimal-Format
  4. Middle-Level Language

Answer: b. High-Level Language

Explanation: Users write the program in a high-level language because it is easier to use, understand and remember.


2) Which computer program accepts the high-level language and converts it into assembly language?

  1. Interpreter
  2. Linker
  3. Assembler
  4. Compiler

Answer: d. Compiler

Explanation: Compiler is a computer program that accepts the code written in a high-level language and converts that code into the assembly language.


3) Does the compiler program translate the whole source code in one step?

  1. No
  2. Depends on the Compiler
  3. Don't Know
  4. Yes

Answer: d. Yes

Explanation: The compiler is that program which translates the whole high-level code into the machine code at once.


4) Which of the following file is an output of the assembler?

  1. Program file
  2. Object file
  3. Data File
  4. Task File

Answer: b. Object File

Explanation: The object file contains the object code, which is an output of an assembler.


5) Which tool is used for grouping of characters in tokens in the compiler?

  1. Parser
  2. Code optimizer
  3. Code generator
  4. Scanner

Answer: d. Scanner

Explanation: Scanner is a subroutine which is called by the compiler program. The scanner combines the characters and implements them to produce tokens.


6) What is the linker?

  1. It is always used before the program execution.
  2. It is required to create the load module.
  3. It is the same as the loader
  4. None of the above

Answer: b. It is required to create the load module.

Explanation: Linker is a program in the compiler which is required to create a load module.


7) Parsing is categorized into how many types?

  1. three types
  2. four types
  3. two types
  4. five types

Answer: c. two types

Explanation: In the compiler design, the parser is mainly categorized into top-down parsing and bottom-up parsing.


8) In which parsing, the parser constructs the parse tree from the start symbol and transforms it into the input symbol.

  1. Bottom-up parsing
  2. Top-down parsing
  3. None of the above
  4. Both a and b

Answer: b. Top-Down Parsing

Explanation: Top-down parsing is a technique which constructs the parse tree from the start symbol and transforms it to the input symbol. This type of parsing is also referred to as predictive or recursive parsing.


9) Which derivation is generated by the top-down parser?

  1. Right-most derivation in reverse
  2. Left-most derivation in reverse
  3. Right-most derivation
  4. Left-most derivation

Answer: d. Left-most derivation

Explanation: Top-down parser generates the left-most derivation. It constructs the parse tree from left to right and constructs the left-most derivation of the specified sentence.


10) Which derivation is generated by the bottom-up parser?

  1. Right-most derivation in reverse
  2. Left-most derivation in reverse
  3. Right-most derivation
  4. Left-most derivation

Answer: a. Right-most derivation in reverse.

Explanation: Bottom-up parser generates the right-most derivation in reverse. It constructs the parse tree from the input string to the root and tries to construct the right-most derivation of the specified string backward.


11) Which parser is most powerful in the following parsers?

  1. Operator Precedence
  2. SLR
  3. Canonical LR
  4. LALR

Answer: c. Canonical LR

Explanation: Canonical LR (CLR) is the most powerful parser than LALR and SLR.


12) The output of the lexical analyzer is _______

  1. string character
  2. a syntax tree
  3. a set of RE
  4. a set of tokens

Answer: d. a set of tokens

Explanation: Lexical analyzer gives the set of tokens as output. The set of tokens contains keywords, separators, literals, identifiers, and operators.


13) From the following grammars, which describes the lexical syntax?

  1. Lexical Grammar
  2. Context-free Grammar
  3. Syntactic Grammar
  4. Regular Grammar

Answer: a. Lexical Grammar

Explanation: Lexical grammar is a type of grammar which specifies the syntax of tokens.


14) Which grammar gives multiple parse trees for the same string?

  1. Unambiguous
  2. Regular
  3. Ambiguous
  4. All of the above

Answer: c. Ambiguous

Explanation: Ambiguous grammar is a context-free grammar which gives more than one leftmost or rightmost derivation for the same specified sentence.


15) In Compiler lexical analyzer is used for?

  1. removing comments
  2. removing whitespace
  3. breaking the syntaxes in the set of tokens
  4. All of the mentioned

Answer: d. All of the mentioned

Explanation: Lexical analyzer is used in the compiler for removing the Whitespace and comments. It is also used in breaking the syntaxes into the set of tokens.


16) Which is considered as the sequence of characters in a token?

  1. Mexeme
  2. Lexeme
  3. Texeme
  4. Pattern

Answer: b. Lexeme

Explanation: Lexemes are the string of alphanumeric characters in a single token. In the source program, lexemes are characters which are identified by the pattern for a token.


17) Which part of the compiler highly used the grammar concept?

  1. Code optimization
  2. Code generation
  3. Parser
  4. Lexical Analysis

Answer: c. Parser

Explanation: The concept of grammar is much used in the parser phase of the compiler.

The parser phase is next to the lexical analysis phase in the compiler. Parser generated the parse tree using the predefined grammar. The parser has two different techniques for creating a different parse tree.


18) Which phase of the compiler checks the grammar of the programming?

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

Answer: d. Syntax Analysis

Explanation: Syntax Analysis is the 2nd phase of the compiler, which checks the given input string is the correct syntax of the programming language.


19) Which of the following component is important for semantic analysis?

  1. Yacc
  2. Lex
  3. Symbol Table
  4. Type Checking

Answer: d. Type checking

Explanation: In the semantic analysis, type checking is an important component because it verifies the program's operations from the semantic conventions.


20) Which phase of the compiler is also known as Scanner?

  1. Syntax Analysis
  2. Lexical Analysis
  3. Semantic Analysis
  4. Code generation

Answer: b. Lexical Analysis

Explanation: The first part of the compiler (lexical analysis) is also known as a scanner. It scans the characters from the source program and implements them to produce tokens.


21) Which phase of the compiler is also known as Parser?

  1. Code Optimization
  2. Semantic Analysis
  3. Syntax Analysis
  4. Lexical Analysis

Answer: c. Syntax Analysis

Explanation: The phase of the compiler next to the lexical analysis phase is also known as Parser.

Syntax analysis or parser accepts the tokens produced by the lexical analysis and gives the parse tree in the output.


22) Which of the following parser is a top-down parser?

  1. An LALR parser
  2. A LR parser
  3. Operator precedence parser
  4. Recursive descent parser

Answer: d. Recursive descent parser

Explanation: Recursive descent parser is a type of top-down parser which generates the parse tree from top to bottom and reads the input string from left to right.


23) Keywords are recognized in a compiler during -

  1. the code generation
  2. the data flow analysis
  3. the lexical analysis of the program
  4. the program parsing

Answer: c. the lexical analysis of the program

Explanation: Keywords are firstly recognized during the lexical analysis of the program in the compiler.


24) Leaf nodes in a parse tree indicate?

  1. sub-terminals
  2. half-terminals
  3. non-terminals
  4. terminals

Answer: d. terminals.

Explanation: All the leaf nodes in the parse tree indicate the terminals. And all the interior nodes indicate non-terminals.


25) Which graph describes the basic block and successor relationship?

  1. Control graph
  2. DAG
  3. Flow graph
  4. Hamilton graph

Answer: c. Flow graph

Explanation: A flow graph is a graph of the compiler which describes the basic blocks and how the program control is passed between the blocks.


26) Which language is accepted by the push-down automata?

  1. Type 0 language
  2. Type 1 language
  3. Type 2 language
  4. Type 3 language

Answer: c. Type 2 language

Explanation: According to the Chomsky hierarchy, push down automata accepts the Type 2 language, which is used for context-free language.


27) The most general phase of structured grammar is?

  1. Context-sensitive grammar
  2. Context-free grammar
  3. Regular grammar
  4. All of these

Answer: a. Context Sensitive Grammar

Explanation: Context-sensitive grammar is the most general phase of structured grammar because, in this grammar, the left-hand side and the right side contain the terminals or non-terminals.


28) In the compiler, the function of using intermediate code is:

  1. to improve the register allocation
  2. to increase the error reporting & recovery.
  3. to make semantic analysis easier.
  4. to increase the chances of re-using the machine-independent code optimizer in other compilers.

Answer: d. to increase the chances of re-using the machine-independent code optimizer in other compilers.

Explanation: After semantic analysis, the intermediate code increases the chances of reusing the machine-independent code optimizer in other compilers.


29) In how many types of optimization can be divided?

  1. two types
  2. three types
  3. four types
  4. five types

Answer: a. two types

Explanation: The code optimization technique is divided into machine-dependent and machine-independent types.


30) The value of which variable is updated inside the loop by a loop-invariant value?

  1. loop
  2. strength
  3. induction
  4. invariable

Answer: c. induction

Explanation: The value of the induction variable is updated inside the loop by a loop-invariant value.


31) Which compiler runs on one machine and generates code for multiple machines?

  1. Multipass compiler
  2. Cross compiler
  3. Optimizing compiler
  4. Onepass compiler

Answer: b. Cross compiler

Explanation: Cross compiler is a compiler which runs on one machine and generates code for more than one machine.


32) Which of the following is not a characteristic of the compiler?

  1. More execution time
  2. Debugging process is slow
  3. The execution takes place after the removal of all syntax errors
  4. Firstly scans the entire program and then transforms it into machine-understandable code

Answer: a. More execution time

Explanation: The compiler does not take more time to execute. So, more execution time is not a characteristic of the compiler.


33) Which phenomenon happens when the non-terminal on the left side is repeated as the first symbol on the right side?

  1. Left-most derivation
  2. Left recursion
  3. Left factoring
  4. Left parsing

Answer: b. Left recursion

Explanation: Left recursion is the process in which non-terminal on the left side of the production is the same on the right side as the leftmost symbol.


34) In which derivation the right-most non-terminal symbol is replaced at each step?

  1. Right look ahead
  2. Right claim
  3. Rightmost
  4. Right non-terminal

Answer: c. Rightmost

Explanation: The rightmost derivation is that derivation of context-free grammar, which replaces the rightmost non-terminal symbol at each step.


35) In which derivation the leftmost non-terminal symbol is replaced at each step?

  1. Left recursion
  2. Left non-terminal
  3. Left pushdown
  4. Leftmost

Answer: d. Leftmost

Explanation: The leftmost derivation is that derivation of context-free grammar which replaces the leftmost non-terminal symbol at each step.


36) The compiler can detect what type of errors?

  1. neither logical nor grammatical error
  2. logical errors only
  3. grammatical errors only
  4. both grammatical and logical errors

Answer: c. grammatical errors only.

Explanation: Compiler is a computer program that detects grammatical errors, not logical errors.


37) Which symbol is not related to context-free grammar?

  1. End symbol
  2. Start symbol
  3. Non-terminal symbol
  4. Terminal symbol

Answer: a. End symbol

Explanation: Context-free grammar is that grammar which consists of the start symbol, set of terminals, set of non-terminal symbols and the set of productions.


38) Which method merges the multiple loops into the single one?

  1. Constant Folding
  2. Loop rolling
  3. Loop fusion or jamming
  4. None of the above

Answer: c. Loop fusion or Loop jamming

Explanation: Loop fusion is an optimization technique which merges the multiple bodies of loops into a single body. This programming technique may reduce the runtime performance of the program.


39) Which parser is known as the shift-reduce parser?

  1. Bottom-up parser
  2. Top-down parser
  3. Both Top-down and bottom-up
  4. None of the Above

Answer: a. Bottom-up parser

Explanation: Bottom-up parser in the compiler is also called the shift-reduce parser.


40) Which of the following tree is the pictorial identification of the derivation?

  1. The oct tree
  2. The parse tree
  3. The binary tree
  4. None of the above

Answer: b. The parse tree

Explanation: The tree which represents the syntactic structure of the string is known as the parse tree. It also indicates the terminal, start symbol, and non-terminal symbols.


41) The full form of YACC is:

  1. Yet Another Computer Computer
  2. Yet Another Computer Compiler
  3. Yet Another Compiler Computer
  4. Yet Another Compiler Compiler

Answer: d. Yet Another Compiler Compiler

Explanation: The full form of YACC is Yet Another Compiler Compiler, which produces the LALR (1) grammar parser.


42) What type of conflicts can occur in the shift-reduce parsing?

  1. reduce/reduce
  2. shift/reduce
  3. Both shift/reduce and reduce/reduce
  4. None of the above

Answer: b. Shift/reduce

Explanation: None


43) Which of the following grammar can be translated into DFAs?

  1. Generic Grammar
  2. Left Linear Grammar
  3. Right Liner Grammar
  4. All of the above

Answer: c. Right Linear Grammar

Explanation: A right linear grammar is that grammar which contains all the non-terminals on the right-hand side at the right ends. This grammar can be simply converted into the DFA.


44) Which algorithm invokes a function GETREG()?

  1. Code motion algorithm
  2. Code optimization algorithm
  3. Intermediate Code
  4. Code generation algorithm

Answer: d. Code generation algorithm

Explanation: Code generation algorithm invokes the GETREG() function to check the status of available registers and the location where the result should be stored. This function also selects the registers for every memory location.


45) FORTRAN programming language is a _______

  1. Turing language
  2. Context-sensitive language
  3. Context-free language
  4. Regular language

Answer: b. Context-sensitive language.

Explanation: Context-sensitive languages are those languages which are defined by context-sensitive grammar.


46) The execution time of the code depends on?

  1. the usage of machine idioms
  2. the way the registers are used
  3. the orders in which the computations are performed
  4. All of the mentioned

Answer: d. All of the mentioned

Explanation: None


47) Which optimization technique is used to reduce the multiple jumps?

  1. Latter optimization technique
  2. Peephole optimization technique
  3. Local optimization technique
  4. Code optimization technique

Answer: b. Peephole optimization technique

Explanation: The peephole optimization technique is used to reduce the memory footprint and the size of code. It is also used to improve the program performance.


48) Which of the following term is used to keep track of the location where the current values of the name are stored?

  1. Register descriptor
  2. Address descriptor
  3. Allocation descriptor
  4. Flag register

Answer: b. Address descriptor

Explanation: The address descriptor is a descriptor of the code generator technique, which keeps track of the memory location.


49) Which of the following are labeled by operator symbol?

  1. Root
  2. Interior nodes
  3. Leaves
  4. Nodes

Answer: b. Interior nodes

Explanation: In the compiler, interior nodes are specified by the operator symbol.


50) DAG is an abbreviation of?

  1. Detecting Acyclic Graph
  2. Data Acyclic Graph
  3. Dynamic Acyclic Graph
  4. Directed Acyclic Graph

Answer: d. Directed Acyclic Graph

Explanation: DAG is a Directed Acyclic Graph, which is constructed using three address code for optimizing the basic blocks.


51) Which of the following is used in various stages or phases of the compiler?

  1. Records
  2. Program
  3. Symbol Table
  4. Table

Answer: c. Symbol Table

Explanation: A symbol table is simply a table which is created and maintained by the compiler and used in various phases of the compiler.


52) Which of the following structure has four fields?

  1. Parse tree
  2. Triples
  3. Indirect Triples
  4. Quadruples

Answer: d. Quadruples

Explanation: Quadruples are a record structure in a compiler with four fields for implementing the three address code.


53) In which of the following tree, the leaf indicates the operand, and the interior node represents the operator.

  1. Syntax tree
  2. Parser tree
  3. Structured tree
  4. Sematic tree

Answer: a. Syntax tree

Explanation: Syntax tree is a tree in the compiler which represents operands by leaf and operator by interior nodes.


54) Which statement is an abstract form of intermediate code?

  1. 3- address
  2. 2-address
  3. address
  4. Intermediate code

Answer: a. 3-address

Explanation: None


55) Which mapping is described by the implementation of the syntax-directed translator?

  1. Parse table
  2. Input
  3. Output
  4. Input-Output

Answer: d. Input-Output

Explanation: Input-Output is a mapping which is described by the implementation of the syntax-directed translator (SDT).


56) Which of the following function is called the canonical collection of LR(0) item.

  1. FIRST
  2. GOTO
  3. COMPUTE
  4. FOLLOW

Answer: b. GOTO

Explanation: GOTO is a function that is called for defining the DFA. And, it is called the canonical collection of LR(0) item.


57) Which of the following option is not a function of the shift-reduce parser?

  1. Reduce
  2. Accept
  3. Go
  4. Shift

Answer: c. Go

Explanation: The shift-reduce parser contains only shift, reduce, error and accept action. That's why Go is not a function of the shift-reduce parser.


58) Which of the following grammar has no two adjacent non-terminals?

  1. Irregular grammar
  2. Regular grammar
  3. Operator
  4. Precedence grammar

Answer: c. Operator

Explanation: Operator grammar is the grammar that does not contain two adjacent non-terminals on the right side of the production. It is that grammar that defines the mathematical operators.


59) DFA is an abbreviation of.

  1. Non Deterministic Finite set Automata
  2. Deterministic Finite Automata
  3. Non Deterministic Finite Automata
  4. Deterministic Finite set Automata

Answer: b. Deterministic Finite Automata

Explanation: The full form of DFA is Deterministic Finite Automata. It is also known as Deterministic Finite Acceptor. The automata read only one symbol from the input string at a time.


60) NFA is an abbreviation of.

  1. Non Deterministic Finite set Automata
  2. Deterministic Finite Automata
  3. Non Deterministic Finite Automata
  4. Deterministic Finite set Automata

Answer: c. Non Deterministic Finite Automata

Explanation: The full form of NFA is Non-Deterministic Finite Automata. It is also known as a Non-Deterministic Finite State-machine. An Automaton gives more than one possible transition of the same state.






Youtube For Videos Join Our Youtube Channel: Join Now

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA