class Parse(object): def __init__(self): self._pen_style_list = ['b-', 'r-o', 'g-*'] self._draw = Drawing() pass def get_cur_x(self): return self._draw.get_cur_x() def get_cur_y(self): return self._draw.get_cur_y() def get_style(self): return self._draw.get_stype() def get_status(self): return self._draw.get_status() def show(self): return self._draw.show() def parse_one_line(self, line): line2 = line = line.strip() if line.find('#') != -1: line2 = line[0:line.find('#')] # remove comments words = line2.split() if len(words) == 0: return if words[0] == 'P': assert(len(words) == 2) self._draw.set_style(self._pen_style_list[int(words[1])]) elif words[0] == 'D': assert(len(words) == 1) self._draw.pen_down() elif words[0] == 'U': assert(len(words) == 1) self._draw.pen_up() elif words[0] == 'W': assert(len(words) == 2) self._draw.line_left(int(words[1])) elif words[0] == 'N': assert(len(words) == 2) self._draw.line_up(int(words[1])) elif words[0] == 'E': assert(len(words) == 2) self._draw.line_right(int(words[1])) elif words[0] == 'S': assert(len(words) == 2) self._draw.line_down(int(words[1])) else: print "Error: Un-supported Action!, in line \"" + line + "\"" assert(1)