ContextFree Languages Hinrich Schtze CIS LMU 2013 11
- Slides: 82
Context-Free Languages Hinrich Schütze CIS, LMU, 2013 -11 -25 Slides based on RPI CSCI 2400 Thanks to Costas Busch
Take-away Definition context-free grammar Definition context-free language Derivation, sentential form, sentence Derivation trees Ambiguity Context-free grammars for natural language 2
Terminology For our purposes in this class: Context free grammar = Constituency grammar = Phrase structure grammar 3
Grammars express languages Example: the English language 4
5
A derivation of “the dog walks”: 6
A derivation of “a cat runs”: 7
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” } 8
Notation Production Rules Variable Terminal 9
Another Example Grammar: Derivation of sentence : 10
Language? 11
Grammar: Derivation of sentence : 12
Other derivations: 13
Language of the grammar 14
More Notation Grammar Set of variables Set of terminal symbols Start variable Set of Production rules 15
Example Grammar : 16
More Notation Sentential Form: A sentence that contains variables and terminals Example: Sentential Forms sentence 17
We write: Instead of: 18
In general we write: If: 19
By default: 20
Example Grammar Derivations 21
Example Grammar Derivations 22
Another Grammar Example Grammar : 23
Language? 24
Grammar : Derivations: 25
More Derivations 26
Language of a Grammar For a grammar with start variable : String of terminals 27
Example For grammar : Since: 28
A Convenient Notation 29
Revisit first grammar A context-free grammar : A derivation: 30
A context-free grammar : Another derivation: 31
Describes parentheses: (((( )))) 32
Example A context-free grammar : 33
Language? 34
A context-free grammar : Another derivation: 35
36
Example A context-free grammar : 37
Language? 38
A context-free grammar : Two derivations: 39
Interpretation? 40
Describes matched parentheses: () ((( ))) (( )) 41
Definition: Context-Free Grammars Grammar Variables Terminal symbols Start variable Productions of the form: Variable String of variables and terminals 42
43
Definition: Context-Free Languages A language is context-free if and only if there is a context-free grammar with 44
Derivation Order Leftmost derivation: Rightmost derivation: 45
Language? 46
Leftmost derivation: Rightmost derivation: 47
Language? 48
Derivation Trees 49
50
51
52
53
Derivation Tree 54
Derivation Tree yield 55
Partial Derivation Trees Partial derivation tree 56
Partial derivation tree 57
sentential form Partial derivation tree yield 58
Sometimes, derivation order doesn’t matter Leftmost: Rightmost: Same derivation tree 59
Ambiguity 60
leftmost derivation 61
leftmost derivation 62
Two derivation trees 63
The grammar is ambiguous: string has two derivation trees 64
The grammar is ambiguous: string has two leftmost derivations 65
Definition: A context-free grammar if some string is ambiguous has: two or more derivation trees 66
In other words: A context-free grammar if some string is ambiguous has: two or more leftmost derivations (or rightmost) 67
Why do we care about ambiguity? take 68
69
70
Correct result: 71
• Ambiguity is bad for programming languages • We want to remove ambiguity 72
We fix the ambiguous grammar: New non-ambiguous grammar: 73
74
Unique derivation tree 75
The grammar : is non-ambiguous: Every string has a unique derivation tree 76
Another Ambiguous Grammar IF_STMT if EXPR then STMT else STMT Ambiguity? 77
If expr 1 then if expr 2 then stmt 1 else stmt 2 IF_STMT if expr 1 if then expr 2 STMT then stmt 1 else STMT else stmt 2 IF_STMT if expr 1 if then expr 2 then stmt 1 78
Inherent Ambiguity Some context free languages have only ambiguous grammars Example: 79
The string has two derivation trees 80
Ambiguity in natural language? 81
Take-away Definition context-free grammar Definition context-free language Derivation, sentential form, sentence Derivation trees Ambiguity Context-free grammars for natural language 82
- Hyperplanes
- Wizfiz
- Document correction
- Convolutional neural networks
- Cis lmu
- Lmu lst
- Pj portal lmu
- Lmu
- Fachschaft geographie lmu
- Pags lmu
- Lmu otd
- Kontaktstelle mathematik lmu
- Lmu medieninformatik
- Fachschaft schulpsychologie lmu
- Phonetik lmu
- Videoonline lmu allgemeine pädagogik
- Constanze rossmann lmu
- Judith huber lmu
- Lmu munich law
- Apa style zitieren
- Algorithmen und datenstrukturen lmu
- Grid and cloud computing lmu
- Information retrieval lmu
- Pags lmu
- 1 3 dimethylcyclohexane cis trans
- Cayenta payroll management
- Upenn cis courses
- Trans-2-esene
- Alkanların adlandırılması
- Cis 540
- Cis fedtsyrer
- Cis 110 upenn
- Cis 90
- Cit upenn
- Cis-1 2-diclorociclohexano
- What legendary rock band had a drummer nicknamed "bonzo"?
- Cis golgi network
- Cis 460
- Clinical information systems (cis)
- Cis 4004
- Cahn ingold prelog rules
- Cis90
- Cis moss
- Cis 4361
- Formula del ciclopropano
- Lpk cis tangerang
- Cis 565
- * código de identificación de servicios (cis)
- Image search
- Cis 350
- Tuoli
- Temple university cis
- Cis-1 3-dimethylcyclohexane
- 1 2 diclorociclopentano
- Cis 371
- Rit cis
- Cis 3360
- Cis 200
- Stability of chair and boat conformation
- Cis 4930
- Upenn cis 519
- Cis courses upenn
- Cis 501
- Cis 262
- Octahedral cis trans
- Cis 700
- Heptan kaç karbonlu
- Cis 1068
- E sign ssp
- Cis 581 upenn
- Cis 565
- Trans fat vs cis fat
- Cis 419 upenn
- Lms cis
- 1 2 dimetilcicloesano
- Cis 90
- Cis 2168
- Cis 4004
- Upenn cse
- Bureau cis
- Isomer geometri 1 2 dikloroetena
- Cis 700
- Cis 501