Department of Computer science – CS 386 Note for Lecture on 04/12/06 Instructor:Prof. Dr J.Miller Last date for submit the Homework2 is 04/17/06 Language: Language a set of words, formed by symbols in a given alphabet. May or may not be infinite Grammar: Grammar is the study of rules governing the use of language, the set of rules governing a particular language is also called the grammar of the language. For example grammar must be context free for computer language in order for it to be efficient to write in Formal grammar: Formal grammar is an abstract structure that describes a formal language precisely, i.e., a set of rules that mathematically delineates a (usually infinite) set of finite-length strings over a (usually finite) alphabet. Formal grammars are so named by analogy to grammar in human languages. Find the grammar generate this language? L = {w n a (w) = n b (w)} Where n a (w) is the # of “a” S in W G = ({S}, {a.b},S,P) P: S aSb S bSa S SS S SS S SS aSbS aSbbSa When we can say Equivalent? We have same language EXAMPEL What is the language of this grammar? P: S aAb S aAb the meaning of this S aAb S Amir Chartab Shargh 1 = OR abba Department of Computer science – CS 386 Note for Lecture on 04/12/06 Instructor:Prof. Dr J.Miller G = ({S,A}, {a,b},S,P) L = { a n b n : n>= 0} Automate theory: Symbol Symbol an arbitrary datum which has some meaning to or effect on the machine. Word A finite string formed by the concatenation of a number of symbols. Alphabet A finite set of symbols. Language Language a set of words, formed by symbols in a given alphabet. May or may not be infinite. Automatons are characterized by the following features: 1. Input: read-only 2. Output 3. Temporary storage: CPU 4. Control unit Automate divided to two parts: The terminates Automate None terminates Automate 1 Non-deterministic Automata a 2 a 3 Now this two kind of automate separately divided to two different parts: 1. Acceptor: An automaton whose output is yes or no is an acceptor.(1,0) 2. Transducer: An automaton whose output is a string of symbols is a transducer. Amir Chartab Shargh 2 Department of Computer science – CS 386 Note for Lecture on 04/12/06 Instructor:Prof. Dr J.Miller Nondeterministic finite automaton (NFA) NFA is a finite state machine where for each pair of state and input symbol there may be several possible next states. Deterministic Finite Automata (DFA) Each state of an automaton of this kind has a transition for every symbol in the alphabet. M = (Q, ∑ , , qo , F) Q = finite set of internal states ∑ = alphabet : Q * ∑ = transition function Qo Q = initial stage F Q = final stages 0 1 Qo 0 Q1 1 1 Q2 0 Two circles means final stage M = ({qo , q1 , q2 }, {0,1}, qo q1 ) qoqo q1q2 qoq1 q2q2 q1qo q2q1 We have 6 transition here Now show this 001101 qoqo q1q2 qoqo q2q2 q0qo1 q2q1 Amir Chartab Shargh 3 Department of Computer science – CS 386 Note for Lecture on 04/12/06 Instructor:Prof. Dr J.Miller 1 1* (0 1) * 1* = {1, 11, 111 …} 1 = {} q0 , aq1 q1, bq2 * q0, abq2 L (M) = {W * : * (q0, W) F} L (M) = {W * : * (q0, W) F} b Qo a,b Q1 Q2 a,b a Trap state DFA: L = { a n b : n 0} a b q0 q0 q1 q0 q2 q2 q0 q2 q2 Table show DFA Amir Chartab Shargh 4 Department of Computer science – CS 386 Note for Lecture on 04/12/06 Instructor:Prof. Dr J.Miller Example: a Qo ∑ = {a, b} Starting with “ab” b Q1 Q2 a b a,b Q3 a,b // a trap state Example: ∑ = {a, b} DFA accept all string except those containing the substring 001 1 Q0 0 Q1 0 Q2 1 0 Final Stage Comments: 1. As long we read a “1” we go back to start state 2. If we get a 0 we have possibility to get a 1. Amir Chartab Shargh 5 1 Q3