Cse420 Lab 1
Cse420 Lab 1
Lab 01
Introduction
I. Topic Overview:
The lab is designed to introduce the students to the basics steps of a compiler Design.
After that the lab will focuses and dive deep into the first compilation step which is
Lexical analysis. Basic techniques of coding and required tools will also be shown to
students.
Page 2 of
[distinct]. See the example for more details. You can assume that, there will be a space after each
keywords. But, removal of space will add bonus point.
Task 1: For the following sample program find all the tokens.
Note that a lexical Analyzer is responsible for
1. Scan Input
2. Remove WS, NL, ...
3. Identify Tokens
4. Create Symbol Table (ST)
5. Insert Tokens into ST
6. Generate Errors
7. Send Tokens to Parser
Input:
int a, b, c;
float d, e;
a = b = 5;
c = 6;
if ( a > b)
{
Page 3 of
c = a - b;
e = d - 2.0;
}
else
{
d = e + 6.0;
b = a + c;
}
Output:
Keywords: int, float, if, else
Identifiers: a, b, c, d, e
Math Operators: +, -, =
Logical Operators: >
Numerical Values: 5, 6, 2.0, 6.0
Others: , ; ( ) { }
Page 4 of