1 package net.sf.yacas; 2 3 import java.io.Writer; 4 5 6 class LispPrinter 7 { Print(LispPtr aExpression, Writer aOutput, LispEnvironment aEnvironment)8 public void Print(LispPtr aExpression, Writer aOutput, LispEnvironment aEnvironment) throws Exception 9 { 10 PrintExpression(aExpression, aOutput, aEnvironment,0); 11 } RememberLastChar(char aChar)12 public void RememberLastChar(char aChar) 13 { 14 } 15 PrintExpression(LispPtr aExpression, Writer aOutput, LispEnvironment aEnvironment,int aDepth )16 void PrintExpression(LispPtr aExpression, Writer aOutput, 17 LispEnvironment aEnvironment,int aDepth /* =0 */) throws Exception 18 { 19 LispPtr iter = new LispPtr(); 20 iter.Set(aExpression.Get()); 21 int item = 0; 22 while (iter.Get() != null) 23 { 24 // if String not null pointer: print string 25 String string = iter.Get().String(); 26 27 if (string != null) 28 { 29 aOutput.write(string); 30 aOutput.write(" "); 31 } 32 // else print "(", print sublist, and print ")" 33 else if (iter.Get().SubList() != null) 34 { 35 if (item != 0) 36 { 37 Indent(aOutput,aDepth+1); 38 } 39 aOutput.write("("); 40 PrintExpression((iter.Get().SubList()),aOutput, aEnvironment,aDepth+1); 41 aOutput.write(")"); 42 item=0; 43 } 44 else 45 { 46 aOutput.write("[GenericObject]"); 47 } 48 iter = (iter.Get().Next()); 49 item++; 50 } // print next element 51 } 52 Indent(Writer aOutput, int aDepth)53 void Indent(Writer aOutput, int aDepth) throws Exception { 54 aOutput.write("\n"); 55 int i; 56 for (i = aDepth; i > 0; i--) { 57 aOutput.write(" "); 58 } 59 } 60 } 61