simple.visitor
Class PostfixPrinter

java.lang.Object
  extended by simple.visitor.PostfixPrinter
All Implemented Interfaces:
Visitor

public class PostfixPrinter
extends java.lang.Object
implements Visitor

This class implements the Visitor interface that is able to traverse the parse tree of an expression. When given the root of such tree, this visitor outputs the expression tree in postfix string version. For example, the expression (1 + 2) * (3 / 4) will output "1 2 + 3 4 / *".

Author:
santa
See Also:
Visitor

Constructor Summary
PostfixPrinter(Stmt s)
          Creates a printer object, passing a Stmt node that represents the root of the parse tree to be traversed.
 
Method Summary
 java.lang.String postfixPrint()
          Traverses the tree to build the postfix string and returns it.
 void visit(Expr e)
           
 void visit(ExprP e)
           
 void visit(Fact e)
           
 void visit(NumFact e)
           
 void visit(ParenFact e)
           
 void visit(ParseNode e)
           
 void visit(Stmt e)
           
 void visit(Term e)
           
 void visit(TermP e)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PostfixPrinter

public PostfixPrinter(Stmt s)
Creates a printer object, passing a Stmt node that represents the root of the parse tree to be traversed.

Parameters:
s - the root node of the parse tree
Method Detail

visit

public void visit(ParseNode e)
Specified by:
visit in interface Visitor

visit

public void visit(Expr e)
Specified by:
visit in interface Visitor

visit

public void visit(ExprP e)
Specified by:
visit in interface Visitor

visit

public void visit(Fact e)
Specified by:
visit in interface Visitor

visit

public void visit(NumFact e)
Specified by:
visit in interface Visitor

visit

public void visit(ParenFact e)
Specified by:
visit in interface Visitor

visit

public void visit(Stmt e)
Specified by:
visit in interface Visitor

visit

public void visit(Term e)
Specified by:
visit in interface Visitor

visit

public void visit(TermP e)
Specified by:
visit in interface Visitor

postfixPrint

public java.lang.String postfixPrint()
Traverses the tree to build the postfix string and returns it.

Returns:
the postfix string of the expression tree