diff python/asm.py @ 198:33d50727a23c

Fixup testscript
author Windel Bouwman
date Sat, 01 Jun 2013 13:11:22 +0200
parents 4a1ca1271241
children a690473b79e2
line wrap: on
line diff
--- a/python/asm.py	Sat Jun 01 11:56:16 2013 +0200
+++ b/python/asm.py	Sat Jun 01 13:11:22 2013 +0200
@@ -1,16 +1,8 @@
-import re
+import re, sys, argparse
 import pyyacc
 from ppci import Token, CompilerError, SourceLocation
-import sys, argparse
 
 
-# Different instruction sets:
-class InstructionSet:
-   pass
-
-class X86(InstructionSet):
-   pass
-
 # Generic assembler:
 keywords = ['global', 'db']
 
@@ -28,7 +20,8 @@
        ('ID', r'[A-Za-z][A-Za-z\d_]*'),
        ('SKIP', r'[ \t]'),
        ('LEESTEKEN', r':=|[\.,=:\-+*\[\]/\(\)]|>=|<=|<>|>|<'),
-       ('STRING', r"'.*?'")
+       ('STRING', r"'.*?'"),
+       ('COMMENT', r";.*")
      ]
      tok_re = '|'.join('(?P<%s>%s)' % pair for pair in tok_spec)
      gettok = re.compile(tok_re).match
@@ -138,11 +131,15 @@
         self.output = []
         # Construct a parser given a grammar:
         ident = lambda x: x   # Identity helper function
-        g = pyyacc.Grammar(['ID', 'NUMBER', ',', '[', ']', ':', '+', '-', '*', pyyacc.EPS])
-        g.add_production('asmline', ['label', 'instruction'])
-        g.add_production('asmline', ['instruction'])
-        g.add_production('asmline', ['label'])
-        g.add_production('asmline', [])
+        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'])
+        g.add_production('asmline2', ['instruction'])
+        g.add_production('asmline2', ['label'])
+        g.add_production('asmline2', [])
+        g.add_production('optcomment', [])
+        g.add_production('optcomment', ['COMMENT'])
         g.add_production('label', ['ID', ':'], self.p_label)
         g.add_production('instruction', ['opcode', 'operands'], self.p_ins_1)
         g.add_production('instruction', ['opcode'], self.p_ins_2)
@@ -218,7 +215,7 @@
         self.parse_line(line)
         self.assemble_aast()
 
-    def assemble_aast(self, at):
+    def assemble_aast(self):
         """ Assemble a parsed asm line """
         pass