def l_parse_tree(self, word): # leftmost parse-tree pt = ParseTree() p = self.parse(word) if not p: print "Failing at ", word.encode('utf-8') return pt pt.add_rule(('G', p[0])) for l, each_r in zip(p[0].split(','), p[1]): if isinstance(each_r, basestring): pt.add_rule((l, each_r)) elif l.startswith('W'): pt.add_rule((l, each_r[0])) L_parse_tree = each_r[1].parse_tree() pt.add_rule(L_parse_tree[0]) if len(L_parse_tree.tree)>1: pt.tree.extend(L_parse_tree[1][1]) elif l == 'T': p = each_r[1] rule_name = ','.join([r[0].replace('T_','') for r in p]) pt.add_rule((l, rule_name)) pt.extend_rule(p) else: print "Something is severly wrong" return pt
def l_parse_tree(self, word): # leftmost parse-tree pt = ParseTree() p = self.parse(word) if not p: print "Failing at ", word.encode('utf-8') return pt pt.add_rule(('G', p[0])) for l, each_r in zip(p[0].split(','), p[1]): if isinstance(each_r, basestring): pt.add_rule((l, each_r)) elif l.startswith('W'): pt.add_rule((l, each_r[0])) L_parse_tree = each_r[1].parse_tree() pt.add_rule(L_parse_tree[0]) if len(L_parse_tree.tree) > 1: pt.tree.extend(L_parse_tree[1][1]) elif l == 'T': p = each_r[1] rule_name = ','.join([r[0].replace('T_', '') for r in p]) pt.add_rule((l, rule_name)) pt.extend_rule(p) else: print "Something is severly wrong" return pt
def parse_tree(self): pt = ParseTree() pt.add_rule((self.sym, self.prod)) pt.extend_rule(self.L.parse_tree()) return pt
def parse_tree(self): pt = ParseTree() pt.add_rule((self.sym, self.prod)) pt.extend_rule(self.L.parse_tree()) return pt