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
   *
   *     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.wam.printer;
 
SourceClausePrinter prints the source of a compiled clause in a vertically spread out way, so that each predicate call and argument appears in its own row. This leaves enough space vertically to print the compiled byte code alongside.

CRC Card
Responsibilities Collaborations
Print each predicate call and argument in its own row.

Author(s):
Rupert Smith
 
 public class SourceClausePrinter extends BasePrinter
 {
    
Creates a printer.

Parameters:
interner The name interner.
symbolTable The compiler symbol table.
traverser The positional context traverser.
column The column to print to.
table The table to inform of cell sizes and positions.
 
     public SourceClausePrinter(VariableAndFunctorInterner internerSymbolTable<IntegerStringObjectsymbolTable,
         PositionalTermTraverser traverserint columnTextTableModel table)
     {
         super(internersymbolTabletraversercolumntable);
     }

    
 
     protected void enterFunctor(Functor functor)
     {
         String showContextAs = .getFunctorName(functor) + (functor.isAtom() ? "" : "(");
 
         int delta = showContextAs.length();
 
         addLineToRow( + showContextAs);
         nextRow();
 
          = .generateTraceIndent(delta);
     }

    
 
     protected void leaveFunctor(Functor functor)
     {
         String toAppend = ;
         boolean addData = false;
 
         if (functor.isCompound())
         {
             toAppend += ")";
             addData = true;
         }
 
         if (!.isInHead() && !.isLastBodyFunctor() && .isTopLevel())
         {
             toAppend += ",";
             addData = true;
         }
 
         if (.isInHead() && .isTopLevel())
         {
             toAppend += " :-";
             addData = true;
         }
 
         if (addData)
         {
             addLineToRow(toAppend);
             nextRow();
         }
 
     }

    
    protected void enterVariable(Variable variable)
    {
        String showContextAs = .getVariableName(variable);
        int delta = showContextAs.length();
        addLineToRow( + showContextAs);
        nextRow();
         = .generateTraceIndent(delta);
    }
New to GrepCode? Check out our FAQ X