Download presentation
Presentation is loading. Please wait.
1
1 Reverse of a Regular Language
2
2 Theorem: The reverse of a regular language is a regular language Proof idea: Construct NFA that accepts : invert the transitions of the NFA that accepts
3
3 Proof Since is regular, there is NFA that accepts Example:
4
4 Invert Transitions
5
5 Make old initial state a final state
6
6 Add a new initial state
7
7 Resulting machine accepts is regular
8
8 Grammars
9
9 Grammars express languages Example: the English language
10
10
11
11 A derivation of “the boy walks”:
12
12 A derivation of “a dog runs”:
13
13 Language of the grammar: L = { “a boy runs”, “a boy walks”, “the boy runs”, “the boy walks”, “a dog runs”, “a dog walks”, “the dog runs”, “the dog walks” }
14
14 Notation Variable or Non-terminal Terminal Production rule
15
15 Another Example Grammar: Derivation of sentence :
16
16 Grammar: Derivation of sentence :
17
17 Other derivations:
18
18 Language of the grammar
19
19 More Notation Grammar Set of variables Set of terminal symbols Start variable Set of Production rules
20
20 Example Grammar :
21
21 More Notation Sentential Form: A sentence that contains variables and terminals Example: Sentential Formssentence
22
22 We write: Instead of:
23
23 In general we write: If:
24
24 By default:
25
25 Example Grammar Derivations
26
26 Grammar Example Derivations
27
27 Another Grammar Example Grammar : Derivations:
28
28 More Derivations
29
29 Language of a Grammar For a grammar with start variable : String of terminals
30
30 Example For grammar : Since:
31
31 A Convenient Notation
32
32 Linear Grammars
33
33 Linear Grammars Grammars with at most one variable at the right side of a production Examples:
34
34 A Non-Linear Grammar Grammar :
35
35 Another Linear Grammar Grammar :
36
36 Right-Linear Grammars All productions have form: Example: or
37
37 Left-Linear Grammars All productions have form: Example: or
38
38 Regular Grammars
39
39 Regular Grammars A regular grammar is any right-linear or left-linear grammar Examples:
40
40 Observation Regular grammars generate regular languages Examples:
41
41 Regular Grammars Generate Regular Languages
42
42 Theorem Languages Generated by Regular Grammars Regular Languages
43
43 Theorem - Part 1 Languages Generated by Regular Grammars Regular Languages Any regular grammar generates a regular language
44
44 Theorem - Part 2 Languages Generated by Regular Grammars Regular Languages Any regular language is generated by a regular grammar
45
45 Proof – Part 1 Languages Generated by Regular Grammars Regular Languages The language generated by any regular grammar is regular
46
46 The case of Right-Linear Grammars Let be a right-linear grammar We will prove: is regular Proof idea: We will construct NFA with
47
47 Grammar is right-linear Example:
48
48 Construct NFA such that every state is a grammar variable: special final state
49
49 Add edges for each production:
50
50
51
51
52
52
53
53
54
54
55
55 Grammar NFA
56
56 In General A right-linear grammar has variables: and productions: or
57
57 We construct the NFA such that: each variable corresponds to a node: special final state
58
58 For each production: we add transitions and intermediate nodes ………
59
59 For each production: we add transitions and intermediate nodes ………
60
60 Resulting NFA looks like this: It holds that:
61
61 The case of Left-Linear Grammars Let be a left-linear grammar We will prove: is regular Proof idea: We will construct a right-linear grammar with
62
62 Since is left-linear grammar the productions look like:
63
63 Construct right-linear grammar In :
64
64 Construct right-linear grammar In :
65
65 It is easy to see that: Since is right-linear, we have: Regular Language Regular Language Regular Language
66
66 Proof - Part 2 Languages Generated by Regular Grammars Regular Languages Any regular language is generated by some regular grammar
67
67 Proof idea: Let be the NFA with. Construct from a regular grammar such that Any regular language is generated by some regular grammar
68
68 Since is regular there is an NFA such that Example:
69
69 Convert to a right-linear grammar
70
70
71
71
72
72
73
73 In General For any transition: Add production: variableterminalvariable
74
74 For any final state: Add production:
75
75 Since is right-linear grammar is also a regular grammar with
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.