Regular Grammar by HC120614205942

VIEWS: 17 PAGES: 15

									บทท 3 Regular Languages & Regular Grammar           3-13

3.3 Regular Grammars

Right - linear grammar
                                                -

                   A  xB
                   A x
                A, B  V, x  T*

Left-linear grammar
                                            Left-

                       A  Bx ,
                       A x



a36c7657-40d3-400f-a260-2e6089bf2dec.doc
บทท 3 Regular Languages & Regular Grammar           3-14

Regular Grammar


              left linear
(            ‘linear’ :

productions )

      .        G1 = ( {S}, {a,b}, S, P1 )
               P1 : S  abS | a .
G1                              -           Regular
Grammar
       Derivation ababa :
       S  abS  ababS  ababa
                                                )


a36c7657-40d3-400f-a260-2e6089bf2dec.doc
บทท 3 Regular Languages & Regular Grammar                     3-15


      .     G2 = ({S, A, B}, {a, b}, S, P2)
       P2 : S  Aab ,
            A  Aab | B ,
            B  a.
G2       left linear grammar
Regular Grammar
     . Derivation :
       S  Aab  Aabab  Aabab
          Babab  aabab
    (generate string                                          )

       Grammar
                                                Left linear

               S  Ab     ,
               A  bS ,  .
                                           Right linear

Grammar                                     Regular Grammar
a36c7657-40d3-400f-a260-2e6089bf2dec.doc
บทท 3 Regular Languages & Regular Grammar                  3-16

Theorem Let G = (V, T, S, P) be a
right-linear grammar . Then L(G) is
a regular language.


                             right-linear grammar
                                  NFA accepts L(G)
                              derivation string in L(G)

       V0  a1Vi
           a1a2Vj
           a1a2…..akVn
          *

           a1a2…..akal = w

NFA
  *( q0 , a1a2…..akal ) = qf

         a1               a2                     ak   al
q0                                         ...             qf

a36c7657-40d3-400f-a260-2e6089bf2dec.doc
บทท 3 Regular Languages & Regular Grammar                 3-17




                       Vx  aVy
                         (qx , a) = qy         f
                       Vx 
                         (qx , a) = qf         f
         qf              accepting state
          starting state =

        qx       a1               a2    ... am qz
                          Vx  a1a2 ... amVz

        qx        a1               a2    ...    am   qf
                             Vx  a1a2 ... am

a36c7657-40d3-400f-a260-2e6089bf2dec.doc
บทท 3 Regular Languages & Regular Grammar                      3-18


      . G = ( {S, A, B}, {a,b}, S, P )
               S  aA | aB ,
               A  bB | b ,
               B  aA | bB .
       Derivation of string abab :
       S  aA  abB  abaA  abab


                         S          a          A       b   F
                         a                 a       b

                                     B

                           a



S  aA
                                       a
                           S                   A


a36c7657-40d3-400f-a260-2e6089bf2dec.doc
บทท 3 Regular Languages & Regular Grammar                      3-19

S  aB
                                       a
                         S                         A

                             a
                                           B

Ab
                       S           a               A   b   F

                         a
                                   B


                                               


                       S           a           A       b   F
                        a                  a       b

                                   B

                         a

a36c7657-40d3-400f-a260-2e6089bf2dec.doc
บทท 3 Regular Languages & Regular Grammar          3-20


  .          DFA accepts the language
generated by the grammar
               S  aA,
               A  abS | b .

                      a                    b
          S                       A            F
            b                     a




a36c7657-40d3-400f-a260-2e6089bf2dec.doc
บทท 3 Regular Languages & Regular Grammar               3-21

Theorem
   If L be a regular language on ,
then there exists a right linear
grammar G = (V, , S, P) such that
L = L(G)



                            Regular Language
                                                 

                                           DFA
                                                 ?

                       Right Linear Grammar
                                DFA  Right Linear G.


 Regular Language  Regular Grammar

a36c7657-40d3-400f-a260-2e6089bf2dec.doc
บทท 3 Regular Languages & Regular Grammar                      3-22


                   Right linear Grammar                  DFA
    M = (Q, , , q0                                   DFA
accepts language L
               Q = {q0, q1,...qn}
                = {a1, a2,...am}

                              right         linear     grammar
       G=(V,                                V = { q0, q1,...qn }

                                          S = q0 (Start State)

  (qx, a) = qy    qy  F, a
      production qx  aqy

  (qx, a) = qf                                qf  F, a
       qx aqf                                   qf  

a36c7657-40d3-400f-a260-2e6089bf2dec.doc
บทท 3 Regular Languages & Regular Grammar              3-23

ตย. การ                                         DA
                DFA                         Grammar
          (q0, a) = { q1 }                 q0  aq1
          (q1, a) = { q2 }                 q1  aq2
          (q2, b) = { q2 }                 q2  bq2
          (q2, a) = { qf }                 q2  aqf
               qf  F                        qf  




a36c7657-40d3-400f-a260-2e6089bf2dec.doc
บทท 3 Regular Languages & Regular Grammar                3-24

Theorem A language L is regular if
and only if there exists a left linear
grammar G such that L = L(G).

Proof
               left linear grammar
                                            v = ab
               A  Bv , or                  A  Bab  abab
               Av
                                      ^
                      right linear grammar G

               Av B,          R            vR = ba
                                            A  baB  baba
or             A  vR


                                ^
                            L(G) = (L(G))R


a36c7657-40d3-400f-a260-2e6089bf2dec.doc
บทท 3 Regular Languages & Regular Grammar                                                                            3-25


 L(G) regular G right linear grammar.
                    ^
                    เป็ น                              เนื่องจาก   เป็ น
                                                                                                      ^


                                   ่
         จากแบบฝึ กหัดเราพิสูจน์ได้วา ถ้า   L regular L regular
                                                    เป็ น                      แล้ว
                                                                                      R
                                                                                          เป็ น           ด้วย




        ดังนั้น   (L(G))R regular          เป็ น




 L(G) =                                    (^                 L           (          G           )       )           R


         L(G)R = ( ( L ( G ) )
           ^                                                                                          R
                                                                                                                 )    R


                   ^             = L(G)
                           ่
                   สรุ ปได้วา   L(G) regular  เป็ น




a36c7657-40d3-400f-a260-2e6089bf2dec.doc
บทท 3 Regular Languages & Regular Grammar         3-26


Theorem A language L is regular if
and only if there exists a regular
grammar G such that L = L(G).

           Th.1 Regular Expression
                                Th.2
                                              Regular
                                            Language
Th.1 RE  nfa
           dfa or nfa Th.4
           Th.3
Th 2 RL  RE (RL dfa  GTG  RE)
      .




           Linear Grammar 
Th.3 Right Regular Grammar RL
   ( Right Linear Grammar  nfa  RL )
Th.4 RL  Right Linear Grammar
  (RL  dfa  Right Linear Grammar)




a36c7657-40d3-400f-a260-2e6089bf2dec.doc
บทท 3 Regular Languages & Regular Grammar                     3-27

Homework

Peter Linz ,
Exercises 3.2 p.89 : 1,4,7,8,9,10(a),15
{ Hint           10(a)                     DFAGTGRE }
Exercises 3.3 p.99 : 1,2,3,4,5,10(a)
{ Hint           10(a)                     DFARegular Grammar }




a36c7657-40d3-400f-a260-2e6089bf2dec.doc

								
To top