zoukankan      html  css  js  c++  java
  • 正规文法与正规式

    1.分别写出描述以下语言的正规文法和正规式:

    L1={abna|n≥0}。

    解:正规文法:

      S→aA  A→bna

      A→Ba  B→bn

      B→bB|b

    正规式:

      B=b*

      A=b*a

      S=ab*a

    L2={ambn|n≥1,m ≥1}

    解:正规文法:

      S->AB  A->aA|a

      B->bB|b

    正规式:B=a*b*

        A=a*b*b

        S=aa*b*b

    L2={(ab)n|n≥1}

     解:

    正规文法:S->aA  A->bB

         B-aA|ε

    正规式:(ab)*(ab)

     2.将以下正规文法转换到正规式

    (1)

    Z→0A
    A→0A|0B
    B→1A|ε

     解:Z→0A   (1)
      A→0A|0B (2)
      B→1A|ε   (3)

    将(3)代入(2) 得:A = 0A+0(1A+£)=0A+01A+0

                      =(0+01)A +0

                      =(0+01)*0  (4)

    将(4)代入(2)得:Z=0(0|01)*0

    (2)

    Z→U0|V1
    U→Z1|1
    V→Z0|0

    解: Z→U0|V1  (1)
       U→Z1|1    (2)
       V→Z0|0    (3)

    将(2)、(3)同时代入(1)得:Z=(Z1+1)0+(Z0+0)1

                    =Z10+10+Z01+01

                    =Z(10+01)+(10+01)

                    =(10|01)(10|01)*

    (3)

    S→aA
    A→bA|aB|b
    B→aA

    解:S→aA    (1)
      A→bA|aB|b  (2)
      B→aA    (3)

    将(3)代入(2)得:A=bA+aaA+b

               =(b+aa)*b  (4)

    将(4)代入(1)得:S=a(b|aa)*b  

     (4)

    I→l|Il|Id

    解:I=l+II+Id=l+I(l+d)=l(l|d)*

    课程作业
  • 相关阅读:
    Sprinig.net 双向绑定 Bidirectional data binding and data model management 和 UpdatePanel
    Memcached是什么
    Spring.net 网络示例 codeproject
    jquery.modalbox.show 插件
    UVA 639 Don't Get Rooked
    UVA 539 The Settlers of Catan
    UVA 301 Transportation
    UVA 331 Mapping the Swaps
    UVA 216 Getting in Line
    UVA 10344 23 out of 5
  • 原文地址:https://www.cnblogs.com/lingcode/p/11676717.html
Copyright © 2011-2022 走看看