CompilerMCQ Computer Science

Compilers Questions and Answers – Lexical Analysis – 2

This set of Compilers Multiple Choice Questions & Answers (MCQs) focuses on “Lexical Analysis – 2”.

 

What constitutes the stages of the compilation process?

a) Feasibility study, system, design, and testing

b) Implementation and. documentation

c) Lexical analysis, syntax. Analysis and code generation

d) None of the mentioned

Answer

Answer: c

Explanation: As defined in the compilation process.

The lexical analyzer takes_________as input and produces a stream of_______as output.

a) Source program, tokens

b) Token, source program

c) Either of the two

d) None of the mentioned

Answer

Answer: a

Explanation: As per the definition of Lexical Analyser which states that lexical analysis is the process of converting a sequence of characters into tokens.

Parsing is also known as

a) Lexical Analysis

b) Syntax Analysis

c) Semantic Analysis

d) Code Generation

Answer

Answer: b

Explanation: Parsing or syntactic analysis is the process of analysing a string of symbols and conforming to the rules of grammar.

A compiler program written in a high level language is called

a) Source Program

b) Object Program

c) Machine Language Program

d) None of the mentioned

Answer

Answer: a

Explanation: The input that we give in high level language is also known as the source language.

System program such a compiler are designed so that they are

a) Re-enterable

b) Non-Usable

c) Serially usable

d) None of the mentioned

Answer

Answer: a

Explanation: For the convince of the user compilers are made re-enterable.

Which of the following is not feature of compiler?

a) Scan the entire program first and translate into machine code

b) To remove syntax errors

c) Slow for debugging

d) Execution time is more

Answer

Answer: d

Explanation: The objective of the compiler is clearly not to increase the execution time of the program.

A system program that brings together separately compiled modules of a program into a form language that is suitable for execution

a) Assembler

b) Linking loader

c) Cross compiler

d) None of the mentioned

Answer

 

Answer: b

Explanation: A loader which brings together the functions of a relocating loader with the ability to combine a number of program segments that have been independently compiled into an executable program.

A programmer, by mistakes writes a program to multiply two numbers instead of dividing them, how can this error be detected

a) Compiler

b) Interpreter

c) Compiler or interpreter

d) None of the mentioned

Answer

Answer: d

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

 

The process of forming tokens from an input stream of characters is called_____
a) Liberalisation
b) Characterisation
c) Tokenization
d) None of the mentioned

Answer

Answer: c
Explanation: The process of forming tokens from an input stream of characters is called tokenization.

When expression sum=3+2 is tokenized then what is the token category of 3
a) Identifier
b) Assignment operator
c) Integer Literal
d) Addition Operator

Answer

Answer: c
Explanation:
Lexeme
Token category
Sum “Identifier”
= “Assignment operator”
3 “Integer literal”
+ “Addition operator”
2 “Integer literal”
; “End of statement”.

Which grammar defines Lexical Syntax
a) Regular Grammar
b) Syntactic Grammar
c) Context free Grammar
d) Lexical Grammar

Answer

Answer: d
Explanation: The specification of a programming language often includes a set of rules, the lexical grammar, which defines the lexical syntax.

Two Important lexical categories are
a) White Space
b) Comments
c) None of the mentioned
d) White Space & Comments

Answer

Answer: d
Explanation: Two important common lexical categories are white space and comments.

It has encoded within it information on the possible sequences of characters that can be contained within any of the tokens it handles .Above motioned function is performed by?
a) Scanner
b) Parser
c) Syntactic Analyser
d) All of the mentioned

Answer

Answer: a
Explanation: The first stage, the scanner, is FSM. It has encoded information on the possible sequences of characters that can be contained within any of the tokens it handles .

What goes over the characters of the lexeme to produce a value?
a) Scanner
b) Parser
c) Evaluator
d) Lexical generator

Answer

Answer: a
Explanation: In order to construct a token, the lexical analyzer needs a second stage, the evaluator, which goes over the characters of the lexeme to produce a value.

Lexers are often generated by a lexer generator, same as parser generators,
a) True
b) False

Answer

Answer: a
Explanation: Lexers are often generated by a lexer generator same as parser.

Which one is a lexer Generator
a) ANTLR
b) DRASTAR
c) FLEX
d) All of the mentioned

Answer

Answer: d
Explanation: ANTLR – Can generate lexical analyzers and parsers.
DFASTAR – Generates DFA matrix table-driven lexers in C++.
Flex – variant of the “lex” (C/C++).
Ragel – A state machine and lexer generator with output in C, C++, C#, Objective-C, D, Java, Go and Ruby.

Which of the lexical analyser can handle Unicode
a) Java CC
b) JFLex
c) Quex
d) All of the mentioned

Answer

Answer: d
Explanation: JavaCC – JavaCC generates lexical analyzers written in Java.
JFLex – A lexical analyzer generator for Java.
Quex – A fast universal lexical analyzer generator for C and C++.
FsLex – A lexer generator for byte and Unicode character input for F#.

The output of a lexical analyzer is
a) Machine Code
b) Intermediate Code
c) Stream of Token
d) Parse Tree

Answer

Answer: c
Explanation: The output given is in form of tokens.

Next…..

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button