CD Lab Exam Questions
1)
a) Write a program to count number of whitespaces and new lines in given inputfile by using
transition diagram.
Inputfile : int main()
{
Hi aziz
printf(hi )
}
Output: Whitespaces = 8
New lines = 6
b) Write a Lex program to print the words whose starting letter as vowels in given input file.
Input file: Your skills of writing Paragraph will make you a perfect man.If
you look at any printed prose book,
you will see that each chapter is divided up into sections
Output: of, a, If, at, any etc....
2)
a) Write a program to indetify reloop operators as tokens in given input program fragment
by using transition diagram.
Input file:
int a >> 10;
int mail();
Printf(a>10m, a++)
if(a==!);
Output: >>, leftshift
>, grater than
==, equal to etc....
b) Write a Lex program to capitalize the comments in given input file
Input:
Output:
Input:
Output:
Input:
Output:
Input:
Output:
1) Hi aziz
Hi AZIZ
2) Hi AZIZ
HI AZIZ
3) hi AZIZ
hi AZIZ
4) hi aziz
hi aziz
3) Write a program to identify single line comment and double line comments as tokens in given
input program fragment by using transition diagram.
Input: // Single line comment
int main ()
/* dounle line comment */
Printf();
Hi program int float a=3;
/* int main()
printf() */
Output: // Single line comment single line comment
/* dounle line comment */ dounle line comment
/* int main()
printf() */
dounle line comment
4) Write a program to identify all type of nembers as tokens in given program fragment by using
transition diagram.
Ex: 420, -420, 0.420, -0.420, .420, 4.2E0,4.2E+0, etc....
5) Write a program to identify the string literals and character literals as tokens in given program
fragment.
Input: int c = Aziz;
int c = 'A';
printf(% I hate U) ;
Aziz
'A
'Aziz'
Output: Aziz String literal
'A'
Character literal
% I hate U String literal
Aziz Error
'A Error
'Aziz' Error
6) Write a program to implement the removel of leftfactoring in given CFG.
7) Write a program to implement the removel of direct and indirect left recursion in given CFG.
8) Write a program to find the FIRST and FOLLOW for given CFG. Assume that the given CFG is
free of ambiguity.
9) Write a program to implement pridictive parsing table and stack implementation to given CFG.
Input: CFG, FIRST, FOLLOW, String w.
Output: PPT, Stack implementation