Download presentation
Presentation is loading. Please wait.
1
Costas Busch - RPI1 Grammars
2
Costas Busch - RPI2 Grammars Grammars express languages Example: the English language
3
Costas Busch - RPI3
4
4 A derivation of “the dog walks”:
5
Costas Busch - RPI5 A derivation of “a cat runs”:
6
Costas Busch - RPI6 Language of the grammar: L = { “a cat runs”, “a cat walks”, “the cat runs”, “the cat walks”, “a dog runs”, “a dog walks”, “the dog runs”, “the dog walks” }
7
Costas Busch - RPI7 Notation VariableTerminal Production Rules
8
Costas Busch - RPI8 Another Example Grammar: Derivation of sentence :
9
Costas Busch - RPI9 Grammar: Derivation of sentence :
10
Costas Busch - RPI10 Other derivations:
11
Costas Busch - RPI11 Language of the grammar
12
Costas Busch - RPI12 More Notation Grammar Set of variables Set of terminal symbols Start variable Set of Production rules
13
Costas Busch - RPI13 Example Grammar :
14
Costas Busch - RPI14 More Notation Sentential Form: A sentence that contains variables and terminals Example: Sentential Formssentence
15
Costas Busch - RPI15 We write: Instead of:
16
Costas Busch - RPI16 In general we write: If:
17
Costas Busch - RPI17 By default:
18
Costas Busch - RPI18 Example Grammar Derivations
19
Costas Busch - RPI19 Grammar Example Derivations
20
Costas Busch - RPI20 Another Grammar Example Grammar : Derivations:
21
Costas Busch - RPI21 More Derivations
22
Costas Busch - RPI22 Language of a Grammar For a grammar with start variable : String of terminals
23
Costas Busch - RPI23 Example For grammar : Since:
24
Costas Busch - RPI24 A Convenient Notation
25
Costas Busch - RPI25 Linear Grammars
26
Costas Busch - RPI26 Linear Grammars Grammars with at most one variable at the right side of a production Examples:
27
Costas Busch - RPI27 A Non-Linear Grammar Grammar : Number of in string
28
Costas Busch - RPI28 Another Linear Grammar Grammar :
29
Costas Busch - RPI29 Right-Linear Grammars All productions have form: Example: or string of terminals
30
Costas Busch - RPI30 Left-Linear Grammars All productions have form: Example: or string of terminals
31
Costas Busch - RPI31 Regular Grammars
32
Costas Busch - RPI32 Regular Grammars A regular grammar is any right-linear or left-linear grammar Examples:
33
Costas Busch - RPI33 Observation Regular grammars generate regular languages Examples:
34
Costas Busch - RPI34 Regular Grammars Generate Regular Languages
35
Costas Busch - RPI35 Theorem Languages Generated by Regular Grammars Regular Languages
36
Costas Busch - RPI36 Theorem - Part 1 Languages Generated by Regular Grammars Regular Languages Any regular grammar generates a regular language
37
Costas Busch - RPI37 Theorem - Part 2 Languages Generated by Regular Grammars Regular Languages Any regular language is generated by a regular grammar
38
Costas Busch - RPI38 Proof – Part 1 Languages Generated by Regular Grammars Regular Languages The language generated by any regular grammar is regular
39
Costas Busch - RPI39 The case of Right-Linear Grammars Let be a right-linear grammar We will prove: is regular Proof idea: We will construct NFA with
40
Costas Busch - RPI40 Grammar is right-linear Example:
41
Costas Busch - RPI41 Construct NFA such that every state is a grammar variable: special final state
42
Costas Busch - RPI42 Add edges for each production:
43
Costas Busch - RPI43
44
Costas Busch - RPI44
45
Costas Busch - RPI45
46
Costas Busch - RPI46
47
Costas Busch - RPI47
48
Costas Busch - RPI48 Grammar NFA
49
Costas Busch - RPI49 In General A right-linear grammar has variables: and productions: or
50
Costas Busch - RPI50 We construct the NFA such that: each variable corresponds to a node: special final state
51
Costas Busch - RPI51 For each production: we add transitions and intermediate nodes ………
52
Costas Busch - RPI52 For each production: we add transitions and intermediate nodes ………
53
Costas Busch - RPI53 Resulting NFA looks like this: It holds that:
54
Costas Busch - RPI54 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
55
Costas Busch - RPI55 Since is left-linear grammar the productions look like:
56
Costas Busch - RPI56 Construct right-linear grammar Left linear Right linear
57
Costas Busch - RPI57 Construct right-linear grammar Left linear Right linear
58
Costas Busch - RPI58 It is easy to see that: Since is right-linear, we have: Regular Language Regular Language Regular Language
59
Costas Busch - RPI59 Proof - Part 2 Languages Generated by Regular Grammars Regular Languages Any regular language is generated by some regular grammar
60
Costas Busch - RPI60 Proof idea: Let be the NFA with. Construct from a regular grammar such that Any regular language is generated by some regular grammar
61
Costas Busch - RPI61 Since is regular there is an NFA such that Example:
62
Costas Busch - RPI62 Convert to a right-linear grammar
63
Costas Busch - RPI63
64
Costas Busch - RPI64
65
Costas Busch - RPI65
66
Costas Busch - RPI66 In General For any transition: Add production: variableterminalvariable
67
Costas Busch - RPI67 For any final state: Add production:
68
Costas Busch - RPI68 Since is right-linear grammar is also a regular grammar with
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.