Languages and Finite Automata - PowerPoint PPT Presentation

1 / 82
About This Presentation
Title:

Languages and Finite Automata

Description:

Inherent Ambiguity. Some context free languages. have only ambiguous grammars. Example: 81. The string. has two derivation trees. 82. Ambiguity in natural language? ... – PowerPoint PPT presentation

Number of Views:58
Avg rating:3.0/5.0
Slides: 83
Provided by: cost70
Category:

less

Transcript and Presenter's Notes

Title: Languages and Finite Automata


1
Formal Languages Context-Free Languages Hinrich
Schütze IMS, Uni Stuttgart, WS 2006/07 Slides
based on RPI CSCI 2400 Thanks to Costas Busch
2

Regular Languages
3

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

6
Grammars
  • Grammars express languages
  • Example the English language

7

8
  • A derivation of the dog walks

9
  • A derivation of a cat runs

10
  • 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
11
Notation

Production Rules
Variable
Terminal
12
Another Example
  • Grammar
  • Derivation of sentence

13
Language?
14
  • Grammar
  • Derivation of sentence

15
  • Other derivations

16
  • Language of the grammar

17
More Notation
  • Grammar

Set of variables
Set of terminal symbols
Start variable
Set of Production rules
18
Example
  • Grammar

19
More Notation
  • Sentential Form
  • A sentence that contains
  • variables and terminals
  • Example

Sentential Forms
sentence
20
  • We write
  • Instead of

21
  • In general we write
  • If

22
  • By default

23
Example

Grammar
Derivations
24
Example
Grammar
Derivations
25
Another Grammar Example
  • Grammar

Derivations
26
Language?
27
More Derivations

28
Language of a Grammar
  • For a grammar
  • with start variable

String of terminals
29
Example
  • For grammar

Since
30
A Convenient Notation

31
Example

A context-free grammar
A derivation
32

A context-free grammar
Another derivation
33
(((( ))))
Describes parentheses
34
Example
A context-free grammar
A derivation
35
Language?
36
A context-free grammar
Another derivation
37
(No Transcript)
38
Example
A context-free grammar
A derivation
39
Language?
40
A context-free grammar
A derivation
41
Interpretation?
42
Describes matched parentheses
() ((( ))) (( ))
43
Definition Context-Free Grammars
Grammar
Variables
Terminal symbols
Start variable
Productions of the form
String of variables and terminals
Variable
44
(No Transcript)
45
Definition Context-Free Languages
  • A language is context-free
  • if and only if
  • there is a context-free grammar
  • with

46
Derivation Order

47
Language?
48
(No Transcript)
49
Language?
50
Derivation Trees

51

52
(No Transcript)
53
(No Transcript)
54
(No Transcript)
55
Derivation Tree
56
Derivation Tree
yield
57
Partial Derivation Trees

Partial derivation tree
58

Partial derivation tree
59
sentential form

Partial derivation tree
yield
60
Sometimes, derivation order doesnt matter
Leftmost

Rightmost
Same derivation tree
61
Ambiguity

62
leftmost derivation
63
leftmost derivation
64
(No Transcript)
65
The grammar
is ambiguous
string
has two derivation trees
66
The grammar
is ambiguous
string
has two leftmost derivations
67
Definition
A context-free grammar is ambiguous if
some string has two or
more derivation trees
68
In other words
A context-free grammar is ambiguous if
some string has two or
more leftmost derivations
(or rightmost)
69
Why do we care about ambiguity?
take
70
(No Transcript)
71
(No Transcript)
72
Correct result
73
  • Ambiguity is bad for programming languages
  • We want to remove ambiguity

74
We fix the ambiguous grammar
New non-ambiguous grammar
75
(No Transcript)
76
Unique derivation tree
77
The grammar
is non-ambiguous
Every string has a unique
derivation tree
78
Another Ambiguous Grammar
IF_STMT
if EXPR then STMT
if EXPR then STMT else STMT
79
If expr1 then if expr2 then stmt1 else stmt2
IF_STMT
if
expr1
then
STMT
else
if
expr2
then
stmt1
stmt2
IF_STMT
if
expr1
then
else
STMT
stmt2
if
expr2
then
stmt1
80
Inherent Ambiguity
  • Some context free languages
  • have only ambiguous grammars

Example
81
The string
has two derivation trees
82
Ambiguity in natural language?
Write a Comment
User Comments (0)
About PowerShow.com