FABER F10 - PowerPoint PPT Presentation

1 / 91
About This Presentation
Title:

FABER F10

Description:

Title: FABER F10 Author: Gordana Dodig-Crnkovic Last modified by: Stefan Bygde Created Date: 8/31/2000 1:12:33 AM Document presentation format: Bildspel p sk rmen ... – PowerPoint PPT presentation

Number of Views:81
Avg rating:3.0/5.0
Slides: 92
Provided by: Gordan76
Category:
Tags: faber | derivation | f10 | word

less

Transcript and Presenter's Notes

Title: FABER F10


1
CDT314 FABER Formal Languages, Automata and
Models of Computation Lecture 5 Mälardalen
University 2010
2
ContentMidterm solutionsRegular vs. Nonregular
Languages Context-Free LanguagesContext-Free
GrammarsDerivation Trees. AmbiguityPush-Down
Automata, PDAApplications
3
A Nonregular Language

DFA must have infinite number of states.
States
are distinct for each
4
Non-regular languages
Context-Free Languages
Regular Languages
5
Automata theory formal languages and formal
grammars
6
Context-Free Languages

7
Context-Free Languages
Context-Free Grammars
Pushdown Automata
8
Context-Free Grammars

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
Another derivation
14
(No Transcript)
15
Example
A context-free grammar
A derivation
16
A context-free grammar
A derivation
17
(No Transcript)
18
Definition Context-Free Grammars
Grammar
Variables
Terminal symbols
Start variables
Productions of the form
19
Definition Context-Free Languages
  • A language is context-free
  • if and only if there is a grammar with

20
Derivation Order
Leftmost derivation
21
Derivation Order
22
Leftmost derivation
23
Rightmost derivation
24
Derivation Trees

25
(No Transcript)
26
(No Transcript)
27
(No Transcript)
28
(No Transcript)
29
Derivation Tree
30
Derivation Tree
yield
31
Partial Derivation Trees
Partial derivation tree
32
Partial derivation tree
33
sentential form

Partial derivation tree
yield
34
Sometimes, derivation order doesnt matter
Leftmost
Rightmost
Same derivation tree
35
Ambiguity

36
derivation
( denotes multiplication)
leftmost derivation
37
derivation
leftmost derivation
38
(No Transcript)
39
Two derivation trees
40
The grammar
is ambiguous!
41
is ambiguous
42
Definition
A context-free grammar is ambiguous if
some string has two or more
derivation trees (two or more leftmost/rightmost
derivations)
43
Why do we care about ambiguity?
44
Why do we care about ambiguity?
45
Why do we care about ambiguity?
46
(No Transcript)
47
Ambiguity is bad for programming languages We
want to remove ambiguity!
48
We fix the ambiguous grammar
by introducing parentheses () to indicate
grouping, (precedence)
Non-ambiguous grammar
49
(No Transcript)
50
Unique derivation tree
51
The grammar
is non-ambiguous
Every string has a unique
derivation tree
52
Inherent Ambiguity
  • Some context free languages
  • have only ambiguous grammars!

53
The string
has two derivation trees
54
Definition Context-Free Grammars
Grammar
Variables
Terminal symbols
Start variables
Productions of the form
55
Definition Regular Grammars
Grammar
Variables
Terminal symbols
Start variables
Right or Left Linear Grammars. Productions of the
form
or
56
Non-regular languages
Context-Free Languages
Regular Languages
57
Context-Free Languages
Pushdown Automata
Context-Free Grammars
58
Pushdown AutomataPDAs

59
Pushdown Automaton - PDA
Input String
Stack
States
60
The Stack
A PDA can write symbols on stack and read them
later on.
POP reading symbol PUSH writing symbol
All access to the stack only on the top! (Stack
top is written leftmost in the string, e.g. yxz)
A stack is valuable as it can hold an unlimited
amount of information.
The stack allows pushdown automata to recognize
some non-regular languages.
61
The States
Pop oldreading stack symbol
Push new writing stack symbol
Input symbol
62
input
stack
top
Replace
(An alternative is to start and finish with empty
stack)
63
input
64
input
65
(No Transcript)
66
Example 3.7 Salling A PDA for simple nested
parenthesis strings
Time 0
Input
Stack
67
Example 3.7
Time 1
Input
Stack
68
Example 3.7
Time 2
Input
Stack
69
Example 3.7
Time 3
Input
70
Example 3.7
Time 4
Input
71
Example 3.7
Time 5
Input
72
Example 3.7
Time 6
Input
Stack
73
Example 3.7
Time 7
Input
Stack
74
ApplicationsCompilers

75
Machine Code
Program
Add v,v,0 cmp v,5 jmplt ELSE THEN add x,
12,v ELSE WHILE cmp x,3 ...
v 5 if (vgt5) x 12 v while (x !3)
x x - 3 v 10 ......
Compiler
76
Compiler
Lexical analyzer
parser
input
output
machine code
program
77
A parser knows the grammar of the programming
language
78
Parser
PROGRAM STMT_LIST STMT_LIST STMT
STMT_LIST STMT STMT EXPR IF_STMT
WHILE_STMT
STMT_LIST EXPR EXPR EXPR EXPR - EXPR
ID IF_STMT if (EXPR) then STMT
if (EXPR) then STMT else STMT WHILE_STMT
while (EXPR) do STMT
79
The parser finds the derivation of a particular
input
derivation
Parser
input
E ? E E ? E E E ? 10 EE ? 10
2 E ? 10 2 5
E ? E E E E INT
10 2 5
80
derivation
derivation tree
E ? E E ? E E E ? 10 EE ? 10
2 E ? 10 2 5
81
derivation tree
machine code
mult a, 2, 5 add b, 10, a
82
Parsing

83
Parser
input string
derivation
grammar
84
Example
Parser
derivation
input
?
85
Exhaustive Search
Phase 1
Find derivation of
All possible derivations of length 1
86
(No Transcript)
87
Phase 2
Phase 1
88
Phase 2
Phase 3
89
Final result of exhaustive search
(top-down parsing)
Parser
input
derivation
90
Context Free Arthttp//www.contextfreeart.org/
91
Context Free Arthttp//www.contextfreeart.org/
Write a Comment
User Comments (0)
About PowerShow.com