Theory of Computation (Fall 2014): Context-Free Grammars, Proving that Languages are Context-Free,...
-
Upload
vladimir-kulyukin -
Category
Science
-
view
77 -
download
2
description
Transcript of Theory of Computation (Fall 2014): Context-Free Grammars, Proving that Languages are Context-Free,...
Theory of Computation
Context-Free Grammars,Proving that Languages are Context-Free,
& Backus-Naur Notation
Vladimir Kulyukin
Outline
● Context-Free Grammars● Proving that Languages are Context-Free● Backus-Naur Notation
Context-Free Grammars
Context-Free Grammar (CFG): Definition
.over string a is and ere wh
, form theof is productionEach
s;production ofset finite a is
symbol;start theis
alphabet; terminal theis
alphabet; lnontermina theis
where,,,, tuple-4 a is CFG A
VΣyVX
yX
P
VS
Σ
V
PSVGG
Example 01
. from derived is that show ,on induction
By .| :CFG following heConsider t :Proof
free.-context is L that Show .0 Let :Claim
Sban
aSbS
|nbaL
nn
nn
Example 02
. from derived is that show ,on induction
By .| :CFG following heConsider t :Proof
free.-context is that Show .0|Let :Claim
3
3
Sban
aSbbbS
LnbaL
nn
nn
Example 03
.|;|; :Lfor G CFG aconstruct can
weNow .| :for CFG a be Let .| :for
CFG a be Let . that Observe free.-context are and both
01, ExampleBy .0| and 0|Let :Proof
.free-context is 0,0|Let :Claim
221121
2222111
12121
21
dcSSbaSSSSS
dcSSLGbaSSL
GLLLLL
mdcLnbaL
mndcbaL
mmnn
mmnn
Example 04
. and of
rules the to| addingby for CFG aconstruct can
Then we ly.respective , and of symbols starting two thebe
and Let ly.respective , and for and grammars
free-context exist two therefree,-context are and Since :Proof
free.-context is Then
.Let languages. free-context be and Let :Claim
21
21
21
212121
21
2121
GG
SSSLG
GG
SSLLGG
LL
L
LLLLL
Example 05
. , oflength on theinduction by Then,
|
|
:CFG following thebe Let :Proof
.,12 |, :Claim *
LGLz
baX
XXXSS
G
NkkzbazL
Example 06
.Then
.||
:CFG following thebe Let :Proof
.|, :Claim *
LGL
bSbaSaS
G
xxzbazL R
Backus-Naur Notation
Backus-Naur Notation (BNN)
● BNN is frequently used in R&D on compilers and programming languages
● BNN is a CFG specification language● The main difference is that BNN uses ::= instead of
and puts non-terminals inside <>
BNN Example
cba |||exp
|expexp
|expexp
|expexp
|exp*exp
|expexp::exp
Two Derivations of Expression a-b*c
<exp>
<exp> * <exp>
<exp> <exp>-
a b c
<exp>
<exp> - <exp>
<exp> * <exp>
a b c
References & Reading Suggestions
● Davis, Weyuker, Sigal. Computability, Complexity, and Languages, 2nd Edition, Academic Press
● Brooks Webber. Formal Language: A Practical Introduction, Franklin, Beedle & Associates, Inc
● Hopcroft and Ullman. Introduction to Automata Theory, Languages, and Computation, Narosa Publishing House