Files
algorithms-26/task2/math_objects.py

30 lines
689 B
Python

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