HW05 due 03/05

advertisement
CmSc 365 Theory of Computation
Homework 05 due 03/05
1. Context-free grammars capture the syntactic structure of the languages they
recognize/generate. Each non-terminal symbol of a CFG corresponds to a
syntactic category. For example, in the CFG rule NP  D N, NP corresponds to
the syntactic category “noun phrase”, D corresponds to the syntactic category
“determiner”, and N corresponds to the syntactic category “noun”. We say that a
string falls under the syntactic category A, if it can be derived from the nonterminal symbol A.
Consider the following CFG rules:
R1: P  [B, P]
R2: P  B
R3: B  C
R4: B  (P)
R5: C  x | y | z
Here the non-terminal symbols are B, C, P. The terminal symbols are [ ] , ( ) x y z.
Note that the comma is a terminal symbol.
For each of the following strings, indicate all the syntactic categories of which it
is a member, if any, and write down the corresponding derivation.
a)
b)
c)
d)
e)
f)
z
(x)
[y]
([x,y])
[(x),y]
[(x),[y,x]]
2. Construct a context-free grammar G = (V,  , S, R) to generate the language
L = {wa*b*wR | w  {a,b}*}. Describe explicitly each component of the
grammar. Give the derivation of ababa. Indicate the rule applied at each step.
3. Construct a regular grammar G = (V,  , S, R) that generates strings over the
alphabet {a,b} described by the regular expression b*ab*. Describe explicitly
each component of the grammar. “Regular grammar” means that the right side of
each rule should be one of the following:
Empty symbol
Terminal symbol
Terminal followed by a non-terminal symbol
Non-terminal followed by a terminal symbol
Give the derivation of bbab
1
Download