diff --git a/exceptions.py b/exceptions.py index fe36dec..6633bbe 100644 --- a/exceptions.py +++ b/exceptions.py @@ -24,7 +24,7 @@ def __init__(self, cond,symbol_table): self.symbol_table=symbol_table def __str__(self): - return f"\033[38;5;14mSOMETHING WENT WRONG EVALUATING: {self.cond}\nHERE IS THE CURRENT SYMBOL TABLE:\n {self.symbol_table}" + return f"\033[38;5;14mSOMETHING WENT WRONG EVALUATING: {self.cond}\nHERE IS THE CURRENT SYMBOL TABLE:\n{self.symbol_table}" class _noLabel(Exception): def __init__(self, label): @@ -52,3 +52,18 @@ def __str__(self): class _unmatchedComment(Exception): def __str__(self): return "\033[38;5;14mWHICH IS BETTER? PAWS OR MAWS?" + +class _clearError(Exception): + def __init__(self, var): + self.var=var + + def __str__(self): + return f"\033[38;5;14mCANNOT CLEAR A {type(self.var).upper()}! ({self.var})" + +class _outOfScope(Exception): + def __str__(self): + return f"\033[38;5;14mLEASH TOO SHORT" + +class _furpileDuplicate(Exception): + def __str__(self): + return f"\033[38;5;14mWHO'S THE FAKE ONE?" \ No newline at end of file diff --git a/main.py b/main.py index 36849e6..bc98536 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,6 @@ import math -from exceptions import _noEnd,_undeclared_var,_caperror,_jump_error,_noLabel,_noStart,_noBoop,_tooManyBoop,_castingFail,_unmatchedComment +from exceptions import _noEnd,_undeclared_var,_caperror,_jump_error,_noLabel,_noStart,_noBoop,_tooManyBoop,_castingFail,_unmatchedComment, _clearError class EsoFurCompiler: def __init__(self): self.symbol_table = {} @@ -86,6 +86,28 @@ def compile(self, code): i+=1 continue + #var clearing + if line.endswith("Gets Canceled"): + var = line.removesuffix(" Gets Canceled") + if var.startswith('"') or var.endswith('"'): + raise _clearError(var) + if var.isdigit() == True: + raise _clearError(var) + if var not in self.symbol_table: + raise _undeclared_var(var) + self.symbol_table[var] = None + i+=1 + continue + + # String joining + if line.startswith("Look!") and "Joined The" in line: + add, original1 = line[line.find("Look!")+5:line.find("Joined The")], line[line.find("Joined The")+11:] + add = str(self._parse_value(add.strip())) + original = str(self._parse_value(original1.strip())) + self.symbol_table[original1] = original+add + i+=1 + continue + # Jumps if 'Nuzzles' in line: if line.startswith("Nuzzles")==False: @@ -125,12 +147,22 @@ def compile(self, code): # Print if line.startswith('Howl'): - var_name = line.split(' ')[1] - value = self._assign(var_name.strip()) + var_name = line.removeprefix("Howl") + value = self._parse_value(var_name.strip()) print(value) i+=1 continue + if line.startswith("Awoo"): + var = line.split("Awoo")[1] + value = self._parse_value(var.strip()) + if type(value)==int: + print(chr(value)) + else: + print(value) + i += 1 + continue + # Ask user for input if line.startswith('Boop The User For'): text=line.split() @@ -237,7 +269,7 @@ def _parse_value(self, value_str): try: return eval(value_str, {}, self.symbol_table) except: - raise _jump_error() + raise _jump_error("a", "b") def _cast_value(self, value, type_name): if type_name == 'Int':