From b439d663a3f3d4d275f07339c1c0e794808f67d9 Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Tue, 30 Aug 2022 14:46:23 +0800 Subject: hackc: parse variable declaration Also add a handful of overloading operators to Token --- projects/hackc/parser.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'projects/hackc/parser.py') diff --git a/projects/hackc/parser.py b/projects/hackc/parser.py index f73c3d1..9a927c6 100644 --- a/projects/hackc/parser.py +++ b/projects/hackc/parser.py @@ -1,4 +1,5 @@ from .tokens import Token +from .syntax import Class from .utils import * KEYWORDS = [ @@ -37,7 +38,7 @@ class Parser: def print_tokens(self): print("LINE\tCOL\tTYPE\tTOKEN") for token in self.tokens: - print(f"{token.line_no + 1}\t{token.column + 1}\t{token.type[:3]}\t{token.token}") + print(f"{token.line_no + 1}\t{token.column + 1}\t{token.type[:3]}\t{token}") print(f"===== {len(self.tokens)} tokens =====") def tokenize(self): @@ -91,3 +92,6 @@ class Parser: print_err(line) print_err(" " * pos + f"^ Invalid token") exit(EXIT_CODE_INVALID_TOKEN) + + def parse(self): + syntax_tree = Class.from_tokens(self.tokens) -- cgit v1.2.3