feat: add task 2 calculator draft

This commit is contained in:
2026-04-09 17:28:40 +06:00
parent 67e25b3f72
commit 3ac1c8b2a1
6 changed files with 222 additions and 1 deletions

29
task2/math_objects.py Normal file
View 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