0% found this document useful (0 votes)
10 views

Spring 2024_CS606_1

The document is an assignment for a Compiler Construction course, requiring the identification of tokens produced by a lexical analyzer from a given code snippet. It includes a table listing the tokens along with their corresponding types, such as keywords, identifiers, operators, and literals. The assignment is due on April 29, 2024, and is worth a total of 20 marks.

Uploaded by

asjadasjad19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Spring 2024_CS606_1

The document is an assignment for a Compiler Construction course, requiring the identification of tokens produced by a lexical analyzer from a given code snippet. It includes a table listing the tokens along with their corresponding types, such as keywords, identifiers, operators, and literals. The assignment is due on April 29, 2024, and is worth a total of 20 marks.

Uploaded by

asjadasjad19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

CS606 – Compiler Construction Total marks = 20

Assignment # 01 Deadline
th
29 of April 2024
Name : Asjad Subhan BC200203447

Question No 01 Marks (20)


Consider the following stream of characters as input to the lexical analyzer (i.e., scanner);

for (int i = 0; i < 10; i++) {


if (i % 2 == 0) {
cout << "Even number: " << i << endl;
} else {
cout << "Odd number: " << i << endl;
}
}

You are required to find the tokens produced by lexical analyzer and write them along with their types (types
are given below) in the following sample table.

Solution:

table with the tokens produced by the lexical analyzer along with their types:

Token Type
for Keyword
( Parenthesis
int Keyword
i Identifier
= Operator
0 Integer
; Semicolon
i Identifier
< Operator
10 Integer
; Semicolon
i++ Identifier
) Parenthesis
{ Brace
if Keyword
( Parenthesis
i Identifier
% Operator
2 Integer
== Operator
0 Integer
) Parenthesis
{ Brace
cout Identifier
Token Type
<< Operator
"Even number: " String Literal
<< Operator

i Identifier

<< Operator

endl Identifier

; Semicolon

} Brace

else Keyword

{ Brace

cout Identifier

<< Operator

"Odd number: " String Literal

<< Operator

i Identifier

<< Operator

endl Identifier

; Semicolon

} Brace

} Brace

You might also like