Compare commits

..

2 commits

Author SHA1 Message Date
973365e2ec
feat: Atomic & Compound parsen 2025-05-08 09:35:49 +02:00
e1763e0510
fix: Repl ook enter duwen 2025-05-08 09:34:05 +02:00
3 changed files with 30 additions and 2 deletions

View file

@ -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

View file

@ -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()
}
}
}

View file

@ -55,7 +55,14 @@ class Repl {
} }
} }
"a" -> return "" -> {
io.checkNewLine()
return
}
"a" -> {
io.checkNewLine()
return
}
"." -> { "." -> {
io.checkNewLine() io.checkNewLine()
return return