CMPS 260 Spring 2020
Homework #2: Languages, Context-free Grammars, Finite Automata
Due: 4pm, Thursday, February 20

1.
SAbaAS(1)
SAbA(2)
AaA(3)
Aλ(4)
Consider context-free grammar G1 shown to the right. S is the grammar's start symbol, A is its other non-terminal symbol (also called a variable), and the terminal symbols are a and b.

(a) Describe L(G1), the language generated by this grammar. That is, provide a precise characterization of the terminal strings that can be derived from S. (You need not use mathematical notation; it suffices to state a simple condition, using natural language, that is met by all, and only, the strings derivable from S.)

(b) Demonstrate that G1 is ambiguous (by showing two non-identical derivation trees that have the same "yield").


2.
SaSa(1)
SbSb(2)
Sa(3)
Sb(4)
Consider context-free grammar G2 shown to the right. S is the grammar's only non-terminal (and hence its start symbol). The terminal symbols are a and b.

Describe L(G2), the language generated by this grammar. That is, provide a precise characterization of the terminal strings that can be derived from S. (You need not use mathematical notation; it suffices to state a simple condition, using natural language, that is met by all, and only, the strings derivable from S.)


3. Present a context-free grammar that generates the language L3 = { ambman  |  m≥0 ∧ n≥2 }


4. Present a finite automaton that recognizes/accepts the language

L4 = { w ∈ {0,1}*  |  110 is a substring of w but 111 is not }


5. Present a finite automaton that recognizes/accepts the language

L5 = { w ∈ {0,1}*  |  n0(w) mod 2 = 1  ∧  n1(w) mod 3 ≠ 0 }

Following Linz's notation, nc(x) is the number of occurrences of symbol c in string x.

In other words, L5 contains precisely those bit strings in which the number of occurrences of 0 is odd and the number of occurrences of 1 is not divisible by 3.