annotate applications/ide/compiler/display.py @ 39:600f48b74799

Move ide
author windel
date Fri, 03 Feb 2012 18:40:43 +0100
parents ide/compiler/display.py@92df07bc2081
children
rev   line source
1
92df07bc2081 Initial import of compiler
windel
parents:
diff changeset
1 from .nodes import *
92df07bc2081 Initial import of compiler
windel
parents:
diff changeset
2
92df07bc2081 Initial import of compiler
windel
parents:
diff changeset
3 def printNode(node, indent=0):
92df07bc2081 Initial import of compiler
windel
parents:
diff changeset
4 """
92df07bc2081 Initial import of compiler
windel
parents:
diff changeset
5 Print visitor
92df07bc2081 Initial import of compiler
windel
parents:
diff changeset
6 all printing goes in here
92df07bc2081 Initial import of compiler
windel
parents:
diff changeset
7 """
92df07bc2081 Initial import of compiler
windel
parents:
diff changeset
8 print(' '*indent+str(node))
92df07bc2081 Initial import of compiler
windel
parents:
diff changeset
9 if type(node) is Procedure:
92df07bc2081 Initial import of compiler
windel
parents:
diff changeset
10 print(' '*indent+' PARAMETERS:')
92df07bc2081 Initial import of compiler
windel
parents:
diff changeset
11 for p in node.parameters:
92df07bc2081 Initial import of compiler
windel
parents:
diff changeset
12 printNode(p, indent+4)
92df07bc2081 Initial import of compiler
windel
parents:
diff changeset
13 if node.block:
92df07bc2081 Initial import of compiler
windel
parents:
diff changeset
14 print(' '*indent+' CODE:')
92df07bc2081 Initial import of compiler
windel
parents:
diff changeset
15 printNode(node.block, indent+4)
92df07bc2081 Initial import of compiler
windel
parents:
diff changeset
16 elif type(node) is Module:
92df07bc2081 Initial import of compiler
windel
parents:
diff changeset
17 print(node.symtable)
92df07bc2081 Initial import of compiler
windel
parents:
diff changeset
18 printNode(node.initcode, indent+2)
92df07bc2081 Initial import of compiler
windel
parents:
diff changeset
19 else:
92df07bc2081 Initial import of compiler
windel
parents:
diff changeset
20 for c in node.getChildren():
92df07bc2081 Initial import of compiler
windel
parents:
diff changeset
21 printNode(c, indent+2)