Revision Log
Revision: 1.2 - (view) (download) (as text)
| 1 : | ktanaka | 1.1 | import java.io.*; |
| 2 : | public class LispToSkeleton{ | ||
| 3 : | final static boolean debug=false; | ||
| 4 : | public static int[] lispToIntArray(LispObject l) throws LispException{ | ||
| 5 : | int i,len=l.length(); | ||
| 6 : | int[] array=new int[len]; | ||
| 7 : | for(i=0;i<len;i++,l=l.cdr()){ | ||
| 8 : | array[i]=l.car().getInteger(); | ||
| 9 : | } | ||
| 10 : | return array; | ||
| 11 : | } | ||
| 12 : | public static Point lispToPoint(LispObject l) throws LispException{ | ||
| 13 : | if(debug) | ||
| 14 : | System.out.println("lispToPoint("+l+")"); | ||
| 15 : | return new Point(l.car().getInteger(),l.cdr().car().getInteger()); | ||
| 16 : | } | ||
| 17 : | public static Point[] lispToPoints(LispObject l) throws LispException{ | ||
| 18 : | if(debug) | ||
| 19 : | System.out.println("lispToPoints("+l+")"); | ||
| 20 : | int len=l.length(); | ||
| 21 : | Point[] points=new Point[len]; | ||
| 22 : | int i; | ||
| 23 : | for(i=0;i<len;i++,l=l.cdr()){ | ||
| 24 : | points[i]=lispToPoint(l.car()); | ||
| 25 : | } | ||
| 26 : | return points; | ||
| 27 : | } | ||
| 28 : | public static Element lispToElement(LispObject l) throws LispException{ | ||
| 29 : | if(debug) | ||
| 30 : | System.out.println("lispToElement("+l+")"); | ||
| 31 : | Symbol tagSymbol=(Symbol)l.car(); | ||
| 32 : | int type=Element.stringToType(tagSymbol.getName()); | ||
| 33 : | if(type== -1){ | ||
| 34 : | System.err.println("Illegal tag"+tagSymbol.getName()); | ||
| 35 : | } | ||
| 36 : | l=l.cdr(); | ||
| 37 : | int[] points=lispToIntArray(l.car()); | ||
| 38 : | l=l.cdr(); | ||
| 39 : | |||
| 40 : | return new Element(type,points,null,null); | ||
| 41 : | } | ||
| 42 : | public static Element[] lispToElements(LispObject l) throws LispException{ | ||
| 43 : | if(debug) | ||
| 44 : | System.out.println("lispToElements("+l+")"); | ||
| 45 : | int len=l.length(); | ||
| 46 : | Element[] elements=new Element[len]; | ||
| 47 : | int i; | ||
| 48 : | for(i=0;i<len;i++,l=l.cdr()){ | ||
| 49 : | elements[i]=lispToElement(l.car()); | ||
| 50 : | } | ||
| 51 : | return elements; | ||
| 52 : | } | ||
| 53 : | public static Annotation[] lispToAnnotations(LispObject l) throws LispException{ | ||
| 54 : | return null; | ||
| 55 : | } | ||
| 56 : | public static Skeleton lispToSkeleton(LispObject l) throws LispException{ | ||
| 57 : | return new Skeleton(lispToPoints(l.car()), | ||
| 58 : | lispToElements(l.cdr().car()), | ||
| 59 : | lispToAnnotations(l.cdr().cdr())); | ||
| 60 : | } | ||
| 61 : | public static void main(String args[]) throws IOException,LispException{ | ||
| 62 : | LispInputStream lis; | ||
| 63 : | if(args.length>0) | ||
| 64 : | lis=new LispInputStream(new FileReader(args[0])); | ||
| 65 : | else | ||
| 66 : | lis=new LispInputStream(new InputStreamReader(System.in)); | ||
| 67 : | LispObject lo=null; | ||
| 68 : | while((lo=lis.nextObject())!=null){ | ||
| 69 : | ktanaka | 1.2 | System.out.println(lo); |
| 70 : | ktanaka | 1.1 | if(lo.getType()==LispObject.CONS && lo.car().getName().equals("setq")){ |
| 71 : | Skeleton skel=LispToSkeleton.lispToSkeleton(lo.cdr().cdr().car().cdr().car()); | ||
| 72 : | System.out.println(skel); | ||
| 73 : | } | ||
| 74 : | } | ||
| 75 : | } | ||
| 76 : | } |
|
ktanaka Powered by ViewCVS 1.0-dev |
ViewCVS and CVS Help |