diff python/asm.py @ 206:6c6bf8890d8a

Added push and pop encodings
author Windel Bouwman
date Fri, 28 Jun 2013 16:49:38 +0200
parents ca1ea402f6a1
children 003c8a976fff
line wrap: on
line diff
--- a/python/asm.py	Sun Jun 23 18:23:18 2013 +0200
+++ b/python/asm.py	Fri Jun 28 16:49:38 2013 +0200
@@ -17,7 +17,7 @@
        ('NUMBER', r'\d+'),
        ('ID', r'[A-Za-z][A-Za-z\d_]*'),
        ('SKIP', r'[ \t]'),
-       ('LEESTEKEN', r':=|[\.,=:\-+*\[\]/\(\)]|>=|<=|<>|>|<'),
+       ('LEESTEKEN', r':=|[\.,=:\-+*\[\]/\(\)]|>=|<=|<>|>|<|}|{'),
        ('STRING', r"'.*?'"),
        ('COMMENT', r";.*")
      ]
@@ -73,7 +73,7 @@
         self.restart()
         # Construct a parser given a grammar:
         ident = lambda x: x   # Identity helper function
-        g = pyyacc.Grammar(['ID', 'NUMBER', ',', '[', ']', ':', '+', '-', '*', pyyacc.EPS, 'COMMENT'])
+        g = pyyacc.Grammar(['ID', 'NUMBER', ',', '[', ']', ':', '+', '-', '*', pyyacc.EPS, 'COMMENT', '{', '}'])
         g.add_production('asmline', ['asmline2'])
         g.add_production('asmline', ['asmline2', 'COMMENT'])
         g.add_production('asmline2', ['label', 'instruction'])
@@ -90,6 +90,9 @@
         g.add_production('operands', ['operands', ',', 'operand'], self.p_operands_2)
         g.add_production('operand', ['expression'], ident)
         g.add_production('operand', ['[', 'expression', ']'], self.p_mem_op)
+        g.add_production('operand', ['{', 'listitems', '}'], self.p_list_op)
+        g.add_production('listitems', ['expression'], self.p_listitems_1)
+        g.add_production('listitems', ['listitems', ',', 'expression'], self.p_listitems_2)
         g.add_production('expression', ['term'], ident)
         g.add_production('expression', ['expression', 'addop', 'term'], self.p_binop)
         g.add_production('addop', ['-'], ident)
@@ -114,6 +117,17 @@
         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):