From f6160a3036a3a6731d3536315ea205852a9283e0 Mon Sep 17 00:00:00 2001 From: uvok Date: Mon, 12 Jan 2026 19:28:03 +0100 Subject: Include NL in lexer/parser makes sure instructions are separated. --- nandgame/assembler/parser.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'nandgame/assembler/parser.py') 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 -- cgit v1.2.3