Theory of Computation (Fall 2014): Context-Free Grammars, Proving that Languages are Context-Free,...

15
Theory of Computation Context-Free Grammars, Proving that Languages are Context-Free, & Backus-Naur Notation Vladimir Kulyukin

description

 

Transcript of Theory of Computation (Fall 2014): Context-Free Grammars, Proving that Languages are Context-Free,...

Page 1: Theory of Computation (Fall 2014): Context-Free Grammars, Proving that Languages are Context-Free, Backus-Naur Notation

Theory of Computation

Context-Free Grammars,Proving that Languages are Context-Free,

& Backus-Naur Notation

Vladimir Kulyukin

Page 2: Theory of Computation (Fall 2014): Context-Free Grammars, Proving that Languages are Context-Free, Backus-Naur Notation

Outline

● Context-Free Grammars● Proving that Languages are Context-Free● Backus-Naur Notation

Page 3: Theory of Computation (Fall 2014): Context-Free Grammars, Proving that Languages are Context-Free, Backus-Naur Notation

Context-Free Grammars

Page 4: Theory of Computation (Fall 2014): Context-Free Grammars, Proving that Languages are Context-Free, Backus-Naur Notation

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

Page 5: Theory of Computation (Fall 2014): Context-Free Grammars, Proving that Languages are Context-Free, Backus-Naur Notation

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

Page 6: Theory of Computation (Fall 2014): Context-Free Grammars, Proving that Languages are Context-Free, Backus-Naur Notation

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

Page 7: Theory of Computation (Fall 2014): Context-Free Grammars, Proving that Languages are Context-Free, Backus-Naur Notation

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

Page 8: Theory of Computation (Fall 2014): Context-Free Grammars, Proving that Languages are Context-Free, Backus-Naur Notation

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

Page 9: Theory of Computation (Fall 2014): Context-Free Grammars, Proving that Languages are Context-Free, Backus-Naur Notation

Example 05

. , oflength on theinduction by Then,

|

|

:CFG following thebe Let :Proof

.,12 |, :Claim *

LGLz

baX

XXXSS

G

NkkzbazL

Page 10: Theory of Computation (Fall 2014): Context-Free Grammars, Proving that Languages are Context-Free, Backus-Naur Notation

Example 06

.Then

.||

:CFG following thebe Let :Proof

.|, :Claim *

LGL

bSbaSaS

G

xxzbazL R

Page 11: Theory of Computation (Fall 2014): Context-Free Grammars, Proving that Languages are Context-Free, Backus-Naur Notation

Backus-Naur Notation

Page 12: Theory of Computation (Fall 2014): Context-Free Grammars, Proving that Languages are Context-Free, 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 <>

Page 13: Theory of Computation (Fall 2014): Context-Free Grammars, Proving that Languages are Context-Free, Backus-Naur Notation

BNN Example

cba |||exp

|expexp

|expexp

|expexp

|exp*exp

|expexp::exp

Page 14: Theory of Computation (Fall 2014): Context-Free Grammars, Proving that Languages are Context-Free, Backus-Naur Notation

Two Derivations of Expression a-b*c

<exp>

<exp> * <exp>

<exp> <exp>-

a b c

<exp>

<exp> - <exp>

<exp> * <exp>

a b c

Page 15: Theory of Computation (Fall 2014): Context-Free Grammars, Proving that Languages are Context-Free, Backus-Naur Notation

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