Alphabets , strings, languages and grammars

hele987 1,284 views 33 slides Aug 04, 2019
Slide 1
Slide 1 of 33
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33

About This Presentation

a Formal language Simple and basic Termes


Slide Content

Chapter One Alphabets , Strings, Languages and Grammars Prepared By Haftom B. 1

Prepared By Haftom B. 2

Alphabets and Strings A common way to talk about words, number, pairs of words, etc. is by representing them as strings To define strings, we start with an alphabet Examples An alphabet is a finite set of symbols. S 1 = {a, b, c, d, …, z}: the set of letters in English S 2 = {0, 1, …, 9}: the set of (base 10) digits S 3 = {a, b, …, z, #}: the set of letters plus the special symbol # S 4 = {(, )}: the set of open and closed brackets Prepared By Haftom B. 3

Strings The empty string will be denoted by E Examples A string over alphabet S is a finite sequence of symbols in S. abfbz is a string over S 1 = {a, b, c, d, …, z} 9021 is a string over S 2 = {0, 1, …, 9} ab#bc is a string over S 3 = {a, b, …, z, #} ))()(() is a string over S 4 = {(, )} Prepared By Haftom B. 4

Cont.… We will use small alphabets: Strings 5 Prepared By Haftom B.

String Operations 6 1. Concatenation Prepared By Haftom B.

7 2. Reverse Prepared By Haftom B.

3. String Length Length: Examples: 8 Prepared By Haftom B.

Recursive Definition of Length For any letter: For any string : Example: 9 Prepared By Haftom B.

4. Length of Concatenation Example : 10 Prepared By Haftom B.

Proof of Concatenation Length Claim: Proof: By induction on the length Induction basis : From definition of length: 11 Prepared By Haftom B.

Empty String A string with no letters: Observations: 12 Prepared By Haftom B.

Substring Substring of string: a subsequence of consecutive characters String Substring 13 Prepared By Haftom B.

Prefix and Suffix Given string Prefixes Suffixes 14 prefix suffix Prepared By Haftom B.

Another Operation Example: Definition: 15 Prepared By Haftom B.

The * Operation : the set of all possible strings from alphabet 16 Prepared By Haftom B.

17 The + Operation : the set of all possible strings from alphabet except Prepared By Haftom B.

1.2 Languages Languages can be used to describe problems with “yes/no” answers, for example: A language is a set of strings over an alphabet. L 1 = The set of all strings over S 1 that contain the substring “fool” L 2 = The set of all strings over S 2 that are divisible by 7 = {7, 14, 21, …} L 3 = The set of all strings of the form s#s where s is any string over {a, b, …, z} L 4 = The set of all strings over S 4 where every ( can be matched with a subsequent ) Prepared By Haftom B. 18

Cont.… A language is any subset of Example 1: Languages: 19 Prepared By Haftom B.

Example 2 An infinite language is aabbaa ? 20 Prepared By Haftom B.

21 Note that: Sets Set size Set size String length Prepared By Haftom B.

1.2.1 Operations on Languages The usual set operations Complement: 22 Prepared By Haftom B.

Reverse Definition: Examples: 23 Prepared By Haftom B.

Concatenation Definition: Example: 24 Prepared By Haftom B.

Another Operation Definition: Special case: 25 Prepared By Haftom B.

More Examples 26 Prepared By Haftom B.

Star-Closure (Kleene *) Definition: Example: 27 Prepared By Haftom B.

Positive Closure Definition: 28 Prepared By Haftom B.

Grammar Prepared By Haftom B. 29 A grammar is a mechanism used for describing languages. This is one of the most simple but yet powerful mechanism . The grammar for English tells us what are the words in it and the rules to construct sentences.

Formal definitions of a Grammar Prepared By Haftom B. 30 A grammar G is defined as a quadruple

Example Prepared By Haftom B. 31 Consider the grammar , where N = { S }, and P is the set of the following production rules .   Some terminal strings are generated by this grammar together with their derivation is given below

Cont.. Prepared By Haftom B. 32

Cont.… Prepared By Haftom B. 33 Example: Find a grammar for the language It is possible to find a grammar for L by modifying the previous grammar since we need to generate an extra b at the end of the string . We can do this by adding a production S Bb where the non-terminal B generates