The document describes a coding assignment to analyze a code snippet and identify the tokens. It provides the code snippet to analyze, which is a for loop printing even and odd numbers. It then lists the tokens identified in the code snippet along with their type.
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 ratings0% found this document useful (0 votes)
461 views2 pages
CS606 Assignment 1 Solution
The document describes a coding assignment to analyze a code snippet and identify the tokens. It provides the code snippet to analyze, which is a for loop printing even and odd numbers. It then lists the tokens identified in the code snippet along with their type.
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
Assignment # 01 Spring 2024
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; } }
Solution:
No. Token Type
1 For Keyword 2 ( Symbol 3 int Keyword 4 i Identifier 5 = Symbol 6 0 Integer 7 ; Symbol 8 i Identifier 9 < Symbol 10 10 Integer 11 ; Symbol 12 I ++ Identifier 13 ) Symbol 14 { Symbol 15 If Keyword 16 ( Symbol 17 i Identifier 18 % Symbol 19 2 Integer 20 == Symbol 21 0 Integer 22 ) Symbol 23 { Symbol 24 cout Identifier 25 << Symbol 26 “Even Number” String 27 << Symbol 28 i Identifier 29 << Symbol 30 endl Identifier 31 ; Symbol 32 } Symbol 33 else Keyword 34 { Symbol 35 Cout Identifier 36 << Symbol