diff python/ppci/assembler.py @ 375:19eacf4f7270

Started on memory manager
author Windel Bouwman
date Sun, 23 Mar 2014 15:44:06 +0100
parents 3bb7dcfe5529
children 6df89163e114
line wrap: on
line diff
--- a/python/ppci/assembler.py	Fri Mar 21 15:27:18 2014 +0100
+++ b/python/ppci/assembler.py	Sun Mar 23 15:44:06 2014 +0100
@@ -97,7 +97,7 @@
 
     def __init__(self, kws, instruction_rules, emit):
         # Construct a parser given a grammar:
-        tokens2 = ['ID', 'NUMBER', ',', '[', ']', ':', '+', '-', '*',
+        tokens2 = ['ID', 'NUMBER', ',', '[', ']', ':', '+', '-', '*', '=',
                    pyyacc.EPS, 'COMMENT', '{', '}',
                    pyyacc.EOF, 'val32', 'val16', 'val12', 'val8', 'val5', 'val3']
         tokens2.extend(kws)
@@ -119,57 +119,17 @@
             self.add_rule(prod, rhs, f)
 
         #g.add_production('instruction', [])
-        g.add_production('expression', ['term'], lambda x: x)
-        g.add_production('expression', ['expression', 'addop', 'term'], self.p_binop)
-        g.add_production('addop', ['-'], lambda x: x.val)
-        g.add_production('addop', ['+'], lambda x: x.val)
-        g.add_production('mulop', ['*'], lambda x: x.val)
-        g.add_production('term', ['factor'], lambda x: x)
-        g.add_production('term', ['term', 'mulop', 'factor'], self.p_binop)
-        g.add_production('factor', ['ID'], lambda name: ASymbol(name.val))
-        g.add_production('factor', ['NUMBER'], lambda num: ANumber(int(num.val)))
         g.start_symbol = 'asmline'
         self.emit = emit
         self.p = g.generate_parser()
         # print('length of table:', len(self.p.action_table))
 
     # Parser handlers:
-    def p_ins_1(self, opc, ops):
-        ins = AInstruction(opc, ops)
-        self.emit(ins)
-
-    def p_ins_2(self, opc):
-        self.p_ins_1(opc, [])
-
-    def p_operands_1(self, op1):
-        return [op1]
-
-    def p_operands_2(self, ops, comma, op2):
-        assert type(ops) is list
-        ops.append(op2)
-        return ops
-
-    def p_listitems_1(self, li1):
-        return [li1]
-
-    def p_listitems_2(self, lis, comma, li2):
-        assert type(lis) is list
-        lis.append(li2)
-        return lis
-
-    def p_list_op(self, brace_open, lst, brace_close):
-        return AUnop('{}', lst)
-
-    def p_mem_op(self, brace_open, exp, brace_close):
-        return AUnop('[]', exp)
 
     def p_label(self, lname, cn):
         lab = Label(lname.val)
         self.emit(lab)
 
-    def p_binop(self, exp1, op, exp2):
-        return ABinop(op, exp1, exp2)
-
     def parse(self, lexer):
         self.p.parse(lexer)