feat: Atomic & Compound parsen
This commit is contained in:
parent
e1763e0510
commit
973365e2ec
2 changed files with 22 additions and 1 deletions
|
@ -63,6 +63,8 @@ open class Preprocessor {
|
||||||
Functor.of("functor/3") -> FunctorOp(args[0], args[1], args[2])
|
Functor.of("functor/3") -> FunctorOp(args[0], args[1], args[2])
|
||||||
Functor.of("arg/3") -> Arg(args[0], args[1], args[2])
|
Functor.of("arg/3") -> Arg(args[0], args[1], args[2])
|
||||||
Functor.of("clause/2") -> ClauseOp(args[0] as Head, args[1] as Body)
|
Functor.of("clause/2") -> ClauseOp(args[0] as Head, args[1] as Body)
|
||||||
|
Functor.of("atomic/1") -> AtomicOp(args[0])
|
||||||
|
Functor.of("compound/1") -> CompoundOp(args[0])
|
||||||
|
|
||||||
// Arithmetic
|
// Arithmetic
|
||||||
Functor.of("inf/0") -> Integer(Int.MAX_VALUE)
|
Functor.of("inf/0") -> Integer(Int.MAX_VALUE)
|
||||||
|
@ -111,7 +113,6 @@ open class Preprocessor {
|
||||||
Functor.of("!/0") -> Cut()
|
Functor.of("!/0") -> Cut()
|
||||||
Functor.of(",/2") -> Conjunction(args[0] as LogicOperand, args[1] as LogicOperand)
|
Functor.of(",/2") -> Conjunction(args[0] as LogicOperand, args[1] as LogicOperand)
|
||||||
Functor.of(";/2") -> Disjunction(args[0] as LogicOperand, args[1] as LogicOperand)
|
Functor.of(";/2") -> Disjunction(args[0] as LogicOperand, args[1] as LogicOperand)
|
||||||
Functor.of("|/2") -> Bar(args[0] as LogicOperand, args[1] as LogicOperand)
|
|
||||||
Functor.of("\\+/1") -> Not(args[0] as Goal)
|
Functor.of("\\+/1") -> Not(args[0] as Goal)
|
||||||
|
|
||||||
// Database
|
// Database
|
||||||
|
|
|
@ -137,3 +137,23 @@ class ClauseOp(private val head: Head, private val body: Body) :
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class AtomicOp(private val term: Term) : Operator(Atom("atomic"), null, term) {
|
||||||
|
override fun satisfy(subs: Substitutions): Answers {
|
||||||
|
return if (atomic(term, subs)) {
|
||||||
|
sequenceOf(Result.success(emptyMap()))
|
||||||
|
} else {
|
||||||
|
emptySequence()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class CompoundOp(private val term: Term) : Operator(Atom("compound"), null, term) {
|
||||||
|
override fun satisfy(subs: Substitutions): Answers {
|
||||||
|
return if (compound(term, subs)) {
|
||||||
|
sequenceOf(Result.success(emptyMap()))
|
||||||
|
} else {
|
||||||
|
emptySequence()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Reference in a new issue