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)
class IRProp:
lexeme: Lexeme[Tok]
arguments: 'Sequence[IRTerm]'
def __str__(self) -> str:
return f'{self.lexeme.matched_string}({",".join(str(arg) for arg in self.arguments)})'
"""
Represents a proposition or object for resolution
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)
class IRVar:
lexeme: Lexeme[Tok]
def __str__(self) -> str:
return f'*{self.lexeme.matched_string}'
"""
A variable which may be substituted for any other term
"""
lexeme: Lexeme[Tok]
def __str__(self) -> str:
return f'*{self.lexeme.matched_string}'
@dataclass(frozen=True)
class IRNeg:
inner: 'IRTerm'
def __str__(self) -> str:
return f'¬{self.inner}'
"""
A negated proposition
"""
inner: 'IRTerm'
def __str__(self) -> str:
return f'¬{self.inner}'
IRTerm: TypeAlias = IRVar | IRProp | IRNeg