Regular languages ( Chapter 9 in your book)

Document Sample
Regular languages ( Chapter 9 in your book) Powered By Docstoc
					           Regular languages and NFA's( Chapter 9 in your book)

Def: A grammar is context free ( CFG) if every rule has a single non-terminal on the
left side, that is, is of the form A w, where A is a single non-terminal, and w is any
string made up of terminals and non-terminals, including , possibly, .
One especially simple type of CFG is the regular grammar, defined next.
Def: A grammar is (left) regular if every rule is of the form AxB; A  x . or A 
Def. A language is regular if it can be generated by some regular grammar.               (see page 300 in
your book.)
Note: To prove a language is regular , one need merely find a regular grammar that generates it.
To prove a language is not regular, one has to prove that no regular grammar can ever generate it.
The mere fact that some non-regular grammar generates a language proves nothing about its
regularity since the same language can be generated by more than one grammar.
 Def : A NFA, M, ( non-deterministic finite automaton) is a 6-tuple: (Q,S,F, ,S ) where Q
is a finite set of states, S  Q is the start state, F  Q is the set of accepting states,  is a finite
set of symbols, and   Q  Q   is the set of transitions.
          A string of  is accepted by an NFA if there is a path for the string that ends in an
accepting state. The language of M, L(M) is the set of all accepted strings.
            Sample exercises. Let the symbol set,  = {a,b,c}. For each of the following languages
over *,
          find an NFA that accepts it and a regular grammar that generates it.
          The language is all strings in * which

        1. End with abc

        2. Begin and end in a.

        3. Do not contain the subsstring bc.

        4. contain the substring ab one or more times.

        5. contain the substring ab exactly one time.

        6. contain exactly 3 a's.
        6.5 contain ab at least two times.
        7. in which every a is immediately followed by b.
                Note: the condition does not require that any a's occur, but if a does appear, it
        must be followed by b .
        8. in which every a is eventually followed by b.
        9. The number of a's is a multiple of 3.
        10. in which , if b appears, c never appear later in the string.

        You should be able to do most, if not all, of 17-28, page 307, using this NFA method.
However, not all context free languages are regular, as we shall prove shortly, so do not expect to
always be able to find a regular grammar, if you are asked for a CFG.
Theorem: A language is regular if and only if it is accepted by some NFA.
        (Further, there is an algorithm for finding an NFA from a regular grammar and
        vice versa.)
Proof: To be presented in class.

          Proposition: L= {anbn | n > 0 } is not regular, ( but is context free.)
          proof: The proof can be used to used to prove a pumping lemma for regular languages,
but we will make it specific to the language L. Suppose L can be generated by some regular
language, G. Let N be greater than the number of non-terminals of G. Consider the derivation
tree for aNbN .
          In the derivation of just the a N portion of the string , some non terminal, say A, must
appear twice. Thus the derivation can be "pumped" to get a derivation of a N + p b N where p > 0, so
this string is not in L. The grammar does too much -- it generates strings that are not in L.
Note: Proofs can also be made by showing that no DFA accepts L .