Skip to content

Commit

Permalink
feat(IfElseCondition): add node to interpret if-else statements
Browse files Browse the repository at this point in the history
  • Loading branch information
aadhithya committed May 16, 2022
1 parent 56e7a88 commit 8ae2192
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion rajinipp/ast/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ def __init__(self, condition, value) -> None:
self.value = value

def eval(self):
if self.condition:
if self.condition.eval():
return self.value.eval()
return


class IfElseCondition(Node):
def __init__(self, condition, true_value, false_value) -> None:
super().__init__()
self.condition = condition
self.true_value = true_value
self.false_value = false_value

def eval(self):
if self.condition.eval():
return self.true_value.eval()
else:
return self.false_value.eval()

0 comments on commit 8ae2192

Please sign in to comment.