Presentation is loading. Please wait.

Presentation is loading. Please wait.

Akram Salah ISSR 2012. Basic Concepts Languages Grammar Automata (Automaton)

Similar presentations


Presentation on theme: "Akram Salah ISSR 2012. Basic Concepts Languages Grammar Automata (Automaton)"— Presentation transcript:

1 Akram Salah ISSR 2012

2 Basic Concepts Languages Grammar Automata (Automaton)

3 Language A body of communicative symbols, whether it is made up of words, sounds, gestures, facial expressions, or visual signals that by long use by the population of a wide spread territory has became whereby the ideas or feelings of the individual members of that population are communicated or expressed. A system suitable for the expression of certain ideas, facts, concepts, including a set of symbols and rules for their manipulation.

4 Language Alphabet  : finite, non empty set of symbols String: finite sequence of symbols from   = {a, b}, abab, aaabbba are strings on  w = abaaa called a word A language is a set of words, each is a string, defined over 

5 Languages w = a 1 a 2 …a n and v = b 1 b 2 …b m Concatenate: wv = a 1 a 2.. a n b 1 b 2..b m Reverse: w R = a n.. a 2 a 1 If w = vu, v prefix of w u suffix of w

6 Languages Length of a string w, |w| The number of symbols in w Empty string  a string with no symbols |  | = 0  w = w  = w, for all w |uv| = |u| + |v|

7 Languages w is a string, w n is concatenating w with itself n times. w 0 =  If  is an alphabet,  * is the set of strings concatenating 0 or more elements of .  + is the set of strings concatenating 1 or more symbols.  + =  * - {  }.  * =  + U {  }

8 Languages A language, L, defined over an alphabet , is a subset of  * Any string w in a language L is called a word or a sentence. We can define more than one language over the same . Complement of a language L c =  * -L. Concatenation of two languages

9

10 Grammars A grammar for a language tells us whether a particular sentence is well formed or not. A set of rules. We need a precise non-ambiguous notation to describe the rules. The rules simply tells us which subset of L is accepted as a “legal” expression

11 Grammars ->, {“a”, “the”} {“boy”, “dog”} {“walks”, “runs”} “a boy runs”| Properly formed “the dog walks”|

12 Grammars A grammar G is a quadruple G = (V, T, S, P) Where: V finite set of objects called variables T finite set of objects called terminal symbols S  V is a special symbols called start variable P is a finite set of productions V  T are non-empty and disjoint

13 Grammars Production rules are the heart of a grammar They specify how the grammar transforms one string to another They define a language associated with G Production rule in the form: x -> y x  (V U T) + & y  (V U T) *

14 Grammars Given a string w = uxv, rule x -> y is applicable to w z = uyv. written as w => z, w derives z or z is driven from w

15 Grammars If w 1 => w 2 => … w n, we write w 1 = * > w n “*” indicates 0 or more steps to derive w n from w 1 w = * > w w= + > v

16 Grammars Applying productions in different order, a grammar generates many strings G = (V, T, S, P), L(G) ={ w  T * : S = * > w} L(G) is Language generated by G S => w 1 => w 2 => … => w n => w is derivation of w S, w 1, w 2, …, w n, sentential forms of the derivation

17 Grammars Example: Given G = ({S}, {a, b}, S, P) Where P S -> aSb, S ->  Then S => aSb=> aaSbb=>aabb

18 Grammars Given G = ({S}, {a, b}, S, P) Where P S -> aSb, S ->  Then S => aSb=> aaSbb=>aabb L(G) = {a n b n : n > 0}

19 Grammars Example: Find a grammar that generates L= {a n b n+1 : n > 0}

20 Grammars G ({S, A}, {a,b}, S, P) where P S -> Ab, A -> aAb, A -> . We can write P S -> Ab, A -> aAb | 

21

22 Automata An automaton is an abstract model of a digital computer. Includes: Input file: Read as a string One symbol at a time, left to right, EOF, no change Can produce output Has temporary storage Unlimited, one character, may change Control unit Finite number of internal states, may change

23 Control Unit Input file Storage Output

24 Automata Control unit is in an internal state. Input scans a symbol The control unit gets to a next-state through a transition function Transition function depends on Current state Current input symbol Information in the temporary storage Configuration: a state of CU, input file, temporary storage Move: the transition from one configuration to next

25 Automata An Automaton: Deterministic: each move is uniquely determined by the current configuration. Nondeterministic: An automaton : Acceptor: the output is limited to “yes” or “no” Either accepts (recognizes) or rejects an input string. Transducer: produces string of symbols as output.

26 Automata Pascal identifier: a letter followed by 0 or more letter or digit. Grammar: ->, -> | | ^, -> a | b | … -> 0 | 1 |.. A0 (derivation) => => A => Aa => A0

27 Automata Automaton 12 3 letter digit Letter or digit

28 Summary Language is a sequence of symbols from an alphabet Grammar is a set of rules to select well formed sequences Automata is computational model for well formed expressions (sequences)

29 Deterministic Finite Acceptors DFA is a type of automata, Deterministic: unique moves (function). Acceptor: has no output (yes/no)

30 Deterministic Finite Acceptor DFA is formally defined as: M = (Q, , , q 0, F) Where Q is a finite set of internal states  is a finite set of symbols, input alphabet  : Q x  -> Q is a total function, transition function q 0  Q is the initial state F (subset of Q) is a set final states

31 Deterministic Finite Acceptor Initially at q 0 Each step, consider, and consume, leftmost symbol Based on transition function, and the symbol read, it moves to the next state As the end of input string, EOF. If the automaton is at one of the final states, F, input string is accepted Otherwise, it is rejected.

32 Deterministic Finite Acceptor Given DFA: M = ({q 0, q 1, q 2 }, {0, 1}, , q 0, {q 1 }) where d is given by:  (q 0, 0) = q 0,  (q 0, 1) = q 1,  (q 1, 0) = q 0,  (q 1, 1) = q 2,  (q 2, 0) = q 2,  (q 2, 1) = q 1. Test 01, 00, 101, 100, 11001

33 Transition Graph A graph represents a DFA: Vertices represent states Edges represent transitions Vertices are labeled by state names Edges are labeled by current value of input symbol Initial state: incoming arrow with no origin Final states are double circle G M has exactly |Q| vertices G M has an edge for each transition rule in 


Download ppt "Akram Salah ISSR 2012. Basic Concepts Languages Grammar Automata (Automaton)"

Similar presentations


Ads by Google