Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
81 views

Cod Lab Assignment

The lab assignment involves several tasks related to compiler design including: 1. Analyzing object code and Lex/Flex tools 2. Writing programs for regular expression to DFA conversion, C tokenization, and identifying C integers and floats 3. Eliminating left recursion and finding FIRST and FOLLOW sets 4. Constructing an LL(1) parsing table 5. Implementing the CYK algorithm to recognize strings from a given grammar 6. Developing a grammar in Chomsky Normal Form and applying CYK

Uploaded by

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

Cod Lab Assignment

The lab assignment involves several tasks related to compiler design including: 1. Analyzing object code and Lex/Flex tools 2. Writing programs for regular expression to DFA conversion, C tokenization, and identifying C integers and floats 3. Eliminating left recursion and finding FIRST and FOLLOW sets 4. Constructing an LL(1) parsing table 5. Implementing the CYK algorithm to recognize strings from a given grammar 6. Developing a grammar in Chomsky Normal Form and applying CYK

Uploaded by

Shobhit Sharma
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Lab Assignment: Compiler Design (COD - 632)

1. Analyze the object code


2. Download and analyze the Lex/Flex tool
3. Write a program to Convert regular expression to DFA directly using firstpos(), laspos()
and followpos(). Display the result of firstpos(), laspos() and followpos() before
printing the DFA state transition.
4. Write a C/C++/Java program to tokenize the simple “Hello World” program of C language. First of
all, define the token for this program. The original program should necessarily include few
comments. Display the tokens by removing all the comments, i.e., the comments should be
ignored for tokenization. No predefined function for tokenization is allowed. Assume the
situations, with and without space between the tokens in the program.

Sample I/P in Python Sample Lexical output


print (3 + x *2 ) # comment (keyword , "print")
(delim , "(")
(int , 3)
(punct, "+")
(id , "x")
(punct, "*")
(int, 2)
(delim, ")")

5. Write a Program in Flex which identifies C Integers and float numbers. Your program should
respond to various inputs as follows:

Sample I/P Sample Lexical output


234 Integer
-765 Integer
8234.01 Float

6. Write a program to eliminate the Left Recursion using the given in Algorithm 4.19 (Page No. 213)
of Compilers Principles, Techniques and Tools book.
Sample Grammar Sample output
E -> E + T | T E -> TE’
T -> T * F |F E’ -> +TE’ | Є
F -> (E) | id T -> FT’
T’ -> *FT’ | Є
F -> (E) | id
7. Write a program to find the FIRST for all grammar symbols and FOLLOW for all Non-Terminals in
a given grammar.
Sample Grammar Sample output
E -> TE’ FIRST (E) = {(,id}
E’ -> +TE’ | Є FIRST (T) = {(,id}
T -> FT’ FIRST (F) = {(,id}
T’ -> *FT’ | Є FIRST (E’) = {+, Є}
F -> (E) | id FIRST (T’) = {*, Є}
FIRST (+) = {+}
FIRST (*) = {*}
FIRST (id) = {id} //optional
FIRST (() = {(}
FIRST ()) = {)}

FOLLOW (E) = {), $}


FOLLOW (E’) = {), $}
FOLLOW (T) = {+, ), $}
FOLLOW (T’) = {+, ), $}
FOLLOW (F) = {*,+, ), $}
Note: Write your own algorithm which can produce FIRST and FOLLOW for any grammar.

8. Write a program to construct the LL(1) parsing table or predictive parsing table using the
algorithm given in Algorithm 4.31 (Page No. 224) of Compilers Principles, Techniques and Tools
book. Use the grammar and the FIRST & FOLLOW of the previous experiment and construct the
table.

Sample I/P Grammar Sample output


E -> TE’ M[E,id] = E->TE’
E’ -> +TE’ | Є M[E,(] = E->TE’
T -> FT’ M[E’, +] = E’->+TE’
T’ -> *FT’ | Є M[E’, )] = E’-> Є
F -> (E) | id M[E’, $] = E’-> Є
M[T,id] = T->FT’
M[T,(] = T->FT’
M[T’,+] = T’-> Є
M[T’, *] = T’->*FT’
M[T’, )] = T’-> Є
M[T’, $] = T’-> Є
M[F,id] = F->id
M[F,(] = F->(E)

9. Consider following grammar


S →EF|AF|EB|AB
X→AY|BY|a|b
Y→AY|BY|a|b
E→AX
F→BX
A→a
B→b

Write the C/C++/Java program using the CYK algorithm to recognize the strings produced by the
above grammar.
Sample String Sample output
aaa Yes
ab Yes
ababb Yes

After completing the enough tasks for the above grammar, give your own grammar of the
Chomsky Normal Form and check its applicability. [CYK is not discussed in the class. You study on
your own and implement it]

You might also like