Cod Lab Assignment
Cod Lab Assignment
5. Write a Program in Flex which identifies C Integers and float numbers. Your program should
respond to various inputs as follows:
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 ()) = {)}
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.
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]