0% found this document useful (0 votes)
121 views2 pages

HW 4

This document provides instructions for homework 4 in CSE 30151 during spring 2014. It includes 4 problems: 1) writing context-free grammars for specific languages, 2) writing a CFG for regular expressions, 3) converting grammars to Chomsky normal form, and 4) algorithms for determining reachable, live, and useful variables in a CFG and constructing an equivalent grammar without useless variables. The document is due on March 18, 2014 at 2:00pm and covers topics including CFGs, regular expressions, and normal forms.

Uploaded by

Umer Khan
Copyright
© Attribution Non-Commercial (BY-NC)
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)
121 views2 pages

HW 4

This document provides instructions for homework 4 in CSE 30151 during spring 2014. It includes 4 problems: 1) writing context-free grammars for specific languages, 2) writing a CFG for regular expressions, 3) converting grammars to Chomsky normal form, and 4) algorithms for determining reachable, live, and useful variables in a CFG and constructing an equivalent grammar without useless variables. The document is due on March 18, 2014 at 2:00pm and covers topics including CFGs, regular expressions, and normal forms.

Uploaded by

Umer Khan
Copyright
© Attribution Non-Commercial (BY-NC)
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/ 2

CSE 30151 Spring 2014 Homework 4 Due at 2:00pm on March 18, 2014

1. Context-free grammars. Give CFGs generating each of the following languages. In all cases, i, j, k 0. (a) {x {a, b} | x starts and ends with the same symbol} (b) {ai bj ck | i = j or j = k } (c) {ai bj ck | i = j + k } (d) {ai bj ck | i = j + k } (e) {ai bj ck | i < j or i > k } 2. Applications of CFGs. Find a CFG generating the language of all regular expressions over the alphabet = {0, 1} (including the R+ operation is not necessary): (a) if the denition of regular expression is interpreted strictly with regard to parentheses (fully parenthesized), for example, ((((01) ) 0)(0 )) (as specied on page 64 of the textbook); (b) if the denition is interpreted so as to allow regular expressions that are not fully parenthesized, for example, (01 111) 0. In this case, any grammar is sucient even if it is ambiguous and doesnt properly enforce the precedence order of the operations. Be careful to distinguish between -substitution rules and substitution rules whose right side is the symbol appearing in a regular expression; use E in the second case. 3. Normal forms. Convert the following grammars to Chomsky normal form: (a) S AB | (b) S aSa | B B bbC | bb C cC | 4. Properties of CFGs. (a) A variable A in a CFG G = (V, , R, S ) is reachable if a string that contains it can be derived from the start variable S . In other words, S uAw, where denotes multiple derivation steps and u, w are strings consisting of variables and terminals (i.e., u, w (V ) ). Give an algorithm for nding all reachable variables in G. (Hint: the algorithm is similar to computing reachable states in a DFA.) (b) A variable A in a CFG G = (V, , R, S ) is live if a string consisting of terminals only can be derived from it. In other words, A x for some x . Give an algorithm for nding all live variables in G. (c) Extra credit. A variable A in a CFG G = (V, , R, S ) is useful if for some string x , there is a derivation of x that takes the form S uAw x (i.e., it is both reachable and live). A variable that is not useful is useless. If a grammar has useless variables, it is possible to construct an equivalent grammar with no useless variables. A aASb | a B bS

Give an algorithm for doing so and nd equivalent CFGs with no useless variables for the grammars below: S ABC | BaB A aA | BaC | aaa A aAb | bAa | a B bBb | a C CA | AC

S AB | AC

B bbA | aaB | AB

C abCa | aDb

D bD | aC

You might also like