diff options
author | Frederick Yin <fkfd@fkfd.me> | 2022-08-30 14:46:23 +0800 |
---|---|---|
committer | Frederick Yin <fkfd@fkfd.me> | 2022-08-30 14:46:23 +0800 |
commit | b439d663a3f3d4d275f07339c1c0e794808f67d9 (patch) | |
tree | 6ab4a6b152336271f4d38c961cee67922020192e /projects/hackc/parser.py | |
parent | d303447dc7a830489828be2e66ccf8c36af4aed6 (diff) |
hackc: parse variable declaration
Also add a handful of overloading operators to Token
Diffstat (limited to 'projects/hackc/parser.py')
-rw-r--r-- | projects/hackc/parser.py | 6 |
1 files changed, 5 insertions, 1 deletions
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) |