Ejemplo n.º 1
0
def DEL(productions):
    newSet = []
    #seekAndDestroy throw back in:
    #        – outlaws all left side of productions such that right side is equal to the outlaw
    #        – productions the productions without outlaws
    outlaws, productions = helper.seekAndDestroy(target='e',
                                                 productions=productions)
    #add new reformulation of old rules
    for outlaw in outlaws:
        #consider every production: old + new resulting important when more than one outlaws are in the same prod.
        for production in productions + [
                e for e in newSet if e not in productions
        ]:
            #if outlaw is present in the right side of a rule
            if outlaw in production[right]:
                #the rule is rewrited in all combination of it, rewriting "e" rather than outlaw
                #this cycle prevent to insert duplicate rules
                newSet = newSet + [
                    e for e in helper.rewrite(outlaw, production)
                    if e not in newSet
                ]

    #add unchanged rules and return
    return newSet + ([
        productions[i]
        for i in range(len(productions)) if productions[i] not in newSet
    ])
Ejemplo n.º 2
0
def DELmakeNewRules(productions):
    newSet = []
    # menghapus leftside production sehingga hanya tersisa rightside untuk di manipulasi
    outlaws, productions = helper.seekAndDestroy(target='e',
                                                 productions=productions)
    # membuat rules baru
    for outlaw in outlaws:
        for production in productions + [
                e for e in newSet if e not in productions
        ]:
            if outlaw in production[right]:
                newSet = newSet + [
                    e for e in helper.rewrite(outlaw, production)
                    if e not in newSet
                ]

    # menambahkan rules yang tidak di ubah sebelumnya
    return newSet + ([
        productions[i]
        for i in range(len(productions)) if productions[i] not in newSet
    ])