Exemple #1
0
    def _init(self, Start):
        def count(counter, nt):
            if nt not in counter:
                counter[nt] = -1
            counter[nt] += 1
            return counter[nt]

        PARSE = functools.partial(gram_parse, self.tokens)
        productions = None
        counter = dict()
        for attrname in dir(self):
            attr = getattr(self, attrname)
            if type(attr) == types.MethodType and hasattr(attr, self.PRODUCTIONS):
                for prod in getattr(attr, self.PRODUCTIONS):
                    p = PARSE(prod)
                    if productions is not None:
                        productions |= p
                    else:
                        productions = p
                    self._addfunc(productions, p[0], count(counter, p[0]), attr)
        if Start in productions.order:
            productions.order.remove(Start)
            productions.order.insert(0, Start)
        self.productions = productions
        self.M = build_table(productions, self.debug)
Exemple #2
0
def t_build():
    print analysis.build_table(productions, True)