ContextFree Languages 1 Regular Languages 2 ContextFree Languages










































































- Slides: 74

Context-Free Languages 1

Regular Languages 2

Context-Free Languages Regular Languages 3

Context-Free Languages Context-Free Grammars Pushdown Automata stack automaton 4

Context-Free Grammars 5

Grammars express languages Example: the English language 6

7

A derivation of “the dog walks”: 8

A derivation of “a cat runs”: 9

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” } 10

Notation Production Rules Variable Terminal 11

Another Example Grammar: Derivation of sentence : 12

Grammar: Derivation of sentence : 13

Other derivations: 14

Language of the grammar 15

More Notation Grammar Set of variables Set of terminal symbols Start variable Set of Production rules 16

Example Grammar : 17

More Notation Sentential Form: A sentence that contains variables and terminals Example: Sentential Forms sentence 18

We write: Instead of: 19

In general we write: If: 20

By default: 21

Example Grammar Derivations 22

Example Grammar Derivations 23

Another Grammar Example Grammar : Derivations: 24

More Derivations 25

Language of a Grammar For a grammar with start variable : String of terminals 26

Example For grammar : Since: 27

A Convenient Notation 28

Example A context-free grammar : A derivation: 29

A context-free grammar : Another derivation: 30

Describes parentheses: (((( )))) 31

Example A context-free grammar : A derivation: 32

A context-free grammar : Another derivation: 33

34

Example A context-free grammar : A derivation: 35

A context-free grammar : A derivation: 36

Describes matched parentheses: () ((( ))) (( )) 37

Definition: Context-Free Grammars Grammar Variables Terminal symbols Start variable Productions of the form: Variable String of variables and terminals 38

39

Definition: Context-Free Languages A language is context-free if and only if there is a context-free grammar with 40

Derivation Order Leftmost derivation: Rightmost derivation: 41

Leftmost derivation: Rightmost derivation: 42

Derivation Trees 43

44

45

46

47

Derivation Tree 48

Derivation Tree yield 49

Partial Derivation Trees Partial derivation tree 50

Partial derivation tree 51

sentential form Partial derivation tree yield 52

Sometimes, derivation order doesn’t matter Leftmost: Rightmost: Same derivation tree 53

Ambiguity 54

leftmost derivation 55

leftmost derivation 56

Two derivation trees 57

The grammar is ambiguous: string has two derivation trees 58

The grammar is ambiguous: string has two leftmost derivations 59

Definition: A context-free grammar if some string is ambiguous has: two or more derivation trees 60

In other words: A context-free grammar if some string is ambiguous has: two or more leftmost derivations (or rightmost) 61

Why do we care about ambiguity? take 62

63

64

Correct result: 65

• Ambiguity is bad for programming languages • We want to remove ambiguity 66

We fix the ambiguous grammar: New non-ambiguous grammar: 67

68

Unique derivation tree 69

The grammar : is non-ambiguous: Every string has a unique derivation tree 70

Another Ambiguous Grammar IF_STMT if EXPR then STMT else STMT 71

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 72

Inherent Ambiguity Some context free languages have only ambiguous grammars Example: 73

The string has two derivation trees 74
Regular grammars generate regular languages
Right linear grammar to left linear grammar
Decision properties of regular languages
Properties of regular languages
Closure under intersection
Regular and irregular languages
Pumping lemma non regular languages examples
Decision properties of regular languages
Proof by contradiction examples
Decision properties of regular languages
Decision properties of regular languages
A method to make regular saving easier is ____.
Aturan produksi
Malha estrutural irregular
Regular polyhedra
Regular language
Best feature articles
Dense regular ct
10 3 areas of regular polygons
Regular expressions wikipedia
Triangulo equilatero caracteristicas
Examples of irregular adverbs
A regular polygon is equiangular
Unit 11 homework 4 area of regular figures
Pentagon shape
Geo algebra
Cuales son los verbos regulares
Anlogos
Regular quadrilaterals
Secular franciscan clothing
Algebraic properties of regular expression
Oabc is a parallelogram p is the point on ac
Ordinary speech with no regular pattern of accentual rhythm
Affirmative past simple tense
Fui di vi
Fixed connective tissue
Chop regular or irregular verb
Escondidas es un verbo
Reloj es regular o irregular
Regular expression
Enjambment
Create length and height in hair design.
A pentagonal plate of side 30mm
Notasi ekspresi reguler
Regular language properties
Erection
Vital signs according to age
Total surface area of pyramid
Irregular past tense of blow
Principal parts of regular and irregular verbs
Espelho física
Concave polygon
Area of a regular nonagon
Principal parts of regular and irregular verbs
Symmetry of regular octagon
Rhythm is the of visual movement colors shapes or lines
Regular and irregular verbs play
Polygon properties
Cepillarse preterite
Regular expression symbols
Nome de todas as pirâmides
Area de un trapecio regular
Bien mal regular
Expressao regular
Fluido espinhal
Que son las emociones ?
11-4 area of regular polygons
Calibri regular
Modifying comparatives
Polígonos convexos
Malo regular bueno excelente
Cdef is a quadrilateral
Regular vs irregular dense connective tissue
Grab minulý čas
Sentences with regular and irregular verbs