mirror of
https://github.com/Alvin-Zilverstand/femcode.git
synced 2026-03-06 11:06:47 +01:00
feat: Implement booleans (Kawaii/Cringe)
This commit is contained in:
12
examples/booleans.fem
Normal file
12
examples/booleans.fem
Normal 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
|
||||||
@@ -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)
|
||||||
|
|||||||
@@ -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()
|
||||||
|
|||||||
Reference in New Issue
Block a user