!759 !include #1003145 // Puzzler for Bubblesort !include #1003146 // HighLevel static int[] makeProgram(int startAddress) { S code = new Puzzler("0 10 i j for for ifless swap").code(); HighLevel h = new HighLevel(startAddress); compile(code, h); ret h.getProgram(); } static void compile(S code, HighLevel h) { new L stack; new Matches m; for (S line : toLinesFullTrim(code)) { if (flexMatch("if * < * then", line)) { stack.add(h.new IfLess(m.get(0), m.get(1))); } else if (flexMatch("for * = * to *-1", line, m)) { // push for int var = h.getvar(m.get(0)); h.set(var, m.get(1)); stack.add(h.new ForIm(var, parseInt(m.get(2)))); } else if (flexMatch("end", line)) { O x = liftLast(stack); call(x, "end"); } else if (flexMatch("swap(*, *)", line)) { h.swap(m.get(0), m.get(1)); } else fail("bad instruction: " + line); } }