Ejemplo n.º 1
0
def test3():
    from langscape.langlets.ls_grammar.grammar_object import GrammarObject

    class NFA2GrammarObjTranslator(NFA2GrammarTranslator):
        def __init__(self, langlet):
            self.langlet = langlet
            nfas = self.langlet.nfagenerator.nfas
            self.names = {}
            for r in nfas:
                name = nfas[r][0].split(":")[0]
                self.names[r] = name
            super(NFA2GrammarObjTranslator, self).__init__(langlet)

        def get_constants(self):
            return  {} #self.langlet.nfagenerator.nfadata.constants

        def get_node_name(self, nid):
            return self.names[nid]

    rules = []
    rules = open("tests/rulefile.txt").readlines()
    for i, rule in enumerate(rules):
        print "RULE", rule
        go = GrammarObject.grammar_from_rule(rule)
        nfa = go.nfagenerator.nfas[go.get_start_symbol()]
        nfa2gra = NFA2GrammarObjTranslator(go)
        if not nfa2gra.check_translation(nfa, False):
            print (i, rule)
        if i == 10:
            break
Ejemplo n.º 2
0
def test3():
    from langscape.langlets.ls_grammar.grammar_object import GrammarObject

    class NFA2GrammarObjTranslator(NFA2GrammarTranslator):
        def __init__(self, langlet):
            self.langlet = langlet
            nfas = self.langlet.nfagenerator.nfas
            self.names = {}
            for r in nfas:
                name = nfas[r][0].split(":")[0]
                self.names[r] = name
            super(NFA2GrammarObjTranslator, self).__init__(langlet)

        def get_constants(self):
            return {}  # self.langlet.nfagenerator.nfadata.constants

        def get_node_name(self, nid):
            return self.names[nid]

    rules = []
    rules = open("tests/rulefile.txt").readlines()
    for i, rule in enumerate(rules):
        print "RULE", rule
        go = GrammarObject.grammar_from_rule(rule)
        nfa = go.nfagenerator.nfas[go.get_start_symbol()]
        nfa2gra = NFA2GrammarObjTranslator(go)
        if not nfa2gra.check_translation(nfa, False):
            print (i, rule)
        if i == 10:
            break
Ejemplo n.º 3
0
 def check_translation(self, nfa, dbg=True):
     global __DEBUG__
     __DEBUG__ = dbg
     if __DEBUG__:
         print "----------------------------------------------"
         pprint.pprint(nfa)
         print "----------------------------------------------"
     R = self.translate(nfa)
     if __DEBUG__:
         print "[check-translation : Rule]", R
     go = GrammarObject.grammar_from_rule(R)
     nfa_R = go.get_nfas()[go.get_start_symbol()]
     __DEBUG__ = False
     return R, nfa_comp(nfa, nfa_R)
Ejemplo n.º 4
0
 def check_translation(self, nfa, dbg=True):
     global __DEBUG__
     __DEBUG__ = dbg
     if __DEBUG__:
         print "----------------------------------------------"
         pprint.pprint(nfa)
         print "----------------------------------------------"
     R = self.translate(nfa)
     if __DEBUG__:
         print "[check-translation : Rule]", R
     go = GrammarObject.grammar_from_rule(R)
     nfa_R = go.get_nfas()[go.get_start_symbol()]
     __DEBUG__ = False
     return R, nfa_comp(nfa, nfa_R)