diff --git a/evaluator.py b/evaluator.py new file mode 100644 index 0000000..0c71648 --- /dev/null +++ b/evaluator.py @@ -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() + diff --git a/main.py b/main.py index cc1aa60..0259721 100644 --- a/main.py +++ b/main.py @@ -6,9 +6,9 @@ def main() -> None: text = "\"\\\"hello\\\\\"" lexer = Lexer(text) parser = Parser(text, lexer) - parsed = parser.parse_expr() - print(parsed) - + parsed = parser.parse() + for node in parsed: + print(node) if __name__ == "__main__": main()