aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/asm_pass0.py5
-rw-r--r--src/asm_pass1.py3
-rw-r--r--src/charmem.py2
-rw-r--r--src/tokenizer.py32
4 files changed, 39 insertions, 3 deletions
diff --git a/src/asm_pass0.py b/src/asm_pass0.py
index 4913e4b..f5b6b0b 100644
--- a/src/asm_pass0.py
+++ b/src/asm_pass0.py
@@ -2,6 +2,7 @@ from dataclasses import dataclass
import os.path
from asm_ops import *
from asm_eval import *
+from tokenizer import *
@dataclass
class Result0Line:
@@ -19,7 +20,9 @@ def pass_0(lines: list[str], file_name: str) -> Result0:
for (line_num, line) in enumerate(lines):
line = line.split(";")[0].strip()
if line == "": continue
- keyword, *args = line.lower().split()
+
+ keyword, *args = tokenize(line)
+
match keyword:
case "@include":
asm_file_name = args[0]
diff --git a/src/asm_pass1.py b/src/asm_pass1.py
index d462526..5e6213a 100644
--- a/src/asm_pass1.py
+++ b/src/asm_pass1.py
@@ -5,6 +5,7 @@ from dataclasses import dataclass
from asm_ops import *
from asm_eval import *
from asm_pass0 import *
+from tokenizer import tokenize
@dataclass
class Result1Line:
@@ -24,7 +25,7 @@ def pass_1(result0: Result0) -> Result1:
operations: OpExpansionDict = default_expansions.copy()
for line in result0.lines:
- keyword, *args = line.line.lower().split()
+ keyword, *args = tokenize(line.line)
match keyword:
case "@opt":
opt_name, opt_value = args
diff --git a/src/charmem.py b/src/charmem.py
index 9b19864..551ba85 100644
--- a/src/charmem.py
+++ b/src/charmem.py
@@ -43,7 +43,7 @@ def string_to_byte(input_string: str):
# Check if the string contains only '0' or '1'
if not all(c in '01' for c in binary_string):
- raise ValueError("Input string must contain only spaces and '#' characters.")
+ raise ValueError("Input string must contain only spaces and '█' characters.")
# Convert the binary string to an unsigned integer byte
return int(binary_string[::-1], 2)
diff --git a/src/tokenizer.py b/src/tokenizer.py
new file mode 100644
index 0000000..2049461
--- /dev/null
+++ b/src/tokenizer.py
@@ -0,0 +1,32 @@
+def tokenize(line: str) -> list[str]:
+ cur: str = ""
+ result: list[str] = []
+ is_py_expr = False
+ idx = 0
+ while idx < len(line):
+ c = line[idx]
+ if not is_py_expr and c == "$":
+ is_py_expr = True
+ idx += 1
+ elif is_py_expr and c == "$":
+ raise Exception("Unexpected start of python expr while already parsing a python expression:\n" + line)
+ elif not is_py_expr and c == "}":
+ raise Exception("Unexpected end of python expr while not parsing a python expression:\n" + line)
+ elif is_py_expr and c == "}":
+ is_py_expr = False
+ result.append(cur)
+ cur = ""
+ elif is_py_expr:
+ cur += c
+ elif c == " " or c == "\t":
+ result.append(cur)
+ cur = ""
+ else:
+ cur += c
+
+ idx += 1
+
+ if len(cur) > 0:
+ result.append(cur)
+
+ return [r for r in result if r != ""] \ No newline at end of file