piglet.visitor
Class PigletFormatter

java.lang.Object
  extended by piglet.visitor.DepthFirstVisitor
      extended by piglet.visitor.TreeFormatter
          extended by piglet.visitor.PigletFormatter
All Implemented Interfaces:
Visitor

public class PigletFormatter
extends TreeFormatter

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

Author:
Jens Palsberg
See Also:
TreeDumper

Constructor Summary
PigletFormatter()
           
 
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(Call n)
           nodeToken -> "CALL" exp -> Exp() nodeToken1 -> "(" nodeListOptional -> ( Exp() )* nodeToken2 -> ")"
 void visit(Goal n)
           nodeToken -> "MAIN" stmtList -> StmtList() nodeToken1 -> "END" nodeListOptional -> ( Procedure() )* nodeToken2 -> <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 -> "]" stmtExp -> StmtExp()
 void visit(StmtExp n)
           nodeToken -> "BEGIN" stmtList -> StmtList() nodeToken1 -> "RETURN" exp -> Exp() nodeToken2 -> "END"
 
Methods inherited from class piglet.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
 
Methods inherited from class piglet.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

PigletFormatter

public PigletFormatter()
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"
 stmtList -> StmtList()
 nodeToken1 -> "END"
 nodeListOptional -> ( Procedure() )*
 nodeToken2 -> <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 -> "]"
 stmtExp -> StmtExp()
 

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

visit

public void visit(StmtExp n)
Description copied from class: TreeFormatter
 nodeToken -> "BEGIN"
 stmtList -> StmtList()
 nodeToken1 -> "RETURN"
 exp -> Exp()
 nodeToken2 -> "END"
 

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

visit

public void visit(Call n)
Description copied from class: TreeFormatter
 nodeToken -> "CALL"
 exp -> Exp()
 nodeToken1 -> "("
 nodeListOptional -> ( Exp() )*
 nodeToken2 -> ")"
 

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