Beispiel #1
0
    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)
Beispiel #2
0
 def __str__(self):
     s = "\n\n" + s_header("State %d:%s\n" % (self.state_id, self.symbol))
     for i in self.items:
         s += "\t{}\n".format(i)
     return s
Beispiel #3
0
 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)