quiz Lexical Analysis

Lexical Tokenization Overview

1. What is the primary purpose of the lexical analysis phase in a compiler?

  • A) To generate machine code
  • B) To optimize code
  • C) To convert source code into tokens
  • D) To perform type-checking
C) To convert source code into tokens Explanation

2. What is a common tool used for generating lexical analyzers?

  • A) yacc
  • B) lex
  • C) gcc
  • D) make
B) lex Explanation

3. Which of the following is an example of a token name in lexical tokenization?

  • A)  x = a + b * 2;
  • B) Identifier
  • C) Lexeme
  • D) Syntax tree
B) Identifier Explanation

4. Which method is commonly used by lexers to identify tokens?

  • A) Binary search
  • B) Regular expressions
  • C) Context-free grammar
  • D) Linear regression
B) Regular expressions Explanation

5. What is the typical format of a token generated by a lexical analyzer?

  • A) {Token type, Token value}
  • B) {Token ID, Token value}
  • C) {Token value, Token length}
  • D) {Token name, Token position}
A) {Token type, Token value} Explanation