Lab Performance - 01 | CSE 332Section: PC-A | Fall 2022 | Marks: 25 |Time limit: 1 Hour |
Starting time: 8:45, Ending time: 9:45
*You must follow the input output sample criteria*
Problem 1: Write a program for continuous iteration of detecting the number of ‘/’ in a string until someone gives an input of -1
Input: Input contains a string or -1.
Output: Print the number of ‘/’ in a string in a new line continuously after each input.
Sample input:
This // is // 1st input, pressed enter then.
This // is // 2nd input, pressed enter then.
This // is // 3rd input, pressed enter then.
No slashes
-1
Sample output:
4
4
4
0
Sample input:
This // is // 1stinput, pressed// enter then.
This // is // 2nd//input,// pressed// enter then.
-1
Sample output:
6
10
Problem 2: Lexical analyzer is so important. Let’s do a job with it. Write a program to detect the following.
Identifier.
Keywords.
Operators.
Special Symbols.
Consider the following,
[‘int’, ‘float’, ‘do’, ‘while’, ‘True’] for keywords only.
[‘“‘, ‘-’, ‘,’,’>’] for special symbols.
[‘+’, ‘-’, ‘%’, ‘&’, ‘=’] for operators.
Rest for Identifiers.
Input: Input contains a string.
Output: Print the mentioned tokens as well as number of each tokens in the next line of the list.
Sample input:
int a, b = 5;
Sample output:
Identifier: a, b
2
Keywords: int
1
Operators: =
1
Symbols: ,, ;
2
Sample input:
int a, b;
Sample output:
Identifier: a, b
2
Keywords: int
1
Operators:
0
Symbols: ,
1
—-----------------------------------------------------*Good Luck*-----------------------------------------------------