comparison python/tree.py @ 322:44f336460c2a

Half of use of burg spec for arm
author Windel Bouwman
date Mon, 27 Jan 2014 19:58:07 +0100
parents 84d67cce67b7
children e9fe6988497c
comparison
equal deleted inserted replaced
321:8c569fbe60e4 322:44f336460c2a
1 1
2 class Tree: 2 class Tree:
3 """ Tree node with a name and possibly some child nodes """ 3 """ Tree node with a name and possibly some child nodes """
4 def __init__(self, name, *args): 4 def __init__(self, name, *args):
5 self.name = name 5 self.name = name
6 self.value = None
6 self.children = args 7 self.children = args
7 8
8 def __repr__(self): 9 def __repr__(self):
9 if self.children: 10 if self.children:
10 ch = ', '.join(str(c) for c in self.children) 11 ch = ', '.join(str(c) for c in self.children)
51 52
52 def apply_rules(self, tree, goal): 53 def apply_rules(self, tree, goal):
53 rule = tree.state.get_rule(goal) 54 rule = tree.state.get_rule(goal)
54 results = [self.apply_rules(kid_tree, kid_goal) 55 results = [self.apply_rules(kid_tree, kid_goal)
55 for kid_tree, kid_goal in zip(self.kids(tree, rule), self.nts(rule))] 56 for kid_tree, kid_goal in zip(self.kids(tree, rule), self.nts(rule))]
56 self.pat_f[rule](*results) 57 self.pat_f[rule](tree, *results)