diff options
Diffstat (limited to 'nandgame/assembler/py_nand_ass/lexer.py')
| -rwxr-xr-x | nandgame/assembler/py_nand_ass/lexer.py | 25 |
1 files changed, 20 insertions, 5 deletions
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 |
