feat: Implement booleans (Kawaii/Cringe)

This commit is contained in:
Alvin
2025-07-22 16:52:55 +02:00
parent 89492017ea
commit 7ef8f820b4
3 changed files with 23 additions and 1 deletions

12
examples/booleans.fem Normal file
View File

@@ -0,0 +1,12 @@
my_bool is Kawaii
Femboy Feminine my_bool Femboycore
UwU Boy "It's Kawaii!"
Periodt
Femboy Feminine Cringe Femboycore
UwU Boy "This won't print."
Periodt
Androgyny Femboycore
UwU Boy "This will print."
Periodt

View File

@@ -26,6 +26,9 @@ class Interpreter:
def visit_String(self, node): def visit_String(self, node):
return node.value return node.value
def visit_Boolean(self, node):
return node.value
def visit_BinOp(self, node): def visit_BinOp(self, node):
left_val = self.visit(node.left) left_val = self.visit(node.left)
right_val = self.visit(node.right) right_val = self.visit(node.right)

View File

@@ -11,6 +11,11 @@ class String(AST):
self.token = token self.token = token
self.value = token.value self.value = token.value
class Boolean(AST):
def __init__(self, token):
self.token = token
self.value = token.value
class BinOp(AST): class BinOp(AST):
def __init__(self, left, op, right): def __init__(self, left, op, right):
self.left = left self.left = left
@@ -240,8 +245,10 @@ class Parser:
if self.peek_next_token().type == 'LPAREN': # Assuming '(' is the next token for a function call if self.peek_next_token().type == 'LPAREN': # Assuming '(' is the next token for a function call
return self.parse_function_call(token) return self.parse_function_call(token)
return Variable(token) return Variable(token)
elif token.type == 'KAWAII' or token.type == 'CRINGE':
return Boolean(token)
else: else:
raise Exception(f"Expected integer, string or identifier, got {token.type}") raise Exception(f"Expected integer, string, boolean or identifier, got {token.type}")
def term(self): def term(self):
node = self.factor() node = self.factor()