add evaluator
This commit is contained in:
parent
5135c149ef
commit
dd527edbc4
116
evaluator.py
Normal file
116
evaluator.py
Normal 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()
|
||||
|
Loading…
Reference in New Issue
Block a user