Assignment-1 Nadeem Sarwar
Assignment-1 Nadeem Sarwar
Assignment-1 Nadeem Sarwar
Enrollment:03-134201-030
Q1. Identify the <token ,lexeme> pairs
Tokens Lexeme
For keyword
( symbols
int keyword
x identifier
= operators
0 constants
; symbols
x identifier
< operators
= operators
5 constants
; symbols
x identifier
+ operators
+ operators
) symbols
2. B= (( c + a) * d ) / f
Tokens Lexeme
B Identifier
= operators
( symbol
( symbol
c identifier
+ operators
a identifier
) symbol
* operators
d Identifier
) symbol
/ symbol
f identifier
3. While ( a < 5 )
a= a+1
Tokens Lexeme
While keyword
( symbol
a identifier
< operators
5 constant
) symbol
a identifier
= operators
a identifier
+ operator
1 constant
4. Char MyCourse[5];
Tokens Lexeme
Char keyword
MyCourse identifier
[ symbol
5 constants
] symbol
; symbol
5. if ( a< b)
a=a*a;
else
b=b*b;
Tokens Lexeme
if keyword
( symbol
a identifier
< operators
b identifier
) symbol
a identifier
= operators
a identifier
* operators
a identifier
; symbol
else keyword
b identifier
= operators
b identifier
* operators
b identifier
; symbol
Q2. Write a program in C++ or Java that reads a source file and performs the followings operations:
#include <iostream>
#include<string>
using namespace std;
void removeblanks(char* str)
{
int count = 0;
for (int i = 0; str[i]; i++)
if (str[i]!= ' ')
str[count++] = str[i];
str[count] = '\0';
}
int main()
{
char str[] = "My name is Abdullah";
removeblanks(str);
cout << str;
return 0;
}
2. Removal of comments
3. Recognizes constants
4. Recognizes Keywords
5. Recognizes identifiers
6. Recognize operators
7. Recognize numbers
Deadline:
Sunday, 20-March-2022 before 11:45 PM (Via LMS)