# 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

- Every linear grammar generates a regular language
- Regular and irregular languages
- Pumping lemma non regular languages examples
- Decision properties of regular languages
- Contradiction in math
- Decision properties of regular languages
- Decision properties of regular languages
- Right linear grammar
- Decision properties of regular languages
- Properties of regular languages
- Regular languages closure properties
- Ser conjugation chart
- Measurement of regular polygon
- Regular language properties
- Unlike a regular mast tower crane a jacking mast
- Past participleknow
- Principal parts of regular verbs
- Regular language
- Area of a nonagon
- Approved chemical sanitizers
- Regular foreign marketing
- Demiregular tessellation
- Request regular
- Regular expression for palindrome
- Pronunciation of past tense verbs
- Regular and irregular verbs play
- Classify polygons
- Regular expression symbols
- Pirmides
- Expressao regular
- Past simple regular verbs study
- Araro sa pagsasaka
- Calibri regular
- Primeira segunda e terceira conjugação
- Faces vertices e arestas
- Malo regular bueno excelente
- Bien mal regular
- The diagram shows a regular hexagon abcdef with centre o
- Loose connective tissue
- What is the ipde process
- Irregular verbs sentences
- Irregular adverb
- What is one part of a regular vessel and engine maintenance
- Many sided polygon
- Dfa to regular expression converter
- Past simple negative and interrogative
- Regular demand
- Creer indefinido
- Primitive regular expressions
- Imperativo afirmativo
- Regular pattern of sound
- A regular hexagon inscribed in a circle
- Bien regular mal
- Regular expression symbols
- Regular expression () meaning
- Convex polygon formula
- Mnpr
- Rational expressions
- Regular grammar is
- Regular expression
- 4 pics 1 word technology
- 10-2 developing formulas for circles and regular polygons
- Teorema de pitagoras piramide
- Group of cells that are similar in structure and function
- Developing formulas for circles and regular polygons
- Expressao regular
- Area of regular polygons maze answers
- Unit 7 lesson 1 midsegments of triangles
- Exercicio regular do direito
- Poliedros regulares y irregulares
- How many lines of symmetry does a starfish have
- Polish notation
- Regular expression to nfa
- Angulos internos de um pentagono
- Find the surface area of the regular pyramid.