コード例 #1
0
ファイル: __init__.py プロジェクト: chenl/parglare
    def print_debug(self):
        a_print("*** STATES ***", new_line=True)
        for state in self.states:
            state.print_debug()

            if state.gotos:
                h_print("GOTO:", level=1, new_line=True)
                prints("\t" + ", ".join([("%s" + s_emph("->") + "%d") %
                                         (k, v.state_id)
                                         for k, v in state.gotos.items()]))
            h_print("ACTIONS:", level=1, new_line=True)
            prints("\t" + ", ".join([("%s" + s_emph("->") + "%s") %
                                     (k, str(v[0]) if len(v) == 1 else "[{}]".
                                      format(",".join([str(x) for x in v])))
                                     for k, v in state.actions.items()]))

        if self.sr_conflicts:
            a_print("*** S/R conflicts ***", new_line=True)
            if len(self.sr_conflicts) == 1:
                message = 'There is {} S/R conflict.'
            else:
                message = 'There are {} S/R conflicts.'
            h_print(message.format(len(self.sr_conflicts)))
            for src in self.sr_conflicts:
                print(src.message)

        if self.rr_conflicts:
            a_print("*** R/R conflicts ***", new_line=True)
            if len(self.rr_conflicts) == 1:
                message = 'There is {} R/R conflict.'
            else:
                message = 'There are {} R/R conflicts.'
            h_print(message.format(len(self.rr_conflicts)))
            for rrc in self.rr_conflicts:
                print(rrc.message)
コード例 #2
0
ファイル: __init__.py プロジェクト: chenl/parglare
    def __str__(self):
        s = []
        for idx, r in enumerate(self.production.rhs):
            if idx == self.position:
                s.append(".")
            s.append(str(r))
        if len(self.production.rhs) == self.position:
            s.append(".")
        s = " ".join(s)

        follow = (s_emph("{{") + "{}" + s_emph("}}"))\
            .format(", ".join([str(t) for t in self.follow])) \
            if self.follow else "{}"

        return (s_header("%d:") + " %s " + s_emph("=") + " %s   %s") \
            % (self.production.prod_id, self.production.symbol, s, follow)
コード例 #3
0
ファイル: grammar.py プロジェクト: morganjk/parglare
 def __str__(self):
     if hasattr(self, 'prod_id'):
         return (s_header("%d:") + " %s " + s_emph("=") +
                 " %s") % (self.prod_id, self.symbol, self.rhs)
     else:
         return ("%s " + s_emph("=") + " %s") % (self.symbol, self.rhs)