
com.thesett.aima.logic.fol.prolog.PrologCompiler Maven / Gradle / Ivy
/*
* Copyright The Sett Ltd, 2005 to 2014.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.thesett.aima.logic.fol.prolog;
import com.thesett.aima.logic.fol.Clause;
import com.thesett.aima.logic.fol.LogicCompiler;
import com.thesett.aima.logic.fol.LogicCompilerObserver;
import com.thesett.aima.logic.fol.Sentence;
import com.thesett.aima.logic.fol.TermTransformer;
import com.thesett.aima.logic.fol.VariableAndFunctorInterner;
import com.thesett.aima.logic.fol.prolog.expressions.BuiltInExpressionTransform;
import com.thesett.common.parsing.SourceCodeException;
/**
* PrologCompiler implements a translation from {@link Clause}s to {@link PrologCompiledClause}s.
*
* This compiler translates all free variables in domain clauses into {@link StackVariable}s with assigned storage
* locations relative to a stack frame. The clause is then set up as the binding context supplier to the variable. When
* evaluating against a clause a binding context accepting stack variables needs to be set up on it, binding stack
* variables will then defer the storage of their bindings onto the stack frame location rather than the variable
* itself. This means that the domain clause can have variable bindings relative to a particular stack frame, and
* evaluating the domain clause in a different stack frame context will allow a different binding of its variables.
*
* The compiler also replaces any occurences of built-in expressions with their implementations.
*
* Query clauses are not transformed with stack variables. There is only one query at the top level of any execution
* chain, so it does not need to be re-used in the way that domain clauses do.
*
*
CRC Card
* Responsibilities Collaborations
* Assign stack frame storage locations for variables.
* {@link StackVariable}, {@link StackVariableTransform}.
* Replace built in expressions with their implementations.
* {@link BuiltInExpressionTransform}.
*
*
* @author Rupert Smith
*/
public class PrologCompiler implements LogicCompiler© 2015 - 2025 Weber Informatics LLC | Privacy Policy