Further progress
This commit is contained in:
		
							
								
								
									
										9
									
								
								main.py
									
									
									
									
									
								
							
							
						
						
									
										9
									
								
								main.py
									
									
									
									
									
								
							@@ -1,17 +1,12 @@
 | 
				
			|||||||
import sys
 | 
					import sys
 | 
				
			||||||
import preprocessor
 | 
					import preprocessor
 | 
				
			||||||
import token
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
if len(sys.argv) < 2:
 | 
					if len(sys.argv) < 2:
 | 
				
			||||||
    print("Usage: hgc (file)")
 | 
					    print("Usage: hgc (file)")
 | 
				
			||||||
    exit(1)
 | 
					    exit(1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
file = open(sys.argv[1]).readlines()
 | 
					with open(sys.argv[1], "r") as file:
 | 
				
			||||||
 | 
					    lines = [preprocessor.process_line(line) for line in file]
 | 
				
			||||||
lines: list[token.tokenlist] = []
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
for line in file:
 | 
					 | 
				
			||||||
    lines.append(preprocessor.process_line(line))
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
for line in lines:
 | 
					for line in lines:
 | 
				
			||||||
    print(line)
 | 
					    print(line)
 | 
				
			||||||
@@ -2,6 +2,8 @@ import token
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
delimiters = ["=", ">", "<", "+", "-", "*", "/", " "]
 | 
					delimiters = ["=", ">", "<", "+", "-", "*", "/", " "]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					quick_tokens = [">", "<", "+", "-", "*", "/"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def doNothing():
 | 
					def doNothing():
 | 
				
			||||||
    return
 | 
					    return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -16,6 +18,12 @@ def process_line(process: str) -> list[token.Token]:
 | 
				
			|||||||
        if prevEquals and c != '=':
 | 
					        if prevEquals and c != '=':
 | 
				
			||||||
            tokens.append(token.Token("="))
 | 
					            tokens.append(token.Token("="))
 | 
				
			||||||
            prevEquals = False
 | 
					            prevEquals = False
 | 
				
			||||||
 | 
					        if c in quick_tokens:
 | 
				
			||||||
 | 
					            tokens.append(token.Token(c))
 | 
				
			||||||
 | 
					            if buf != "":
 | 
				
			||||||
 | 
					                tokens.append(token.Token(buf))
 | 
				
			||||||
 | 
					                buf = ""
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
            match c:
 | 
					            match c:
 | 
				
			||||||
                case '\n':
 | 
					                case '\n':
 | 
				
			||||||
                    doNothing()
 | 
					                    doNothing()
 | 
				
			||||||
@@ -24,7 +32,7 @@ def process_line(process: str) -> list[token.Token]:
 | 
				
			|||||||
                case '=':
 | 
					                case '=':
 | 
				
			||||||
                    if prevEquals:
 | 
					                    if prevEquals:
 | 
				
			||||||
                        prevEquals = False
 | 
					                        prevEquals = False
 | 
				
			||||||
                    tokens.append(token.Token(buf))
 | 
					                        tokens.append(token.Token("=="))
 | 
				
			||||||
                    else:
 | 
					                    else:
 | 
				
			||||||
                        prevEquals = True
 | 
					                        prevEquals = True
 | 
				
			||||||
                case _:
 | 
					                case _:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,3 +1,7 @@
 | 
				
			|||||||
let dingus = 10
 | 
					let dingus = 10
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if "test" == "test"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
print(dingus)
 | 
					print(dingus)
 | 
				
			||||||
							
								
								
									
										19
									
								
								token.py
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								token.py
									
									
									
									
									
								
							@@ -13,17 +13,18 @@ class TokenType(Enum):
 | 
				
			|||||||
    ELSE = 9
 | 
					    ELSE = 9
 | 
				
			||||||
    WHILE = 10
 | 
					    WHILE = 10
 | 
				
			||||||
    LET = 11
 | 
					    LET = 11
 | 
				
			||||||
 | 
					    END = 12
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ADD = 12
 | 
					    ADD = 13
 | 
				
			||||||
    SUBTRACT = 13
 | 
					    SUBTRACT = 14
 | 
				
			||||||
    MULTIPLY = 14
 | 
					    MULTIPLY = 15
 | 
				
			||||||
    DIVIDE = 15
 | 
					    DIVIDE = 16
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    SET = 16
 | 
					    SET = 17
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    EQUAL = 17
 | 
					    EQUAL = 18
 | 
				
			||||||
    GREATER = 18
 | 
					    GREATER = 19
 | 
				
			||||||
    LESSER = 19
 | 
					    LESSER = 20
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    UNKNOWN = 0
 | 
					    UNKNOWN = 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -50,6 +51,8 @@ def get_type(process: str) -> TokenType:
 | 
				
			|||||||
            return TokenType.WHILE
 | 
					            return TokenType.WHILE
 | 
				
			||||||
        case "true" | "false":
 | 
					        case "true" | "false":
 | 
				
			||||||
            return TokenType.BOOLEAN
 | 
					            return TokenType.BOOLEAN
 | 
				
			||||||
 | 
					        case "end":
 | 
				
			||||||
 | 
					            return TokenType.END
 | 
				
			||||||
        case "+":
 | 
					        case "+":
 | 
				
			||||||
            return TokenType.ADD
 | 
					            return TokenType.ADD
 | 
				
			||||||
        case "-":
 | 
					        case "-":
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user