/*
Created 24 Jul 2009 - Richard Morris
*/
package com.singularsys.jep.walkers;
import java.io.PrintStream;
import com.singularsys.jep.JepException;
import com.singularsys.jep.parser.ASTConstant;
import com.singularsys.jep.parser.ASTFunNode;
import com.singularsys.jep.parser.ASTOpNode;
import com.singularsys.jep.parser.ASTVarNode;
import com.singularsys.jep.parser.Node;
public class PostfixTreeDumper extends PostfixTreeWalker {
public static final boolean DETAILED=false;
public static final boolean PRINT_DEPTH=false;
PrintStream out=null;
public PostfixTreeDumper() {out = System.out;}
public PostfixTreeDumper(PrintStream stream) {out=stream;}
public void dump(Node node) throws JepException {
walk(node);
}
@Override
protected void visit(ASTFunNode node, int nchildren, int depth)
throws JepException {
output(node,depth);
}
@Override
protected void visit(ASTOpNode node, int nchildren, int depth)
throws JepException {
output(node,depth);
}
@Override
protected void visit(ASTVarNode node, int nchildren, int depth)
throws JepException {
output(node,depth);
}
@Override
protected void visit(ASTConstant node, int nchildren, int depth)
throws JepException {
output(node,depth);
}
protected void output(Node n, int depth) {
// create the indentation with 'depth' number of spaces
if(PRINT_DEPTH)
for(int i=0;i<depth;++i)
out.print(' ');
// print the node info
if(DETAILED)
{
out.println(n);
}
else {
if(n instanceof ASTConstant) {
out.println(n.getValue());
}
else
out.println(n.getName());
}
}
}
--
Richard Morris
Web: www.singsurf.org www.pfaf.org
Email: ri...@singsurf.org
Tel: (+44) 01208 872963
Post: 1 Lerryn View, Lerryn, Lostwithiel, Cornwall, PL22 0QJ