From 63601830da505314839ebe4edbcf6c88af16c69b Mon Sep 17 00:00:00 2001 From: uvok Date: Fri, 16 Jan 2026 12:50:27 +0100 Subject: parser: Add support for bin,oct and fix hex nums --- nandgame/assembler/py_nand_ass/lexer.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'nandgame/assembler/py_nand_ass/lexer.py') diff --git a/nandgame/assembler/py_nand_ass/lexer.py b/nandgame/assembler/py_nand_ass/lexer.py index 75a3f2f..436119b 100755 --- a/nandgame/assembler/py_nand_ass/lexer.py +++ b/nandgame/assembler/py_nand_ass/lexer.py @@ -10,8 +10,10 @@ tokens = ( "COLON", "SYMBOL", "SHARP", - "NUMBER", + "BINNUMBER", + "OCTNUMBER", "HEXNUMBER", + "DECNUMBER", "DOT", "REG", "NL", @@ -39,9 +41,16 @@ def t_JUMP(t): return t -def t_NUMBER(t): - r"\d+" - t.value = int(t.value) +# order matters! these need to come first! +def t_BINNUMBER(t): + r"0b[01]+" + t.value = int(t.value, 2) + return t + + +def t_OCTNUMBER(t): + r"0[0-9]+" + t.value = int(t.value, 8) return t @@ -51,8 +60,14 @@ def t_HEXNUMBER(t): return t +def t_DECNUMBER(t): + r"\d+" + t.value = int(t.value) + return t + + def t_SYMBOL(t): - r"[A-Za-z][A-Za-z0-9_]+" + r"\b([A-Za-z][A-Za-z0-9_]+)\b" return t -- cgit v1.2.3