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;
import static com.thesett.aima.logic.fol.wam.compiler.WAMInstruction.STACK_ADDR;
PositionPrinter prints some positional context information about functors and how they relate to their compiled form. The position printer will prints the name of the functor, argument or variable and whether the current position is within the functor head or last body element.

CRC Card
Responsibilities Collaborations
Print the positional context information.

Author(s):
Rupert Smith
public class PositionPrinter 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 PositionPrinter(VariableAndFunctorInterner internerSymbolTable<IntegerStringObjectsymbolTable,
        PositionalTermTraverser traverserint columnTextTableModel table)
    {
        super(internersymbolTabletraversercolumntable);
    }

    
    protected void enterFunctor(Functor functor)
    {
        String head = .isInHead() ? "/head" : "";
        String last = .isLastBodyFunctor() ? "/last" : "";
        String symKey = functor.getSymbolKey().toString();
        if (.isTopLevel())
        {
            addLineToRow("functor(" + symKey + ")" + head + last);
        }
        else
        {
            addLineToRow("arg(" + symKey + ")");
        }
        nextRow();
    }

    
    protected void leaveFunctor(Functor functor)
    {
        nextRow();
    }

    
    protected void enterVariable(Variable variable)
    {
        Integer allocation = (Integer.get(variable.getSymbolKey(), "allocation");
        String symKey = variable.getSymbolKey().toString();
        String allocString = "";
        if (allocation != null)
        {
            int slot = (allocation & (0xff));
            int mode = allocation >> 8;
            allocString = ((mode == ) ? "Y" : "X") + slot;
        }
        addLineToRow("arg/var(" + symKey + ") " + allocString);
        nextRow();
    }
New to GrepCode? Check out our FAQ X