diff options
author | Martin <martin@leo.fri1.uni-lj.si> | 2015-09-22 17:27:17 +0200 |
---|---|---|
committer | Martin <martin@leo.fri1.uni-lj.si> | 2015-09-22 17:27:17 +0200 |
commit | f6137121b74b476ddd6ade897aea294d27968df5 (patch) | |
tree | b84e4ddab662aa8bee44b98d8b98753a1ff579e8 /monkey/graph.py | |
parent | 138101ec997ee80e8f33f690ae47e451b5b278f7 (diff) | |
parent | 787715411522954660e9235c7eebe8eb896bc498 (diff) |
Merge branch 'master' of ssh://212.235.189.51:22122/codeq-server
Diffstat (limited to 'monkey/graph.py')
-rw-r--r-- | monkey/graph.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/monkey/graph.py b/monkey/graph.py index c69d55c..7f02c60 100644 --- a/monkey/graph.py +++ b/monkey/graph.py @@ -19,6 +19,21 @@ class Node(object): nodes += n.preorder() return nodes + # Return a list of subtrees of [self]. + def subtrees(self): + yield self + for child in self.eout: + yield from child.subtrees() + + # Return the list of leaves' values (left-to-right). + def terminals(self): + if not self.eout: + return [self.data] + terminals = [] + for child in self.eout: + terminals.extend(child.terminals()) + return terminals + # Return a one-line string representation of [self]. def __str__(self): return '(' + str(self.data) + ' ' + \ |