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

16
ir.py
View file

@ -6,19 +6,35 @@ from tokens import Tok
@dataclass(frozen=True) @dataclass(frozen=True)
class IRProp: class IRProp:
"""
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] lexeme: Lexeme[Tok]
"""
The identifier of this thing, including its location in the source
"""
arguments: 'Sequence[IRTerm]' arguments: 'Sequence[IRTerm]'
def __str__(self) -> str: def __str__(self) -> str:
return f'{self.lexeme.matched_string}({",".join(str(arg) for arg in self.arguments)})' return f'{self.lexeme.matched_string}({",".join(str(arg) for arg in self.arguments)})'
@dataclass(frozen=True) @dataclass(frozen=True)
class IRVar: class IRVar:
"""
A variable which may be substituted for any other term
"""
lexeme: Lexeme[Tok] lexeme: Lexeme[Tok]
def __str__(self) -> str: def __str__(self) -> str:
return f'*{self.lexeme.matched_string}' return f'*{self.lexeme.matched_string}'
@dataclass(frozen=True) @dataclass(frozen=True)
class IRNeg: class IRNeg:
"""
A negated proposition
"""
inner: 'IRTerm' inner: 'IRTerm'
def __str__(self) -> str: def __str__(self) -> str:
return f'¬{self.inner}' return f'¬{self.inner}'