Notes for week 2
Day 1
Nondeterministic Finite Automata (NFA)
- A NFA is an FSA with
- initial state (start state)
- a set of states F distinguished as accepting states.
- An example of an NFA that finds a lexeme.
The language has two types of lexeme.
- The reserved word if
- Identifiers letter (letter|digit)* ( a letter followed by zero or more letters or digits.
- An alternate way to express this NFA is to separate the set of states that recognize if from the set that recognize an identifier. An empty (or e ) input is used to indicate that states 1 and 2 are essentially the same state as the start state.
- Another simple NFA
- This NFA recognizes input streams which end in abb
- Notice you can't tell when you see the letters abb if you are in state 0 or state 3.
- abababb results in state 3
- abbaba results in state 0 after the input of abb.
Deterministic Finite State Automata
- A DFA is a NFA for which
- the e-transition is not allowed
- No more than one edge with a given label can leave any one state.
- Give a DFA that will recognize strings that end in abb:
Day 2
.
Converting an NFA to a DFA.
- Convert the NFA to a DFA
- Consider the table for this NFA
| State |
Input |
| |
a |
b |
| 0 |
{0,1} |
0 |
| 1 |
0 |
2 |
| 2 |
0 |
3 |
| 3 |
0 |
0 |
- Create a new Set of states.
- What happened to state 0 when the input is a? It can go to either 0 or 1. To indicate this create state {0, 1}
- Notice state 0 under input b is alway 0. From this create the first row of the table below.
- Now add the new state {0, 1}. Under input a, 0 goes to either 0 or 1 and 1 goes to 0, so you are still in the state {0,1}
- On the other hand, {0,1} under b goes either to 0 or 2. Why? Add the state {0,2} and its row.
- As a result of this you need a new state {0,3}, and a new row. Notice this row does not add new states so you are done.
| State |
Input |
| |
a |
b |
| 0 |
{0,1} |
0 |
| {0,1} |
{0,1} |
{0,2} |
| {0,2} |
{0, 1} |
{0,3} |
| {0,3} |
{0, 1} |
0 |
For simplicity rename the states A = 0, B = {0,1}, C = {0,2}, D = {0,3}
New graph
Notice this is the DDA I gave last time.
Regular Expressions
- A regular expression over alphabet S is defined as follows:
- Any character in S is a regular expression
- e is a regular expression
- If F and S are regular expressions, then
- RS is a regular expression
- R|S is a regular expression
- R* and R+ are regular expressions.
Converting NFA To DFA
- Strings of as and bs ending in abb can be described as (a|b)*abb.
- Construct an NFA from a regular expression (Thompson's construction)
- Start with trivial NFA
- For a character a construct
- Suppose N(s) and N(t) are NFAs for regular expressions s and t.
- N(s|t) is given as
- N(st) is given as
- N(s*) is given as
- Apply Thompson's construction to (a|b)*abb
- Build a| b
- Build (a|b)*
- Build (a|b)*a(b(b))
- If time apply to ident | if