Tokens MCQ Quiz in मराठी - Objective Question with Answer for Tokens - मोफत PDF डाउनलोड करा
Last updated on Mar 13, 2025
Latest Tokens MCQ Objective Questions
Top Tokens MCQ Objective Questions
Tokens Question 1:
Consider statement in C programming language
a + = b >> 24 ! = 4;
The number of tokens identified by the lexical phase while scanning the above statements is ____.
Answer (Detailed Solution Below) 8
Tokens Question 1 Detailed Solution
The first phase of compiler is called lexical analysis or scanning. The lexical analyzer reads the stream of characters making up the source program and groups the characters into meaningful sequence called lexemes.
For each lexeme, the lexical analyzer produces as output a token of the form that it passes on to the subsequent phase, syntax analysis.
Tokens in given statement:
a |
identifier |
+ = |
assignment operator |
b |
identifier |
>> |
bitwise operator |
24 |
number |
! = |
relational operator |
4 |
number |
; |
statement terminator |
Therefore, there are 8 tokens
Tokens Question 2:
Match the compiler phase with the output it produces.
A. Lexical Analysis |
1. Machine code |
B. Syntax Analysis |
2. Token stream |
C. Intermediate Code Generation |
3. Parse Tree |
D. Code Generator |
4. Three address code |
Answer (Detailed Solution Below)
Tokens Question 2 Detailed Solution
Phases in a compiler:
The correct answer: A → 2, B → 3, C → 4, D → 1.
Important Point:
A parse tree is also called syntax tree
Three address code is one of the intermediate representation.
Tokens Question 3:
Number of tokens in the given statement is?
printf(“Hello”);
Answer (Detailed Solution Below)
Tokens Question 3 Detailed Solution
tokens are
1. printf
2. (
3. “Hello”
4. )
5. ;
Tokens Question 4:
Which of the following is not a token of C program
Answer (Detailed Solution Below)
Tokens Question 4 Detailed Solution
A token is a sequence of characters that can be treated as a single logical entity. C tokens are the basic building blocks in C language which are constructed together to write a C program.
● Each and every smallest individual unit in a C program are known as C tokens.
● C tokens are of six types. They are,
1.Keywords (eg: int, while),
2.Identifiers (eg: main, total, MAX),
3.Constants (eg: 10, 20, 1.02e+2),
4.Strings (eg: “total”, “hello”, "Testbook"),
5.Special symbols (eg: (), {}),
6.Operators (eg: +, /,-,*)
#define is C Preprocessor, which is not part of the compiler but is a separate step in the compilation process. So it is not a token.
Tokens Question 5:
If C is a programming language, then which of the following can be a token produced by lexical analysis phase?
Answer (Detailed Solution Below)
Tokens Question 5 Detailed Solution
- The first phase of compiler is called lexical analysis or scanning. The lexical analyzer reads the stream of characters making up the source program and groups the characters into meaningful sequence called lexemes. For each lexeme, the lexical analyzer produces as output a token of the form that it passes on to the subsequent phase, syntax analysis.
- Tokens may be of the form of identifiers, keywords, constants etc. from the input program.
“testbook” | string |
++ |
unary operator (incremental operator) |
/= |
Assignment operator |
goto |
keyword |
All operators are token
a /= 2
a = a/2
Therefore option all option are correct
Tokens Question 6:
Which of the following is/are true?
I. Keyword are determined during parsing of a language
II. The output of a lexical analyzer is parse tree
III. Type checking is done during parsingAnswer (Detailed Solution Below)
Tokens Question 6 Detailed Solution
- Lexical analysis is the process of converting a sequence of characters into a sequence of tokens. A token can be a keyword. Therefore, keyword of a language is determined during lexical analysis of the program and output of a lexical analyzer is tokens
- Type checking is done at semantic analysis phase and parsing is done at syntax analysis phase.
Tokens Question 7:
The number of tokens in the following C statement is
int i = 10;
float b = 12.0;
printf("x = %i, y = %f", i++, ++b);Answer (Detailed Solution Below) 21
Tokens Question 7 Detailed Solution
Line no. |
Tokens |
Number of Tokens |
Line 1 |
int | i | = | 10 | ; | |
5 |
Line 2 |
float | b | = | 12.0 | ; | |
5 |
Line 3 |
Printf | ( | "x = %i, y = %f" | , | i |++ | , | ++ |b | ) | ; |
|
11 |
Total Number of tokens = 5 + 5 + 11 = 21
Notes:
| is used to separate the token
Tokens Question 8:
Consider the following statements:
S1: New entries are created in symbol table for each new identifier during lexical analysis.
S2: Lexical analyzer detects ill-formed numeric literals and input characters that are not in the source language.
Which of the following is true?
Answer (Detailed Solution Below)
Tokens Question 8 Detailed Solution
The correct answer is option 3 i.e. Both S1 and S2.
A lexical analyzer creates a symbol-table entry as soon as it sees the characters that make up a lexeme. Also, it detects ill-formed numeric literals and input characters that are not in the source language.
Tokens Question 9:
The number of tokens in the following C statements is
printf ("i = %d, j = %f, &i = %x\n", i, j, &i);
Answer (Detailed Solution Below)
Tokens Question 9 Detailed Solution
The correct answer is option 3.
Concept:
A lexical token is a sequence of characters that can be treated as a unit in the grammar of the programming languages.
Example of tokens:
Type token (id, number, real, . . . )
Punctuation tokens (IF, void, return, . . . )
Alphabetic tokens (keywords)
Explanation:
printf ("i = %d, j = %f, &i = %x\n", i, j, &i);
Hence the correct answer is 12.
Tokens Question 10:
The number of tokens in the following C statement is
int i = 10;
float b = 12.0;
printf("x = %i, y = %f", i++, ++b);Answer (Detailed Solution Below)
Tokens Question 10 Detailed Solution
Line no. |
Tokens |
Number of Tokens |
Line 1 |
int | i | = | 10 | ; | |
5 |
Line 2 |
float | b | = | 12.0 | ; | |
5 |
Line 3 |
Printf | ( | "x = %i, y = %f" | , | i |++ | , | ++ |b | ) | ; | |
11 |
Total Number of tokens = 5 + 5 + 11 = 21
Notes:
| is used to separate the token