spiglet.visitor
Class SpigletFormatter

java.lang.Object
  extended by spiglet.visitor.DepthFirstVisitor
      extended by spiglet.visitor.TreeFormatter
          extended by spiglet.visitor.SpigletFormatter
All Implemented Interfaces:
Visitor

public class SpigletFormatter
extends TreeFormatter

A pretty printer visitor designed to be used together with TreeDumper to generate a formatted string that is the Spiglet code. Based on the PigletFormatter, in the homework's website.

Author:
Jens Palsberg
See Also:
TreeDumper

Constructor Summary
SpigletFormatter()
           
 
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" simpleExp -> SimpleExp() nodeToken1 -> "(" nodeListOptional -> ( Temp() )* 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" simpleExp -> SimpleExp() nodeToken2 -> "END"
 
Methods inherited from class spiglet.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
 
Methods inherited from class spiglet.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

SpigletFormatter

public SpigletFormatter()
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"
 simpleExp -> SimpleExp()
 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"
 simpleExp -> SimpleExp()
 nodeToken1 -> "("
 nodeListOptional -> ( Temp() )*
 nodeToken2 -> ")"
 

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