Ejemplo n.º 1
0
def dottree_rec(d, sym, rules, syms, printcover):
    "helper for dottree()"
    if syms.has_key(sym):
        return
    syms[sym] = 1

    name = str(sym.sym)
    if printcover:
        if sym.cover:
            name += "  cover %d,%d" % sym.cover
    d.add("    sym_%d [label=\"%s\", color=red];" %
          (hash(sym), printable(name, 1, 0)))
    for p in sym.possibilities:
        d.add("    sym_%d -> rule_%d;" % (hash(sym), hash(p)))
        if not rules.has_key(p):
            rules[p] = 1
            name = str(p.rule)
            if printcover:
                if p.cover:
                    name += "  cover %d,%d" % p.cover
            d.add("    rule_%d [label=\"%s\"];" %
                  (hash(p), printable(name, 1, 0)))
            for e in p.elements:
                d.add("    rule_%d -> sym_%s;" % (hash(p), hash(e)))
                dottree_rec(d, e, rules, syms, printcover)
Ejemplo n.º 2
0
	def dot(self) :
		d = dot.dot("LR0")
		for idx in range(len(self.states)) :
			label = "State %d" % idx
			for itnum in self.states[idx] :
				label += "\\n" + self.itemstr(itnum)
			d.add("    %d [label=\"%s\",shape=box];" % (idx, label))

			# make names for transitions to each next state
			name = ["" for st in range(len(self.states))]
			for (st,tr),ns in self.goto.items() :
				if st != idx :
					continue
				if name[ns] != "" :
					name[ns] += ", "
				if isinstance(tr, str) :
					name[ns] += printable(tr, 1)
				else :
					name[ns] += self.prodstr(tr, 1)

			# print all transitions that have names
			for ns in range(len(name)) :
				if name[ns] != "" :
					d.add("    %d -> %d [label=\"%s\"];" % (idx, ns, name[ns]))
		d.end()
		d.show()
Ejemplo n.º 3
0
    def dot(self):
        d = dot.dot("LR0")
        for idx in range(len(self.states)):
            label = "State %d" % idx
            for itnum in self.states[idx]:
                label += "\\n" + self.itemstr(itnum)
            d.add("    %d [label=\"%s\",shape=box];" % (idx, label))

            # make names for transitions to each next state
            name = ["" for st in range(len(self.states))]
            for (st, tr), ns in self.goto.items():
                if st != idx:
                    continue
                if name[ns] != "":
                    name[ns] += ", "
                if isinstance(tr, str):
                    name[ns] += printable(tr, 1)
                else:
                    name[ns] += self.prodstr(tr, 1)

            # print all transitions that have names
            for ns in range(len(name)):
                if name[ns] != "":
                    d.add("    %d -> %d [label=\"%s\"];" % (idx, ns, name[ns]))
        d.end()
        d.show()
Ejemplo n.º 4
0
	def chsetname(self, ccl, quoted = 0) :
		if ccl == EPSILON :
			return "epsilon"
		set = []
		idx = 0
		while idx < 256 :
			if self.chsetcontains(ccl, idx) :
				start = idx
				idx += 1
				while idx < 256 and self.chsetcontains(ccl, idx) :
					idx += 1
				if idx > start + 1 :
					set.append("%s-%s" % (printable(chr(start), quoted), printable(chr(idx - 1), quoted)))
				else :
					set.append("%s" % printable(chr(start), quoted))
			idx += 1
		return string.join(set, ", ")
Ejemplo n.º 5
0
	def prodstr(self, prodno, quoted = 0, bracketted=1) :
		str = ""
		if bracketted :
			str += "["
		str += "(%d) %s ->" % (prodno, self.gram[prodno][0])
		for el in self.gram[prodno][1] :
			str += " "
			str += printable(el, quoted)
		if bracketted :
			str += "]"
		return str
Ejemplo n.º 6
0
 def prodstr(self, prodno, quoted=0, bracketted=1):
     str = ""
     if bracketted:
         str += "["
     str += "(%d) %s ->" % (prodno, self.gram[prodno][0])
     for el in self.gram[prodno][1]:
         str += " "
         str += printable(el, quoted)
     if bracketted:
         str += "]"
     return str
Ejemplo n.º 7
0
	def printtab(self) :
		print "Shifts"
		for idx in range(len(self.states)) :
			print "State %3d:" % idx,
			for (st,tr),ns in self.goto.items() :
				if st != idx :
					continue
				if isinstance(tr, str) :
					name = printable(tr)
				else :
					name = self.prodstr(tr)
				print "  on %s goto %d" % (name, ns)
			print
		print
Ejemplo n.º 8
0
def dottree_rec(d, sym, rules, syms, printcover) :
	"helper for dottree()"
	if syms.has_key(sym) :
		return
	syms[sym] = 1

	name = str(sym.sym)
	if printcover :
		if sym.cover :
			name += "  cover %d,%d" % sym.cover
	d.add("    sym_%d [label=\"%s\", color=red];" % (hash(sym), printable(name, 1, 0)))
	for p in sym.possibilities :
		d.add("    sym_%d -> rule_%d;" % (hash(sym), hash(p)))
		if not rules.has_key(p) :
			rules[p] = 1
			name = str(p.rule)
			if printcover :
				if p.cover :
					name += "  cover %d,%d" % p.cover
			d.add("    rule_%d [label=\"%s\"];" % (hash(p), printable(name, 1, 0)))
			for e in p.elements :
				d.add("    rule_%d -> sym_%s;" % (hash(p), hash(e)))
				dottree_rec(d, e, rules, syms, printcover)
Ejemplo n.º 9
0
 def printtab(self):
     print "Shifts"
     for idx in range(len(self.states)):
         print "State %3d:" % idx,
         for (st, tr), ns in self.goto.items():
             if st != idx:
                 continue
             if isinstance(tr, str):
                 name = printable(tr)
             else:
                 name = self.prodstr(tr)
             print "  on %s goto %d" % (name, ns)
         print
     print
Ejemplo n.º 10
0
def printSummary(d,withSilence=True):
    for s in d["sections"]:
        if s["type"]=="header":
            c=s["count"]
            print(f"Header count={c}")
        elif s["type"]=="level":
            t=s["length"]/d["bitrate"]
            if t>1.0/1200 and withSilence:
                print(f"Silence t={t:0.1f}s")            
        elif "keycode" in s:
            print(s["keycode"],end=" ")
            c=KeyCode.code[s["keycode"]]
            if c==KeyCode.BasicHeader or c==KeyCode.MachineHeader:
                fname=printable(s["Filename"])
                l=s["ProgramLength"]
                print(f'filename ="{fname}" length={l}')
            else:
                l=s["length"]
                print(f"length={l}")
Ejemplo n.º 11
0
    def dot(self, shownfastates=0, showccls=0):
        if showccls:
            # make names for the character classes so we dont repeat this often
            cclname = ["" for idx in range(len(self.uccls))]
            ch = 0
            while ch < self.maxchar + 1:
                minch = ch
                curccl = self.chr2uccl[chr(ch)]
                while ch < self.maxchar + 1 and self.chr2uccl[chr(
                        ch)] == curccl:
                    ch += 1
                maxch = ch - 1
                if cclname[curccl] != "":
                    cclname[curccl] += ", "
                cclname[curccl] += printable(chr(minch), 1)
                if minch < maxch:
                    cclname[curccl] += "-" + printable(chr(maxch), 1)

        d = dot.dot("dfa")
        for idx in range(1, len(self.rows)):
            xtra = ""
            name = "%d" % idx
            if shownfastates:
                name += ": %s" % self.dfastate[idx][0]
            if len(self.acc[idx]) > 0:
                name += " acc%s" % self.acc[idx]
                xtra += ", color=red"
            cnt = 0
            for s1, s2 in self.starts:
                if idx == s1 or idx == s2:
                    xtra += ", color=red"
                if idx == s1:
                    name += "\\nstart %d" % cnt
                if idx == s2:
                    name += "\\nstart ^%d" % cnt
                cnt += 1
            d.add("    n%d [label=\"%s\"%s];" % (idx, name, xtra))

            # make one arc to each reachable next state
            # this graph most accurately portrays the table we build, but
            # is sometimes hard to read.  perhaps we should have an option
            # for collecting the character classes for the edge into a single
            # character class and then converting that to a string.
            for ns in range(1, len(self.rows)):
                ccls = []
                for ccl in range(len(self.rows[idx])):
                    if self.rows[idx][ccl] == ns:
                        ccls.append(ccl)
                if ccls == []:
                    continue

                name = ""
                if showccls:  # build up name out of each ccl
                    for ccl in ccls:
                        if name != "":
                            name += "\\n"
                        name += "%d: %s" % (ccl, cclname[ccl])
                else:  # build up name out of the combined ccl
                    ch = 0
                    while ch < self.maxchar + 1:
                        minch = ch
                        while ch < self.maxchar + 1 and self.chr2uccl[chr(
                                ch)] in ccls:
                            ch += 1
                        maxch = ch - 1
                        if maxch < minch:
                            ch += 1
                            continue
                        if name != "":
                            name += ", "
                        name += printable(chr(minch), 1)
                        if maxch > minch:
                            name += "-" + printable(chr(maxch), 1)
                d.add("    n%d -> n%d [label=\"%s\"];" % (idx, ns, name))
        d.show()
Ejemplo n.º 12
0
	def dot(self, shownfastates = 0, showccls = 0) :
		if showccls :
			# make names for the character classes so we dont repeat this often
			cclname = ["" for idx in range(len(self.uccls))]
			ch = 0
			while ch < self.maxchar + 1 :
				minch = ch
				curccl = self.chr2uccl[chr(ch)]
				while ch < self.maxchar + 1 and self.chr2uccl[chr(ch)] == curccl :
					ch += 1
				maxch = ch - 1
				if cclname[curccl] != "" :
					cclname[curccl] += ", "
				cclname[curccl] += printable(chr(minch), 1)
				if minch < maxch :
					cclname[curccl] += "-" + printable(chr(maxch), 1)

		d = dot.dot("dfa")
		for idx in range(1, len(self.rows)) :
			xtra = ""
			name = "%d" % idx
			if shownfastates :
				name += ": %s" % self.dfastate[idx][0]
			if len(self.acc[idx]) > 0 :
				name += " acc%s" % self.acc[idx]
				xtra += ", color=red"
			cnt = 0
			for s1,s2 in self.starts :
				if idx == s1 or idx == s2 :
					xtra += ", color=red"
				if idx == s1 :
					name += "\\nstart %d" % cnt
				if idx == s2 :
					name += "\\nstart ^%d" % cnt
				cnt += 1
			d.add("    n%d [label=\"%s\"%s];" % (idx, name, xtra))

			# make one arc to each reachable next state
			# this graph most accurately portrays the table we build, but
			# is sometimes hard to read.  perhaps we should have an option
			# for collecting the character classes for the edge into a single
			# character class and then converting that to a string.
			for ns in range(1, len(self.rows)) :
				ccls = []
				for ccl in range(len(self.rows[idx])) :
					if self.rows[idx][ccl] == ns :
						ccls.append(ccl)
				if ccls == [] :
					continue

				name = ""
				if showccls : # build up name out of each ccl
					for ccl in ccls :
						if name != "" :
							name += "\\n"
						name += "%d: %s" % (ccl, cclname[ccl])
				else : # build up name out of the combined ccl
					ch = 0
					while ch < self.maxchar + 1 :
						minch = ch
						while ch < self.maxchar + 1 and self.chr2uccl[chr(ch)] in ccls :
							ch += 1
						maxch = ch - 1
						if maxch < minch :
							ch += 1
							continue
						if name != "" :
							name += ", "
						name += printable(chr(minch), 1)
						if maxch > minch :
							name += "-" + printable(chr(maxch), 1)
				d.add("    n%d -> n%d [label=\"%s\"];" % (idx, ns, name))
		d.show()