comparison python/c3/astnodes.py @ 212:62386bcee1ba

Added parser combinator lib
author Windel Bouwman
date Sun, 30 Jun 2013 19:00:41 +0200
parents 46d62dadd61b
children 003c8a976fff
comparison
equal deleted inserted replaced
211:99164160fb0b 212:62386bcee1ba
7 7
8 class Designator(Node): 8 class Designator(Node):
9 def __init__(self, tname): 9 def __init__(self, tname):
10 self.tname = tname 10 self.tname = tname
11 def __repr__(self): 11 def __repr__(self):
12 return 'DESIGNATOR {0}'.format(self.tname) 12 return 'DESIGNATOR {}'.format(self.tname)
13 13
14 """ 14 """
15 Type classes 15 Type classes
16 """ 16 """
17 17
21 21
22 class BaseType(Type): 22 class BaseType(Type):
23 def __init__(self, name): 23 def __init__(self, name):
24 self.name = name 24 self.name = name
25 def __repr__(self): 25 def __repr__(self):
26 return '{0}'.format(self.name) 26 return '{}'.format(self.name)
27 27
28 class FunctionType(Type): 28 class FunctionType(Type):
29 def __init__(self, parametertypes, returntype): 29 def __init__(self, parametertypes, returntype):
30 self.parametertypes = parametertypes 30 self.parametertypes = parametertypes
31 self.returntype = returntype 31 self.returntype = returntype
66 self.ival = ival 66 self.ival = ival
67 self.isLocal = False 67 self.isLocal = False
68 self.isReadOnly = False 68 self.isReadOnly = False
69 self.isParameter = False 69 self.isParameter = False
70 def __repr__(self): 70 def __repr__(self):
71 return '{0}'.format(self.name) 71 return '{}'.format(self.name)
72 72
73 # Procedure types 73 # Procedure types
74 class Function(Symbol): 74 class Function(Symbol):
75 """ Actual implementation of a function """ 75 """ Actual implementation of a function """
76 def __init__(self, name): 76 def __init__(self, name):
77 super().__init__(name) 77 super().__init__(name)
78 def __repr__(self): 78 def __repr__(self):
79 return '{0}'.format(self.name) 79 return '{}'.format(self.name)
80 80
81 # Operations / Expressions: 81 # Operations / Expressions:
82 class Unop(Node): 82 class Unop(Node):
83 def __init__(self, a, op): 83 def __init__(self, a, op):
84 self.a = a 84 self.a = a
85 self.op = op 85 self.op = op
86 def __repr__(self): 86 def __repr__(self):
87 return 'UNOP {0}'.format(self.op) 87 return 'UNOP {}'.format(self.op)
88 88
89 class Binop(Node): 89 class Binop(Node):
90 def __init__(self, a, op, b): 90 def __init__(self, a, op, b):
91 self.a = a 91 self.a = a
92 self.b = b 92 self.b = b
93 self.op = op # Operation: '+', '-', '*', '/', 'mod' 93 self.op = op # Operation: '+', '-', '*', '/', 'mod'
94 def __repr__(self): 94 def __repr__(self):
95 return 'BINOP {0}'.format(self.op) 95 return 'BINOP {}'.format(self.op)
96 96
97 class VariableUse(Node): 97 class VariableUse(Node):
98 def __init__(self, target): 98 def __init__(self, target):
99 self.target = target 99 self.target = target
100 def __repr__(self): 100 def __repr__(self):
101 nm = self.target.name if hasattr(self.target, 'name') else '' 101 nm = self.target.name if hasattr(self.target, 'name') else ''
102 return 'VAR USE {0}'.format(nm) 102 return 'VAR USE {}'.format(nm)
103 103
104 class Literal(Node): 104 class Literal(Node):
105 def __init__(self, val): 105 def __init__(self, val):
106 self.val = val 106 self.val = val
107 def __repr__(self): 107 def __repr__(self):
108 return 'LITERAL {0}'.format(self.val) 108 return 'LITERAL {}'.format(self.val)
109 109
110 # Modules 110 # Modules
111 class Package(Node): 111 class Package(Node):
112 def __init__(self, name): 112 def __init__(self, name):
113 self.name = name 113 self.name = name
114 def __repr__(self): 114 def __repr__(self):
115 return 'PACKAGE {0}'.format(self.name) 115 return 'PACKAGE {}'.format(self.name)
116 116
117 # Statements 117 # Statements
118 class CompoundStatement(Node): 118 class CompoundStatement(Node):
119 def __init__(self, statements): 119 def __init__(self, statements):
120 self.statements = statements 120 self.statements = statements