Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to get some more features in #17

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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?"
40 changes: 36 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
@@ -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 = {}
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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':
Expand Down