Automata Theory Multiple Choice Questions on “Lexical Analysis”.
1. Lexemes can be referred to as:
a) elements of lexicography
b) sequence of alphanumeric characters in a token
c) lexical errors
d) none of the mentioned
Answer: b
Clarification: A lexeme is a string of characters that form a syntactic unit. It is reasonable to say that is the sequence of alphanumeric characters in a token.
2. If the lexical analyser finds a lexeme with the same name as that of a reserved word,it _________
a) overwrites the word
b) overwrites the functionality
c) generates an error
d) something else
Answer: c
Clarification: Reserved words are known as keywords and they are specific and reserved with its functionality to a language. Thus, getting an input with the same name by the analyzer will generate an error.
3. The methodology to show an error when the analyzer faces a keyword over an user’s input is based on:
a) rule priority
b) longest match rule
c) keyword-out rule
d) none of mentioned
Answer: a
Clarification: The lexical analyzer follows the rule priority where its prioritizes keywords over an input it gets with the same name as that of the keyword and thus generates an error.
4. State true or false:
Statement: A lexical analyzer reads the source code line by line.
a) True
b) False
Answer: b
Clarification: A lexical analyzer reads the source code letter by letter and when it encounters a space or an operator or any special character, it decides that the word is completed.
5.Which among the following statement is correct?
Statement 1: When the analyzer scans ‘int’ and ‘intvalue’, it is not able to decide whether the int leads to a keyword or an identifier.
Statement 2: Longest Match Rule
a) Statement 1 is assertion, Statement 2 is the reason
b) Statement 1 is assertion, Statement 2 is the solution
c) There is no such Statement 2
d) This is not a function of Lexical Analyzer
Answer: b
Clarification: The Longest Match rule states that the lexeme scanned should be determined on the basis of longest match among all the token available.
6. The output of the lexical and syntax analyzer can stated as:
a) parse stream, parse tree
b) token tree, parse tree
c) token stream, parse tree
d) all of the mentioned
Answer: c
Clarification: The lexical analyzer outputs the stream of token which is taken up by syntax analyzer one by one against the production rule and parse tree is generated.
7. Which among the following is not a tool to construct lexical analyzer from a regular expression?
a) lex
b) flex
c) jflex
d) none of the mentioned
Answer: d
Clarification: Lexical analysis is done using few tools such as lex, flex and jflex. Jflex is a computer program that generates lexical analyzers (also known as lexers or scanners) and works apparently like lex and flex. Lex is commonly used with yacc parser generator.
8. A program that performs lexical analysis is termed as:
a) scanner
b) lexer
c) tokenizer
d) all of the mentioned
Answer: d
Clarification: A program which performs lexical analysis is called lexer, scanner or lexer. Nowadays, lexer is combined with a parser which allows syntactic analysis.
9. Lexers and parsers are not found in which of the following?
a) compiler front end processing
b) prettyprinters
c) linters
d) none of the mentioned
Answer: d
Clarification: Lexers and parsers are most commonly used in compilers, but it has more application elsewhere like in prettyprinters or linters(application of stylistic formatting conventions to textfiles, source code, etc.).
10. Which phase of compiler includes Lexical Analysis?
a) 1
b) 2
c) 3
d) Its primary function, not in any phase
Answer: a
Clarification: The first phase of compilation process is called lexical analysis. It fragments the source code into token which is the smallest programming unit of a program.
11. Which of the following characters are ignored while lexical analysis?
a) .
b) =
c) #
d) WhiteSpace
Answer: d
Clarification: The lexical analyzer ignores all the whitespaces and fragments the program into tokens.
12. ____________ is used for grouping up of characters into token.
a) Lexical Analyzer
b) oolex
c) jflex
d) All of the mentioned
Answer: d
Clarification: oolex, flex, lex, jflex, all are lexical analyzer tools which perform the following function.
13. The action of parsing the source code into proper syntactic classes is known as:
a) Parsing
b) Interpretation analysis
c) Lexicography
d) Lexical Analysis
Answer: d
Clarification: Lexical analysis or scanning is the process of parsing the source code into proper syntactic classes. It gets things ready for the parser with lexemes to built the parse tree.
14. Which of the following is the task of lexical analysis?
a) To build the uniform symbol table
b) To initialize the variables
c) To organize the variables in a lexical order
d) None of the mentioned
Answer: a
Clarification: Lexical analysis involves the following task:
a) Building a uniform symbol table
b) Parsing the source code into tokens
c) Building a literal and identifier table
15. The scanner outputs:
a) Stream of tokens
b) Image file
c) Intermediate code
d) Machine code
Answer: a
Clarification: A scanner or a lexical analyzer takes a source code as input and outputs a stream of token after fragmenting the code.
16. The phase of compilation which involves type checking is:
a) Parsing
b) Scanning
c) Syntax directed translation
d) Semantic Analyzer
Answer: c
Clarification: Type checking is a process which is performed during Syntax directed translation.