0% found this document useful (0 votes)
384 views7 pages

Assignment-1 Nadeem Sarwar

This document contains information about an assignment for a Compiler Construction course at Bahria University Lahore Campus. It provides details of the assignment such as the course code, instructor name, student name and ID, date, and assignment number and marks. The assignment asks students to identify tokens and lexemes for code snippets and write a C++ program to perform lexical analysis tasks such as removing whitespace and comments, and recognizing constants, keywords, identifiers, operators, and numbers. The deadline for submission is provided.

Uploaded by

Abdullah Arshad
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)
384 views7 pages

Assignment-1 Nadeem Sarwar

This document contains information about an assignment for a Compiler Construction course at Bahria University Lahore Campus. It provides details of the assignment such as the course code, instructor name, student name and ID, date, and assignment number and marks. The assignment asks students to identify tokens and lexemes for code snippets and write a C++ program to perform lexical analysis tasks such as removing whitespace and comments, and recognizing constants, keywords, identifiers, operators, and numbers. The deadline for submission is provided.

Uploaded by

Abdullah Arshad
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/ 7

Bahria University Lahore Campus

Department of Computer Science


BS(CS) Program, Semester 05 Spring 2022
Course: Compiler Construction (CSC-323)
INSTRUCTOR: Nadeem Sarwar
Student name: ID: Section: A

Date: 14/03/2022 Assignment # 01 Marks: 5

Name: Abdullah Arshad

Enrollment:03-134201-030
Q1. Identify the <token ,lexeme> pairs

1. For ( int x= 0; x<=5; x++)

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;
}

1. Removal of white space

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)

You might also like