Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * 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
  * 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.wam.compiler;
BuiltInTransformVisitor should be used with a depth first positional walk over a term to compile. On leaving each term, that is in a post-fix order, if the term is a functor, the built-in transformation function is applied to it. If the built-in applies a transformation to a functor, it is substituted within its parent for the built-in.

CRC Card
Responsibilities Collaborations
Substitute built-ins into a term to compile.

Rupert Smith
Used for debugging.
     /* private static final Logger log = Logger.getLogger(BuiltInTransformVisitor.class.getName()); */

Holds the built in transformation function.
     private final BuiltInTransform builtInTransform;

Creates the visitor with the supplied interner, symbol table and traverser.

interner The name interner.
symbolTable The compiler symbol table.
traverser The positional context traverser.
builtInTransform The built-in transformation function.
         PositionalTermTraverser traverserBuiltInTransform builtInTransform)
         this. = builtInTransform;

     public void setPositionalTraverser(PositionalTermTraverser traverser)
         this. = traverser;

Applies the built-in transform during a post-fix visit of a term.

functor The functor to visit.
     protected void leaveFunctor(Functor functor)
         int pos = .getPosition();
         if (!.isInHead() && (pos >= 0))
             Functor transformed = .apply(functor);
             if (functor != transformed)
                 /*log.fine("Transformed: " + functor + " to " + transformed.getClass());*/
                 BuiltInFunctor builtInFunctor = (BuiltInFunctortransformed;
                 Term parentTerm = .getParentContext().getTerm();
                 if (parentTerm instanceof Clause)
                     Clause parentClause = (ClauseparentTerm;
                     parentClause.getBody()[pos] = builtInFunctor;
                 else if (parentTerm instanceof Functor)
                    Functor parentFunctor = (FunctorparentTerm;
                    parentFunctor.getArguments()[pos] = builtInFunctor;
New to GrepCode? Check out our FAQ X