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/utils.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'projects/hackc/utils.py') diff --git a/projects/hackc/utils.py b/projects/hackc/utils.py index d1ea3ca..4861088 100644 --- a/projects/hackc/utils.py +++ b/projects/hackc/utils.py @@ -4,6 +4,16 @@ EXIT_CODE_FILE_ERROR = 1 EXIT_CODE_INVALID_TOKEN = 2 EXIT_CODE_SYNTAX_ERROR = 4 +# vim autoindent misbehaves if I type these verbatim in strings +LEFT_BRACE = "{" +RIGHT_BRACE = "}" + +class JackSyntaxError(Exception): + def __init__(self, msg, token): + self.message = msg + self.token = token + super().__init__(msg) + def print_err(msg): print(msg, file=stderr) -- cgit v1.2.3