Mercurial > lcfOS
comparison python/ppci/irutils.py @ 318:e84047f29c78
Add burg and yacc initial attempts
author | Windel Bouwman |
---|---|
date | Tue, 31 Dec 2013 12:38:15 +0100 |
parents | e30a77ae359b |
children | 988f3fb861e4 |
comparison
equal
deleted
inserted
replaced
317:e30a77ae359b | 318:e84047f29c78 |
---|---|
117 def Consume(self, typ): | 117 def Consume(self, typ): |
118 if self.Peak == typ: | 118 if self.Peak == typ: |
119 return self.next_token() | 119 return self.next_token() |
120 else: | 120 else: |
121 raise IrParseException('Expected "{}" got "{}"'.format(typ, self.Peak)) | 121 raise IrParseException('Expected "{}" got "{}"'.format(typ, self.Peak)) |
122 | 122 |
123 def parse_module(self): | 123 def parse_module(self): |
124 """ Entry for recursive descent parser """ | 124 """ Entry for recursive descent parser """ |
125 self.Consume('module') | 125 self.Consume('module') |
126 name = self.Consume('ID')[1] | 126 name = self.Consume('ID')[1] |
127 module = ir.Module(name) | 127 module = ir.Module(name) |
130 if self.Peak == 'function': | 130 if self.Peak == 'function': |
131 module.add_function(self.parse_function()) | 131 module.add_function(self.parse_function()) |
132 else: | 132 else: |
133 raise IrParseException('Expected function got {}'.format(self.Peak)) | 133 raise IrParseException('Expected function got {}'.format(self.Peak)) |
134 return module | 134 return module |
135 | 135 |
136 def parse_function(self): | 136 def parse_function(self): |
137 self.Consume('function') | 137 self.Consume('function') |
138 self.parse_type() | 138 self.parse_type() |
139 name = self.Consume('ID')[1] | 139 name = self.Consume('ID')[1] |
140 function = ir.Function(name) | 140 function = ir.Function(name) |
257 def verify_block_termination(self, block): | 257 def verify_block_termination(self, block): |
258 assert not block.Empty | 258 assert not block.Empty |
259 assert block.LastInstruction.IsTerminator | 259 assert block.LastInstruction.IsTerminator |
260 for i in block.Instructions[:-1]: | 260 for i in block.Instructions[:-1]: |
261 assert not isinstance(i, ir.LastStatement) | 261 assert not isinstance(i, ir.LastStatement) |
262 | 262 |
263 def verify_block(self, block): | 263 def verify_block(self, block): |
264 for instruction in block.Instructions: | 264 for instruction in block.Instructions: |
265 self.verify_instruction(instruction) | 265 self.verify_instruction(instruction) |
266 | 266 |
267 def verify_instruction(self, instruction): | 267 def verify_instruction(self, instruction): |