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

Assignment Solution of CS606

Uploaded by

alishhid6
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)
217 views

Assignment Solution of CS606

Uploaded by

alishhid6
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/ 3

Assignment Solution of (CS606)

Student ID : BC200412619

Student Name : Ali Shahid

Assignment Topic : --

VIRTUAL UNIVERSITY OF PAKISTAN

Question:

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.

Sol:

No. Token Type


1 for Keyword
2 ( Separator
3 int Keyword
4 i Identifier
5 = Operator
6 0 Constant
7 ; Separator
No. Token Type
8 i Identifier
9 < Operator
10 10 Constant
11 ; Separator
12 i Identifier
13 ++ Operator
14 ) Separator
15 { Separator
16 if Keyword
17 ( Separator
18 i Identifier
19 % Operator
20 2 Constant
21 == Operator
22 0 Constant
23 ) Separator
24 { Separator
25 cout Identifier
26 << Operator
27 "Even number: " String
28 << Operator
29 i Identifier
30 << Operator
31 endl Identifier
32 ; Separator
33 } Separator
34 else Keyword
35 { Separator
36 cout Identifier
37 << Operator
38 "Odd number: " String
39 << Operator
40 i Identifier
41 << Operator
42 endl Identifier
43 ; Separator
44 } Separator
45 } Separator
According to the lexical rules of the language, these tokens consist of keywords,
identifiers, operators, constants, strings, and separators.

You might also like