Further progress

This commit is contained in:
2025-09-01 21:06:05 +10:00
parent a604b8d5c4
commit 5ebf653342
4 changed files with 38 additions and 28 deletions

View File

@@ -1,17 +1,12 @@
import sys
import preprocessor
import token
if len(sys.argv) < 2:
print("Usage: hgc (file)")
exit(1)
file = open(sys.argv[1]).readlines()
lines: list[token.tokenlist] = []
for line in file:
lines.append(preprocessor.process_line(line))
with open(sys.argv[1], "r") as file:
lines = [preprocessor.process_line(line) for line in file]
for line in lines:
print(line)

View File

@@ -2,6 +2,8 @@ import token
delimiters = ["=", ">", "<", "+", "-", "*", "/", " "]
quick_tokens = [">", "<", "+", "-", "*", "/"]
def doNothing():
return
@@ -16,6 +18,12 @@ def process_line(process: str) -> list[token.Token]:
if prevEquals and c != '=':
tokens.append(token.Token("="))
prevEquals = False
if c in quick_tokens:
tokens.append(token.Token(c))
if buf != "":
tokens.append(token.Token(buf))
buf = ""
else:
match c:
case '\n':
doNothing()
@@ -24,7 +32,7 @@ def process_line(process: str) -> list[token.Token]:
case '=':
if prevEquals:
prevEquals = False
tokens.append(token.Token(buf))
tokens.append(token.Token("=="))
else:
prevEquals = True
case _:

View File

@@ -1,3 +1,7 @@
let dingus = 10
if "test" == "test"
end
print(dingus)

View File

@@ -13,17 +13,18 @@ class TokenType(Enum):
ELSE = 9
WHILE = 10
LET = 11
END = 12
ADD = 12
SUBTRACT = 13
MULTIPLY = 14
DIVIDE = 15
ADD = 13
SUBTRACT = 14
MULTIPLY = 15
DIVIDE = 16
SET = 16
SET = 17
EQUAL = 17
GREATER = 18
LESSER = 19
EQUAL = 18
GREATER = 19
LESSER = 20
UNKNOWN = 0
@@ -50,6 +51,8 @@ def get_type(process: str) -> TokenType:
return TokenType.WHILE
case "true" | "false":
return TokenType.BOOLEAN
case "end":
return TokenType.END
case "+":
return TokenType.ADD
case "-":