Context-Free%20Languages - PowerPoint PPT Presentation

About This Presentation
Title:

Context-Free%20Languages

Description:

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

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

less

Transcript and Presenter's Notes

Title: Context-Free%20Languages


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

A context-free grammar G
7
(((( ))))
8
A context-free grammar G
9
(No Transcript)
10
A context-free grammar G
11
() ((( ))) (( ))
12
Definition of Context-Free Grammars

Any grammar G(V,T,S,P)
V variables T terminal symbols S start
variable
P production rules of the form
string of variables and terminals
13
Definition of Context-Free Languages
  • A language L is context-free
  • if and only if
  • there is a grammar G with L L(G)

14
Derivation Order

Leftmost derivation
Rightmost derivation
15
Derivation Trees

16

17
(No Transcript)
18
(No Transcript)
19
(No Transcript)
20
Derivation Tree
21
sentence
Derivation Tree
yield
22
Partial Derivation Trees

Partial derivation tree
23
sentential form

Partial derivation tree
yield
24
Often, derivation order doesnt matter

Same Derivation Tree
25
Ambiguity

26
(No Transcript)
27
(No Transcript)
28
(No Transcript)
29
The grammar
is ambiguous
string
has two derivation trees
30
The grammar
is ambiguous
string
has two leftmost derivations
31
In general
A context-free grammar is ambiguous if
some string has two or
more derivation trees
32
In other words
A context-free grammar is ambiguous if
some string has two or
more leftmost derivations
rightmost
33
Why do we care about ambiguity?
take
34
(No Transcript)
35
(No Transcript)
36
The right solution
37
Therefore
Ambiguity is bad for programming languages
We want to remove the ambiguity
38
We fix the ambiguous grammar
New grammar
39
(No Transcript)
40
Unique derivation tree
41
The grammar
Is not ambiguous
42
Inherent Ambiguity
  • Some context free languages
  • have only ambiguous grammars

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