Context-Free Languages - PowerPoint PPT Presentation

About This Presentation
Title:

Context-Free Languages

Description:

Ambiguity is bad for programming languages. 43. We fix the ambiguous grammar: ... Some context free languages. have only ambiguous grammars. Example: 48. The string ... – PowerPoint PPT presentation

Number of Views:55
Avg rating:3.0/5.0
Slides: 49
Provided by: costas
Learn more at: http://www.cs.rpi.edu
Category:

less

Transcript and Presenter's Notes

Title: Context-Free Languages


1
Context-Free Languages

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
Example

A context-free grammar
A derivation
7

A context-free grammar
Another derivation
8
(((( ))))
9
Example
A context-free grammar
A derivation
10
A context-free grammar
Another derivation
11
(No Transcript)
12
Example
A context-free grammar
A derivation
13
A context-free grammar
A derivation
14
() ((( ))) (( ))
15
Definition Context-Free Grammars
Grammar
Variables
Terminal symbols
Start variables
Productions of the form
is string of variables and terminals
16
Definition Context-Free Languages
  • A language is context-free
  • if and only if
  • there is a grammar with

17
Derivation Order

18
(No Transcript)
19
Derivation Trees

20

21
(No Transcript)
22
(No Transcript)
23
(No Transcript)
24
Derivation Tree
25
Derivation Tree
yield
26
Partial Derivation Trees

Partial derivation tree
27

Partial derivation tree
28
sentential form

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

Rightmost
Same derivation tree
30
Ambiguity

31
leftmost derivation
32
leftmost derivation
33
(No Transcript)
34
The grammar
is ambiguous
string
has two derivation trees
35
The grammar
is ambiguous
string
has two leftmost derivations
36
Definition
A context-free grammar is ambiguous if
some string has two or
more derivation trees
37
In other words
A context-free grammar is ambiguous if
some string has two or
more leftmost derivations
(or rightmost)
38
Why do we care about ambiguity?
take
39
(No Transcript)
40
(No Transcript)
41
Correct result
42
  • Ambiguity is bad for programming languages
  • We want to remove ambiguity

43
We fix the ambiguous grammar
New non-ambiguous grammar
44
(No Transcript)
45
Unique derivation tree
46
The grammar
is non-ambiguous
Every string has a unique
derivation tree
47
Inherent Ambiguity
  • Some context free languages
  • have only ambiguous grammars

Example
48
The string
has two derivation trees
Write a Comment
User Comments (0)
About PowerShow.com