# get type names
from types import *
-# Prepend the directory where the PLY lex & yacc modules are found
-# to the search path.
-sys.path[0:0] = [os.environ['M5_PLY']]
-
from ply import lex
from ply import yacc
self.micro_classes = {}
self.labels = {}
- def add_microop(self, microop):
+ def add_microop(self, mnemonic, microop):
self.microops.append(microop)
def __str__(self):
raise
try:
for label in statement.labels:
- container.labels[label.name] = microop
- if label.extern:
- container.externs[label.name] = microop
- container.add_microop(microop)
+ container.labels[label.text] = microop
+ if label.is_extern:
+ container.externs[label.text] = microop
+ container.add_microop(statement.mnemonic, microop)
except:
print_error("Error adding microop.")
raise
def t_asm_ID(t):
r'[A-Za-z_]\w*'
t.type = reserved_map.get(t.value, 'ID')
- t.lexer.begin('params')
+ # If the ID is really "extern", we shouldn't start looking for parameters
+ # yet. The real ID, the label itself, is coming up.
+ if t.type != 'EXTERN':
+ t.lexer.begin('params')
return t
# If there is a label and you're -not- in the assembler (which would be caught
t[1].append(t[2])
t[0] = t[1]
+# labels on lines by themselves are attached to the following instruction.
+def p_labels_2(t):
+ 'labels : labels NEWLINE'
+ t[0] = t[1]
+
def p_label_0(t):
'label : ID COLON'
label = Label()