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

Bahria University Lahore Campus Department of Computer Science

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 name and code, instructor name, student name and ID, date, and assignment number and marks. It then lists 5 code snippets and asks the student to identify the tokens and lexemes in each one. It also asks the student to write a C++ or Java program that can remove whitespace from a string, remove comments from a source file, and recognize various elements like constants, keywords, identifiers, operators and numbers. The deadline given for submission is Sunday 20th March 2022 before 11:45PM via the Learning Management System.

Uploaded by

Abdullah Arshad
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
96 views

Bahria University Lahore Campus Department of Computer Science

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 name and code, instructor name, student name and ID, date, and assignment number and marks. It then lists 5 code snippets and asks the student to identify the tokens and lexemes in each one. It also asks the student to write a C++ or Java program that can remove whitespace from a string, remove comments from a source file, and recognize various elements like constants, keywords, identifiers, operators and numbers. The deadline given for submission is Sunday 20th March 2022 before 11:45PM via the Learning Management System.

Uploaded by

Abdullah Arshad
Copyright
© © All Rights Reserved
Available Formats
Download as 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