0% found this document useful (0 votes)
63 views3 pages

CD Lab Exam

This document contains 9 questions related to writing programs to perform various lexical analysis tasks using finite state machines and regular expressions. The tasks include counting tokens in a file, extracting words based on starting characters, identifying operators and comments as tokens, recognizing different types of numbers, parsing string and character literals, removing left-factoring and left-recursion from context-free grammars, and generating predictive parsing tables and stack implementations from grammars and input strings.

Uploaded by

Smily Charyjo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views3 pages

CD Lab Exam

This document contains 9 questions related to writing programs to perform various lexical analysis tasks using finite state machines and regular expressions. The tasks include counting tokens in a file, extracting words based on starting characters, identifying operators and comments as tokens, recognizing different types of numbers, parsing string and character literals, removing left-factoring and left-recursion from context-free grammars, and generating predictive parsing tables and stack implementations from grammars and input strings.

Uploaded by

Smily Charyjo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

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

You might also like