filelanguage and automata 8

Upload: ashutoshfriends

Post on 30-May-2018

216 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/14/2019 filelanguage and automata 8

    1/3

    E q u i v a l e n c e o f C F G ' s a n d P D A ' s

    T h e t i t l e s a y s i t a l l .

    W e ' l l s h o w a l a n g u a g e L i s L G f o r s o m e

    C F G i f a n d o n l y i f i t i s N P f o r s o m e P D A

    P

    O n l y I f C F G t o P D A

    L e t L = L G f o r s o m e C F G G = V ; P ; S

    I d e a : h a v e P D A A s i m u l a t e L M d e r i v a t i o n s i n

    G w h e r e a l e f t - s e n t e n t i a l f o r m i s r e p r e s e n t e d

    b y

    1 . T h e s e q u e n c e o f i n p u t s y m b o l s t h a t A h a s

    c o n s u m e d f r o m i t s i n p u t f o l l o w e d b y

    2 A ' s s t a c k t o p l e f t m o s t .

    E x a m p l e : I f q ; a b c d ; S

    *

    q ; c d ; A B C t h e n

    t h e L S F r e p r e s e n t e d i s a b A B C

    M o v e s o f A

    I f a t e r m i n a l a i s o n t o p o f t h e s t a c k t h e n

    t h e r e b e t t e r b e a n a w a i t i n g o n t h e i n p u t . A

    c o n s u m e s a f r o m t h e i n p u t a n d p o p s i t f r o m

    t h e s t a c k i f s o .

    3T h e L S F r e p r e s e n t e d d o e s n ' t c h a n g e !

    I f a v a r i a b l e B i s o n t o p o f t h e s t a c k t h e n

    P D A A h a s a c h o i c e o f r e p l a c i n g B o n t h e

    s t a c k b y t h e b o d y o f a n y p r o d u c t i o n w i t h

    h e a d B

    F o r m a l C o n s t r u c t i o n o f A

    A = f q g V ; ; q ; S w h e r e i s d e n e d b y :

    1 . I f B i s i n V t h e n q ; ; B = f q B !

    i s i n P g

    2 . I f a i s i n t h e n q ; a ; a = f q g

    E x a m p l e

    G = f S A g f 0 1 g ; P ; S w h e r e P c o n s i s t s o f S !

    A S A ! 0 A 1 A 1 0 1

    A = f q g f 0 1 g f 0 1 ; A ; S g ; ; q ; S w h e r e i s

    d e n e d b y :

    3 q ; ; S = f q ; A S q g

    3 q ; ; A = f q 0 A 1 q A 1 q 0 1 g

    3 q 0 0 = f q g

    3 q 1 1 = f q g

    1

  • 8/14/2019 filelanguage and automata 8

    2/3

    O n l y - I f P r o o f i . e . , G r a m m a r P D A

    P r o v e b y i n d u c t i o n o n t h e n u m b e r o f s t e p s

    i n t h e d e r i v a t i o n S

    *

    l m

    t h a t f o r a n y x

    q ; w x ; S

    *

    q ; x ; w h e r e

    1 w =

    2 i s t h e s u x o f t h a t b e g i n s a t t h e

    l e f t m o s t v a r i a b l e = i f t h e r e i s n o

    v a r i a b l e .

    A l s o p r o v e t h e c o n v e r s e t h a t i f q ; w x ; S

    *

    q ; x ; t h e n S

    *

    w

    I n d u c t i v e p r o o f s i n r e a d e r .

    A s a c o n s e q u e n c e i f y i s a t e r m i n a l s t r i n g

    t h e n S

    *

    y i q ; y ; S

    *

    q ; ; i . e . y i s i n

    L G i y i s i n N A

    P D A t o C F G

    A s s u m e L = N P w h e r e P = Q , ; ; q

    0

    Z

    0

    K e y i d e a : u n i t s o f P D A a c t i o n h a v e t h e n e t

    e e c t o f p o p p i n g o n e s y m b o l f r o m t h e s t a c k

    c o n s u m i n g s o m e i n p u t a n d m a k i n g a s t a t e

    c h a n g e .

    T h e t r i p l e q Z p i s a C F G v a r i a b l e t h a t

    g e n e r a t e s e x a c t l y t h o s e s t r i n g s w s u c h t h a t P

    c a n r e a d w f r o m t h e i n p u t p o p Z n e t e e c t

    a n d g o f r o m s t a t e q t o s t a t e p

    3M o r e p r e c i s e l y q ; w ; Z

    *

    p ; ;

    3A s a c o n s e q u e n c e o f a b o v e q ; w x ; Z

    *

    p ; x ; f o r a n y x a n d

    I t ' s a Z e n t h i n g : q Z p i s a t o n c e a t r i p l e

    i n v o l v i n g s t a t e s a n d s y m b o l s o f P a n d y e t t o

    t h e C F G w e c o n s t r u c t i t i s a s i n g l e i n d i v i s i b l e

    o b j e c t .

    3 O K ; I k n o w t h a t ' s n o t a Z e n t h i n g b u t

    y o u g e t t h e p o i n t .

    C o m p l e t e p r o o f i s i n t h e r e a d e r . W e ' l l j u s t

    g i v e s o m e e x a m p l e s a n d t h e i d e a b e h i n d t h e

    c o n s t r u c t i o n .

    E x a m p l e : a p o p p i n g r u l e e . g . p i n

    q ; a ; Z

    3 q Z p ! a

    2

  • 8/14/2019 filelanguage and automata 8

    3/3

    A r u l e t h a t r e p l a c e s o n e s y m b o l a n d s t a t e b y

    o t h e r s e . g . p Y i n q ; a ; Z

    3F o r a l l s t a t e s r q Z r ! a p Z r

    A r u l e t h a t r e p l a c e s o n e s t a c k s y m b o l b y t w o

    e . g . p ; X Y i n q ; a ; Z

    3 F o r a l l s t a t e s r a n d s q Z s !

    a p X r r Y s

    D e t e r m i n i s t i c P D A ' s

    I n t u i t i v e l y : n e v e r a c h o i c e o f m o v e .

    q ; a ; Z h a s a t m o s t o n e m e m b e r f o r a n y q

    a Z i n c l u d i n g a =

    I f q ; ; Z i s n o n e m p t y t h e n q ; a ; Z m u s t

    b e e m p t y f o r a l l i n p u t s y m b o l s a

    W h y C a r e ?

    P a r s e r s a s i n Y A C C a r e r e a l l y D P D A ' s .

    T h u s t h e q u e s t i o n o f w h a t l a n g u a g e s a D P D A

    c a n a c c e p t i s r e a l l y t h e q u e s t i o n o f w h a t

    p r o g r a m m i n g l a n g u a g e s y n t a x c a n b e p a r s e d

    c o n v e n i e n t l y .

    S o m e L a n g u a g e R e l a t i o n s h i p s

    A c c e p t a n c e b y e m p t y s t a c k i s h a r d f o r a

    D P D A .

    3O n c e i t a c c e p t s i t d i e s a n d c a n n o t a c c e p t

    a n y c o n t i n u a t i o n .

    3T h u s N P h a s t h e p r e x p r o p e r t y i f w

    i s i n N P t h e n w x i s N O T i n N P f o r

    a n y x 6=

    H o w e v e r p a r s e r s d o a c c e p t b y e m p t y i n g t h e i r

    s t a c k .

    3T r i c k : t h e y r e a l l y p r o c e s s s t r i n g s f o l l o w e d

    b y a u n i q u e e n d m a r k e r t y p i c a l l y $ e . g .

    i f t h e y a c c e p t w $ t h e y c o n s i d e r w t o b e a

    c o r r e c t p r o g r a m .

    I f L i s a r e g u l a r l a n g u a g e t h e n L i s a D P D A

    l a n g u a g e .

    3A D P D A c a n s i m u l a t e a D F A w i t h o u t

    u s i n g i t s s t a c k a c c e p t a n c e b y n a l s t a t e .

    I f L i s a D P D A l a n g u a g e t h e n L i s a C F L

    t h a t i s n o t i n h e r e n t l y a m b i g u o u s .

    3 A D P D A y i e l d s a n u n a m b i g u o u s

    g r a m m a r i n t h e s t a n d a r d c o n s t r u c t i o n .

    3