/* * Main.java * * Created on February 9, 2007, 1:04 AM * * Edward Martin * Verify That All Parentheses match * accepts input on stdin, will exit when it hits a \n */ package verifyparen; import java.io.IOException; public class Main { public static void main(String[] args) { char[] app =(">>[-]>[-]+>++++++++++[-<+++<+++>>]<<<,----------[[->>>>+>+>>+<<"+ "<<<<<]>>>>>[-<<<<<+>>>>>]<<<<[->>>>+>+>>+<<<<<<<]>>>>>[-<<<<<+>"+ ">>>>]<<<<<>>>[>[->+<]<[-]]>[-]<>>[[-]>->-[->+<<<<<+>>>>]>[-<+>]"+ "<<[->>+<<<<+>>]>>[-<<+>>]<<<<<[>[->+<]<[-]]>[-]>]>[-<+>]>[-<<+>"+ ">]<<<<+>>[<<->>[-]]>[-]>[-]<<<<[[-]<<<<<+>>>>>]<<<<[->>>>+>+>>+"+ "<<<<<<<]>>>>>[-<<<<<+>>>>>]<<<[->>>+>+>>+<<<<<<]>>>>[-<<<<+>>>>"+ "]<<<<<>>>[>[->+<]<[-]]>[-]<>>[[-]>->-[->+<<<<<+>>>>]>[-<+>]<<[-"+ ">>+<<<<+>>]>>[-<<+>>]<<<<<[>[->+<]<[-]]>[-]>]>[-<+>]>[-<<+>>]<<"+ "<<+>>[<<->>[-]]>[-]>[-]<<<<[[-]<<<<<[->>>>>+>+<<<<<<]>>>>>>[-<<"+ "<<<<+>>>>>>]<<+>[[-]<->]<<<<<->>>>>]+<[[-]>-<]><<<<[-]>>>>[[-]<"+ "<<<,---------->>>>]<<<<]<[[-]>>>>>>[-]++++++++++[<+++++++>-]<++"+ "++++++.>++++++++++[<+++>-]<+++.+++++.[-]>+++++[<+++++++++>-]<.<"+ "<<<<]>>>>>[-]>[-]++++++++[<+++++++++++>-]<--.>++[<+++++>-]<+.>+"+ "+[<+++++>-]<+.---.-----.").toCharArray(); byte[] memory = new byte [30000]; int pos = 0;//memory pointer int pc = 0;//program pointer try { while (true){ if (pc >= app.length){break;} switch (app[pc]){ case '>':pos++;break; case '<':pos--;break; case '+':memory[pos]++;break; case '-':memory[pos]--;break; case '.':System.out.write(memory[pos]);break; case ',':memory[pos] = (byte)System.in.read();break; case '[': if (memory[pos] == 0){ int bCounter = 0; cBracketSearch: while (true){ pc++; switch (app[pc]){ case '[':bCounter++;break; case ']': if (bCounter == 0){ break cBracketSearch; } bCounter--;}}} break; case ']': if (memory[pos] != 0){ int bCounter = 0; oBracketSearch: while (true){ pc--; switch (app[pc]){ case ']': bCounter++; break; case '[': if (bCounter == 0){ break oBracketSearch; } bCounter--;}}}} pc++;} } catch (IOException e){e.printStackTrace();}System.out.flush();}}