summaryrefslogtreecommitdiff
path: root/nandgame/assembler/parser.py
diff options
context:
space:
mode:
authoruvok2026-01-12 19:28:03 +0100
committeruvok2026-01-12 19:28:03 +0100
commitf6160a3036a3a6731d3536315ea205852a9283e0 (patch)
treed8f41109b4d130db3660107cd2374b8697180465 /nandgame/assembler/parser.py
parent7e2ecc6e1f9e49439696adc72dcbefd699168e44 (diff)
Include NL in lexer/parser
makes sure instructions are separated.
Diffstat (limited to 'nandgame/assembler/parser.py')
-rw-r--r--nandgame/assembler/parser.py21
1 files changed, 15 insertions, 6 deletions
diff --git a/nandgame/assembler/parser.py b/nandgame/assembler/parser.py
index b2cc3f9..373f4bd 100644
--- a/nandgame/assembler/parser.py
+++ b/nandgame/assembler/parser.py
@@ -10,7 +10,7 @@ from lexer import tokens
def p_error(p: LexToken):
if p:
- print(f"Unexpected {p.value} on line {p.lineno}")
+ print(f"Unexpected {repr(p.value)} on line {p.lineno}")
else:
print("Unexpected end of file.")
@@ -24,8 +24,8 @@ def p_empty(p):
pass
def p_inss(p):
- '''instruction_list : instruction_list instruction
- | instruction
+ '''instruction_list : instruction_list line
+ | line
'''
if len(p) == 2:
p[0] = [p[1]]
@@ -39,8 +39,8 @@ def p_inss(p):
pass
def p_inss2(p):
- '''instruction_list2 : instruction instruction_list2
- | instruction
+ '''instruction_list2 : line instruction_list2
+ | line
'''
if len(p) == 2:
p[0] = [p[1]]
@@ -53,13 +53,22 @@ def p_inss2(p):
print(f" {p[2]}")
pass
+def p_line(p):
+ '''line : instruction NL
+ | NL
+ '''
+ if len(p) == 2:
+ pass
+ else:
+ p[0] = p[1]
+
def p_instruction(p):
'''instruction : noarg
| onearg
| twoarg
| jumpdest
+ | invalid_arg
'''
- # | invalid_arg
print(f"INS: {p[1]}")
p[0] = p[1]
pass