This commit is contained in:
Emi Simpson 2023-03-05 16:51:19 -05:00
parent f84a340f0a
commit ad012184c5
Signed by: Emi
GPG key ID: A12F2C2FFDC3D847

36
ir.py
View file

@ -6,21 +6,37 @@ from tokens import Tok
@dataclass(frozen=True) @dataclass(frozen=True)
class IRProp: class IRProp:
lexeme: Lexeme[Tok] """
arguments: 'Sequence[IRTerm]' Represents a proposition or object for resolution
def __str__(self) -> str:
return f'{self.lexeme.matched_string}({",".join(str(arg) for arg in self.arguments)})' Can have any number of arguments, each of which should be a `IRTerm`. Note that no
distinction is made between predicates (n-arity, logical statements), functions
(positive-arity functions over objects), and constants (stand-ins for objects)
"""
lexeme: Lexeme[Tok]
"""
The identifier of this thing, including its location in the source
"""
arguments: 'Sequence[IRTerm]'
def __str__(self) -> str:
return f'{self.lexeme.matched_string}({",".join(str(arg) for arg in self.arguments)})'
@dataclass(frozen=True) @dataclass(frozen=True)
class IRVar: class IRVar:
lexeme: Lexeme[Tok] """
def __str__(self) -> str: A variable which may be substituted for any other term
return f'*{self.lexeme.matched_string}' """
lexeme: Lexeme[Tok]
def __str__(self) -> str:
return f'*{self.lexeme.matched_string}'
@dataclass(frozen=True) @dataclass(frozen=True)
class IRNeg: class IRNeg:
inner: 'IRTerm' """
def __str__(self) -> str: A negated proposition
return f'¬{self.inner}' """
inner: 'IRTerm'
def __str__(self) -> str:
return f'¬{self.inner}'
IRTerm: TypeAlias = IRVar | IRProp | IRNeg IRTerm: TypeAlias = IRVar | IRProp | IRNeg