Compiler : Finite State Machine code sample
Sample 0 : import java.io.*; import java.util.*; /* String containing an even number of one 0 1 ------------ A* A B B B A ------------ */ public class FSM { final static int STATES=2, INPUTS=2; public static void main (String[] args) throws IOException{ boolean [] accept = new boolean[STATES]; int [][] fsm = new int[STATES][INPUTS]; accept[0] = true; accept[1] = false; fsm[0][0] = 0; fsm[0][1] = 1; fsm[1][0] = 1; fsm[1][1] = 0; // State A = 0, State B = 1 int inp = 0; int state = 0; try{ inp = System.in.read() - '0'; while(inp >= 0 && inp < INPUTS){ state = fsm[state][inp]; inp = System.in.read() - '0'; } } catch(IOException ioe){ System.out.println("IO error " + ioe); }