add evaluator

This commit is contained in:
SimonFJ20 2023-04-09 03:48:26 +02:00
parent 5135c149ef
commit dd527edbc4
2 changed files with 119 additions and 3 deletions

116
evaluator.py Normal file
View File

@ -0,0 +1,116 @@
from typing import List, Optional
from position import Node
import parsed
class Value:
pass
class Int(Value):
def __init__(self, value: int) -> None:
super().__init__()
self.value = value
class Char(Value):
def __init__(self, value: str) -> None:
super().__init__()
self.value = value
class String(Value):
def __init__(self, value: str) -> None:
super().__init__()
self.value = value
class Bool(Value):
def __init__(self, value: bool) -> None:
super().__init__()
self.value = value
class EvalResult:
pass
class ValueResult(EvalResult):
def __init__(self, value: Value) -> None:
super().__init__()
self.value = value
class ReturnResult(EvalResult):
def __init__(self, value: Optional[Value]) -> None:
super().__init__()
self.value = value
class BreakResult(EvalResult):
def __init__(self, value: Optional[Value]) -> None:
super().__init__()
self.value = value
class ContinueResult(EvalResult):
def __init__(self, value: Optional[Value]) -> None:
super().__init__()
self.value = value
class Evaluator:
def __init__(self) -> None:
pass
def evaluate(self, ast: List[Node[parsed.Expr]]) -> None:
for node in ast:
self.eval_expr(node)
def eval_expr(self, node: Node[parsed.Expr]) -> EvalResult:
if node.value is parsed.ExprError:
raise NotImplementedError()
elif node.value is parsed.Id:
raise NotImplementedError()
elif node.value is parsed.Int:
raise NotImplementedError()
elif node.value is parsed.Char:
raise NotImplementedError()
elif node.value is parsed.String:
raise NotImplementedError()
elif node.value is parsed.Bool:
raise NotImplementedError()
elif node.value is parsed.Unit:
raise NotImplementedError()
elif node.value is parsed.Tuple:
raise NotImplementedError()
elif node.value is parsed.Block:
raise NotImplementedError()
elif node.value is parsed.Lambda:
raise NotImplementedError()
elif node.value is parsed.If:
raise NotImplementedError()
elif node.value is parsed.Match:
raise NotImplementedError()
elif node.value is parsed.Loop:
raise NotImplementedError()
elif node.value is parsed.While:
raise NotImplementedError()
elif node.value is parsed.For:
raise NotImplementedError()
elif node.value is parsed.StructMember:
raise NotImplementedError()
elif node.value is parsed.TupleMember:
raise NotImplementedError()
elif node.value is parsed.Index:
raise NotImplementedError()
elif node.value is parsed.Call:
raise NotImplementedError()
elif node.value is parsed.Unary:
raise NotImplementedError()
elif node.value is parsed.Binary:
raise NotImplementedError()
elif node.value is parsed.Assign:
raise NotImplementedError()
elif node.value is parsed.Let:
raise NotImplementedError()
elif node.value is parsed.Function:
raise NotImplementedError()
elif node.value is parsed.Return:
raise NotImplementedError()
elif node.value is parsed.Break:
raise NotImplementedError()
elif node.value is parsed.Continue:
raise NotImplementedError()
else:
raise NotImplementedError()

View File

@ -6,9 +6,9 @@ def main() -> None:
text = "\"\\\"hello\\\\\"" text = "\"\\\"hello\\\\\""
lexer = Lexer(text) lexer = Lexer(text)
parser = Parser(text, lexer) parser = Parser(text, lexer)
parsed = parser.parse_expr() parsed = parser.parse()
print(parsed) for node in parsed:
print(node)
if __name__ == "__main__": if __name__ == "__main__":
main() main()