Initial revision
import java.io.*; public class LispToSkeleton{ final static boolean debug=false; public static int[] lispToIntArray(LispObject l) throws LispException{ int i,len=l.length(); int[] array=new int[len]; for(i=0;i<len;i++,l=l.cdr()){ array[i]=l.car().getInteger(); } return array; } public static Point lispToPoint(LispObject l) throws LispException{ if(debug) System.out.println("lispToPoint("+l+")"); return new Point(l.car().getInteger(),l.cdr().car().getInteger()); } public static Point[] lispToPoints(LispObject l) throws LispException{ if(debug) System.out.println("lispToPoints("+l+")"); int len=l.length(); Point[] points=new Point[len]; int i; for(i=0;i<len;i++,l=l.cdr()){ points[i]=lispToPoint(l.car()); } return points; } public static Element lispToElement(LispObject l) throws LispException{ if(debug) System.out.println("lispToElement("+l+")"); Symbol tagSymbol=(Symbol)l.car(); int type=Element.stringToType(tagSymbol.getName()); if(type== -1){ System.err.println("Illegal tag"+tagSymbol.getName()); } l=l.cdr(); int[] points=lispToIntArray(l.car()); l=l.cdr(); return new Element(type,points,null,null); } public static Element[] lispToElements(LispObject l) throws LispException{ if(debug) System.out.println("lispToElements("+l+")"); int len=l.length(); Element[] elements=new Element[len]; int i; for(i=0;i<len;i++,l=l.cdr()){ elements[i]=lispToElement(l.car()); } return elements; } public static Annotation[] lispToAnnotations(LispObject l) throws LispException{ return null; } public static Skeleton lispToSkeleton(LispObject l) throws LispException{ return new Skeleton(lispToPoints(l.car()), lispToElements(l.cdr().car()), lispToAnnotations(l.cdr().cdr())); } public static void main(String args[]) throws IOException,LispException{ LispInputStream lis; if(args.length>0) lis=new LispInputStream(new FileReader(args[0])); else lis=new LispInputStream(new InputStreamReader(System.in)); LispObject lo=null; while((lo=lis.nextObject())!=null){ // System.out.println(lo); if(lo.getType()==LispObject.CONS && lo.car().getName().equals("setq")){ Skeleton skel=LispToSkeleton.lispToSkeleton(lo.cdr().cdr().car().cdr().car()); System.out.println(skel); } } } }
ktanaka Powered by ViewCVS 1.0-dev |
ViewCVS and CVS Help |