feat: add task 2 calculator draft
This commit is contained in:
29
task2/math_objects.py
Normal file
29
task2/math_objects.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from collections import deque
|
||||
from typing import Literal, Self
|
||||
|
||||
|
||||
class Token[T]:
|
||||
value: T
|
||||
|
||||
def __init__(self, value: T) -> None:
|
||||
self.value = value
|
||||
|
||||
class Integer(Token[int]):
|
||||
@classmethod
|
||||
def create_from_string(cls, string: str) -> Self:
|
||||
return cls(int(string))
|
||||
|
||||
type _OperatorType = Literal["+", "-", "*", "/"]
|
||||
|
||||
class Operator(Token[_OperatorType]):
|
||||
def __init__(self, value: Literal["+", "-", "*", "/"], precedence = 0) -> None:
|
||||
super().__init__(value)
|
||||
self.precedence: int = precedence
|
||||
|
||||
type _Parentheses = Literal["(", ")"]
|
||||
|
||||
class Parenthesis(Token[_Parentheses]):
|
||||
pass
|
||||
|
||||
# class Stack(MathObject[deque[MathObject]]):
|
||||
# pass
|
||||
Reference in New Issue
Block a user