-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSyntaxTree.py
44 lines (39 loc) · 1.43 KB
/
SyntaxTree.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from Tree import Tree
from Stack import Stack
from Symbol import Symbol
from SyntaxNode import SyntaxNode
class SyntaxTree(Tree):
def __init__(self, n=SyntaxNode(), left=None, right=None):
super().__init__(n=n, left=left, right=right)
@staticmethod
def postorderTraversalPos(root):
res = []
if root:
res = SyntaxTree.postorderTraversalPos(root.getLeft())
res = res + SyntaxTree.postorderTraversalPos(root.getRight())
res.append(root.getNode().getPos())
return res
@staticmethod
def postorderTraversalAnul(root):
res = []
if root:
res = SyntaxTree.postorderTraversalAnul(root.getLeft())
res = res + SyntaxTree.postorderTraversalAnul(root.getRight())
res.append(root.getNode().getAnulable())
return res
@staticmethod
def postorderTraversalPrim(root):
res = []
if root:
res = SyntaxTree.postorderTraversalPrim(root.getLeft())
res = res + SyntaxTree.postorderTraversalPrim(root.getRight())
res.append(root.getNode().getPrimeros())
return res
@staticmethod
def postorderTraversalUlt(root):
res = []
if root:
res = SyntaxTree.postorderTraversalUlt(root.getLeft())
res = res + SyntaxTree.postorderTraversalUlt(root.getRight())
res.append(root.getNode().getUltimos())
return res