package lrs.visitor; import lrs.*; public class ToString implements IAlgo { public static final ToString Singleton = new ToString (); private ToString () { } /** * @param host empty * @param input not used * @return */ public Object forEmpty(LRStruct host, Object input) { return "()"; } /** * Uses an anonymous inner class helper. * @param host not empty * @param input not used. * @return */ public Object forNonEmpty(LRStruct host, Object input) { return "(" + host.getFirst() + host.getRest().execute ( new IAlgo () { public Object forEmpty(LRStruct h, Object inp) { return ")"; } public Object forNonEmpty (LRStruct h, Object inp) { return " " + h.getFirst() + h.getRest ().execute (this, null); } } , null); } }