@@ -0,0 +1,1155 @@
+import java.util.ArrayList;%0Aimport java.util.Formatter;%0Aimport java.util.List;%0A%0Apublic class SprintfFun extends BuiltinFun %7B%0A%09private Formatter formatter = new Formatter();// .format(format,%0A%09%09%09%09%09%09%09%09%09%09%09%09%09// args).toString(%0A%0A%09public SprintfFun() %7B%0A%09%09super(%22sprintf%22, -1);// ignore param's count%0A%09%7D%0A%0A%09@Override%0A%09public Value apply(List%3CValue%3E args) %7B%0A%09%09if (args.size() == 0)%0A%09%09%09S.error(this + %22%E5%BF%85%E9%A1%BB%E8%87%B3%E5%B0%91%E6%9C%89%E4%B8%80%E4%B8%AA%E5%8F%82%E6%95%B0%22);%0A%09%09if (!(args.get(0) instanceof StringValue)) %7B%0A%09%09%09S.error(this + %22%E7%AC%AC%E4%B8%80%E4%B8%AA%E5%8F%82%E6%95%B0%E5%BF%85%E9%A1%BB%E6%98%AFString%22 + args);%0A%09%09%7D%0A%09%09ArrayList%3CObject%3E varargs = new ArrayList%3C%3E(args.size());%0A%09%09%0A%09%09for (int i = 1; i %3C args.size(); i++) %7B%0A%09%09%09Value v = args.get(i);%0A%09%09%09if (v instanceof IntValue) %7B%0A%09%09%09%09varargs.add(((IntValue) v).value);%0A%09%09%09%7D else if (v instanceof FloatValue) %7B%0A%09%09%09%09varargs.add(((FloatValue) v).value);%0A%09%09%09%7D else if (v instanceof StringValue) %7B%0A%09%09%09%09varargs.add(((StringValue) v).value);%0A%09%09%09%7D else%0A%09%09%09%09S.error(this + %22%E6%A0%BC%E5%BC%8F%E5%8C%96%E5%8F%82%E6%95%B0%E5%BF%85%E9%A1%BB%E6%98%AF%EF%BC%9Aint%E3%80%81float%E5%92%8CString%22);%0A%09%09%7D%0A%09%09String s = formatter.format(args.get(0).toString(), varargs.toArray()).toString();%0A%09%09return new StringValue(s);%0A%09%7D%0A%0A%09public static void main(String%5B%5D args) %7B%0A%09%09System.out.printf(%22%25d%5Cn%22, (Object) Integer.valueOf(10));%0A%09%7D%0A%7D%0A

add sprintf: format string