Skip to content

Commit a9169b7

Browse files
committed
Bugfix: detect keywords before colon
Things like: nop: were being parsed as labels, instead of NOP <COLON>. Fixed.
1 parent f7e52f2 commit a9169b7

4 files changed

Lines changed: 14 additions & 3 deletions

File tree

asmlex.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,13 @@
157157
tuple(preprocessor.values())
158158
)
159159

160+
keywords = set(
161+
flags.keys()).union(
162+
regs16.keys()).union(
163+
regs8.keys()).union(
164+
pseudo.keys()).union(
165+
reserved_instructions.keys())
166+
160167

161168
def get_uniques(l):
162169
""" Returns a list with no repeated elements.
@@ -248,12 +255,13 @@ def t_INITIAL_ID(self, t):
248255
tmp = t.value # Saves original value
249256
if tmp[-1] == ':':
250257
c = self.find_column(t)
251-
if not self.input_data[t.lexpos - c + 1: t.lexpos].strip():
258+
tmp = t.value = t.value[:-1].strip() # remove the colon ':'
259+
260+
if not self.input_data[t.lexpos - c + 1: t.lexpos].strip() and tmp.lower() not in keywords:
252261
t.type = 'LABEL'
253-
t.value = tmp[:-1].strip()
262+
t.value = tmp
254263
return t
255264

256-
tmp = t.value = t.value[:-1].strip() # remove the colon ':'
257265
t.lexer.lexpos -= 1
258266

259267
t.value = tmp.upper() # Convert it to uppercase, since our internal tables uses uppercase

tests/functional/and_err.asm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
and : a, 0

tests/functional/nop_nop.asm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
nop:nop
2+

tests/functional/nop_nop.bin

2 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)