Theory of Computing Lab 2

Theory of Computing
CSCI 356/541
Lab Session 2
Outline
Lab 2:
Grammar
Enter Grammar
Test for Grammar Type
Brute Force Parser - Regular or CFG
User Control Parser
Build LL(1) Parse Table
Convert Right-Linear Grammar to FA
Convert CFG to PDA
Push Down Automata
Construct and Run
Convert to CFG
1. Consider a language L1 = {aibjck | i = j or j = k where i, j, k ≥ 0}
(a) Using JFLAP, determine a context-free grammar that generates L1
and determine which strings from {abbc, aabbc, abc, bcc, aaa, ca}
are in L1. Hand in the final output image showing the production
rules and recognized strings.
(b) Convert the resultant CFG from (a) to a PDA using JFLAP. Print it.
(c) Construct another PDA which recognize the language in (a) but
contains more states than the automatically generated one.
Note: automatically generated PDA will have three states.
2. Build the LL(1) parse table for the following grammar.
S  ABCd; A  aA | λ; B  C | b; C  eS | c
Parse the string ‘aaeaabcdcd’ using
(a) brute-force parser and
(b) LL(1) parser;
hand in both parse trees.
(3) Give a context-free grammar that generates the language
x
x
x
L2 = {0 1#0 2#.......#0 k | k>=0, xi is an integer ≥0, and xi=xj for some i≠ j}
In other words, L2 describes all strings of 0's separated by #, where there's
at least one pair of consecutive 0's having equal length.
For example: {00#00, 0#00#000#00, 000#00#0#000} are in L2, where as
{0#00#000, 00, #00} are not in L2.
Type up your grammar using JFLAP. Use JFLAP to test your CFG using
the 5 strings above. Hand in the final output image where the production
rules and recognized strings are visible.
(4) Consider the language L = {ww1w; |w| >= 5, w and w1 in {a,b}*}. Is it
Context-Free?
Provide reason for you answer by playing the Pumping Lemma game in
JFLAP. Hand in the screen shot along with a brief explanation of your
answer.
Exercises are due on next Monday.