class Block(object):
  def __init__(self, lines):
    self.lines = lines
    self.parents = []
    self.children = []
  def add_parent(self, parent):
    self.parents.appent(parent)
  def add_child(self, child):
    self.children.append(child)
  def set_next_block(self, next_block):
    self.next_block = next_block

class Flow_graph(object):
  def __init__(self, intermediate_code):
    self.head = head
    self.end = end

@@ -37,15 +37,8 @@
 self
-, lines
 ):%0A 
@@ -53,21 +53,18 @@
 lines = 
-lines
+%5B%5D
 %0A    sel
@@ -91,21 +91,104 @@
 elf.
-children = %5B%5D
+next_block = False%0A    self.jump_block = False%0A  def add_line(self, line):%0A    self.append(line)
 %0A  d
@@ -252,70 +252,8 @@
 nt)%0A
-  def add_child(self, child):%0A    self.children.append(child)%0A
   de
@@ -320,16 +320,89 @@
 xt_block
+%0A  def set_jump_block(self, jump_block):%0A    self.jump_block = jump_block
 %0A%0Aclass 
@@ -475,35 +475,1818 @@
 elf.
-head = head%0A    self.end = end
+intermediate_code = intermediate_code%0A    self.labeled_blocks = %7B%7D%0A    self.generate_blocks()%0A  def line(self):%0A    if self.position %3E len(self.intermediate_code) or self.position %3C 0:%0A      return False%0A    return self.intermediate_code%5Bself.position%5D%0A  def next_line(self):%0A    self.position += 1%0A  def previous_line(self):%0A    self.position -= 1%0A  def generate_blocks(self):%0A    self.position = 0%0A    self.start = Block()%0A    current_block = self.start%0A    while self.line():%0A      line = self.line()%0A      if type(line) in %5Bintermediate_code_generator.Unconditional_jump,%0A                        intermediate_code_generator.Conditional_jump%5D:%0A        current_block.add_line(line)%0A        if not line.line in self.labeled_blocks:%0A          self.labeled_blocks%5Bline.line%5D = Block()%0A        label_block = self.labeled_blocks%5Bline.line%5D%0A        current_block.set_jump_block(label_block)%0A        label_block.add_parent(current_block)%0A        old_block = current_block%0A        current_block = Block()%0A        old_block.set_next_block(current_block)%0A      elif type(line) is intermediate_code_generator.Label:%0A        old_block = current_block%0A        if not line.line in self.labeled_blocks:%0A          self.labeled_blocks%5Bline.line%5D = Block()%0A        current_block = self.labeled_blocks%5Bline.line%5D%0A        old_block.set_next_block(current_block)%0A      elif type(line) in %5Bintermediate_code_generator.Call,%0A                          intermediate_code_generator.Division,%0A                          intermediate_code_generator.Write,%0A                          intermediate_code_generator.Read%5D:%0A        current_block.add_line(line)%0A        old_block = current_block%0A        current_block = Block()%0A        old_block.set_next_block(current_block)%0A      else:%0A        current_block.add_line(line)%0A      self.next_line()%0A
 %0A

Add generate_blocks