Formal Models

Language

Classes of Grammars

In 1950 Noam Chomsky (a noted Linguist) described four classes of languages (in order of increasing power).

Formal Machine Models


Finite State Automaton (FSA)

A graph with directed labeled arcs, two types of nodes (final and non-final state), and a unique start state is an FSA:



What strings start in state A and end up at state C?

FSA's can have more than one final state:




Non-deterministic FSA vs. Deterministic FSA

Outline of a Proof

Let subsets of states be states in DFA. Keep track of which subset you can be in.





Any string from {A} to either {D} or {CD} represents a path from A to D in the original NFA.

Regular Expressions

You can write any regular language as a regular expression:



0*11*1 + 0*11*(0 + 100*1)1*

The operators used in forming regular expressions are:


Regular expressions, regular grammars and FSA's

Theorem: Regular expressions, regular grammars and FSA's are all equivalent---they can be used to define the same set of languages

The proof is ``constructive.'' That is given either a grammar G or a FSA M, you can construct the other.

To go from a FSA to a regular grammar, make the following transformations:





Why do we care about regular languages?

Programs are composed of tokens:

Each of these can be defined by regular grammars:


Examples

  1. Example 1: An even number of 0's and an even number of 1's
  2. Example 2: a(bb)*bc
  3. Example 3: Binary Odd Numbers
  4. Example 4: 00(1|0)*11
  5. Example 5: Even Number of b's
  6. Example 6: At Most Two Consecutive b