PROGRAMMING LANGUAGES CS 212 LECTURE 03 PROGRAMMING LANGUAGES
What is Automata Theory? An automaton is an abstract model of a digital computer. Alan Turing (1912--‐1954) Father of modern computer science English mathematician Studied abstract machines called Turing machines even before computers existed
Finite Automata Finite automata are computing devices that accept or recognize regular languages.
Finite state machine Let think about a soda vending machine which accept only 5 and 10 Baht coin. A soda bottle cost 30 Baht. Now we have 7 states to put the coin. Start state need 30 Baht, next state need 25, 20, 15, 10, 5, and a final state need 0 Baht. Let draw a state diagram for the machine
FSM ={5,10} State diagram
DFA and NFA Finite automata have two types Deterministic Finite Automata (DFA) Non-Deterministic Finite Automata (NFA)
Example DFA Regular expression r over ={a,b} r = (a+b)*bb(a+b)* Draw a state diagram of r Step 1 : Think about the smallest string , should be bb
Step 2 : Think about (a+b). in front of bb Step 2 : Think about (a+b)* in front of bb. It should be aaaaaabb or abababababbb Step 3 : After bb , we can have anything.
Example L is a language over ={a,b} which have the even number of a and even number of b Step1: is in L, aa, bb, abab, aaabab, aabb, aaaa, aaaabb, aabbaa … are in L. We should have 4 states. 1) # of a and # of b is even 2) # of a is even and # of b is odd 3) # of a is odd and # of b is even 4) # of a is odd and # of b is odd
From start state , if get one b then #of b is odd and #of a is even From start state , if get one b then #of b is odd and #of a is even. If get another b the #of b is even and # a is even.
From start state , if get one a then #of a is odd and #of b is even From start state , if get one a then #of a is odd and #of b is even. If get another a the #of a is even and # b is even.
From state EaOb, if get one a then #of a is odd and #of b is odd From state EaOb, if get one a then #of a is odd and #of b is odd. If get another a the #of a is even and # b is odd.
From state OaOb, if get one b then #of b is even and #of a is odd From state OaOb, if get one b then #of b is even and #of a is odd. If get another b the #of b is odd and # a is odd.
Example Build a DFA for regular expression R = (001)* + (110)*