kanga.visitor
Class KangaFormatter

java.lang.Object
  extended by kanga.visitor.DepthFirstVisitor
      extended by kanga.visitor.TreeFormatter
          extended by kanga.visitor.KangaFormatter
All Implemented Interfaces:
Visitor

public class KangaFormatter
extends TreeFormatter

A pretty printer visitor designed to be used together with TreeDumper to generate a formatted string that is the Kanga code. Taken from here, in the homework's website.

Author:
Jens Palsberg
See Also:
TreeDumper

Constructor Summary
KangaFormatter()
           
 
Method Summary
protected  void processList(NodeListInterface n)
          Accepts a NodeListInterface object and performs an optional format command between each node in the list (but not after the last node).
 void visit(Goal n)
           nodeToken -> "MAIN" nodeToken1 -> "[" integerLiteral -> IntegerLiteral() nodeToken2 -> "]" nodeToken3 -> "[" integerLiteral1 -> IntegerLiteral() nodeToken4 -> "]" nodeToken5 -> "[" integerLiteral2 -> IntegerLiteral() nodeToken6 -> "]" stmtList -> StmtList() nodeToken7 -> "END" nodeListOptional -> ( Procedure() )* nodeToken8 -> <EOF>
 void visit(NodeToken n)
          Executes the commands waiting in the command queue, then inserts the proper location information into the current NodeToken.
 void visit(Procedure n)
           label -> Label() nodeToken -> "[" integerLiteral -> IntegerLiteral() nodeToken1 -> "]" nodeToken2 -> "[" integerLiteral1 -> IntegerLiteral() nodeToken3 -> "]" nodeToken4 -> "[" integerLiteral2 -> IntegerLiteral() nodeToken5 -> "]" stmtList -> StmtList() nodeToken6 -> "END"
 
Methods inherited from class kanga.visitor.TreeFormatter
add, force, force, indent, indent, outdent, outdent, processList, space, space, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit
 
Methods inherited from class kanga.visitor.DepthFirstVisitor
visit, visit, visit, visit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KangaFormatter

public KangaFormatter()
Method Detail

processList

protected void processList(NodeListInterface n)
Description copied from class: TreeFormatter
Accepts a NodeListInterface object and performs an optional format command between each node in the list (but not after the last node).

Overrides:
processList in class TreeFormatter

visit

public void visit(NodeToken n)
Description copied from class: TreeFormatter
Executes the commands waiting in the command queue, then inserts the proper location information into the current NodeToken. If there are any special tokens preceding this token, they will be given the current location information. The token will follow on the next line, at the proper indentation level. If this is not the behavior you want from special tokens, feel free to modify this method.

Specified by:
visit in interface Visitor
Overrides:
visit in class TreeFormatter

visit

public void visit(Goal n)
Description copied from class: TreeFormatter
 nodeToken -> "MAIN"
 nodeToken1 -> "["
 integerLiteral -> IntegerLiteral()
 nodeToken2 -> "]"
 nodeToken3 -> "["
 integerLiteral1 -> IntegerLiteral()
 nodeToken4 -> "]"
 nodeToken5 -> "["
 integerLiteral2 -> IntegerLiteral()
 nodeToken6 -> "]"
 stmtList -> StmtList()
 nodeToken7 -> "END"
 nodeListOptional -> ( Procedure() )*
 nodeToken8 -> <EOF>
 

Specified by:
visit in interface Visitor
Overrides:
visit in class TreeFormatter

visit

public void visit(Procedure n)
Description copied from class: TreeFormatter
 label -> Label()
 nodeToken -> "["
 integerLiteral -> IntegerLiteral()
 nodeToken1 -> "]"
 nodeToken2 -> "["
 integerLiteral1 -> IntegerLiteral()
 nodeToken3 -> "]"
 nodeToken4 -> "["
 integerLiteral2 -> IntegerLiteral()
 nodeToken5 -> "]"
 stmtList -> StmtList()
 nodeToken6 -> "END"
 

Specified by:
visit in interface Visitor
Overrides:
visit in class TreeFormatter