var table=[ ['q0','0','1','R','q1'], ['q1','1','1','R','q1'], ['q1','0','0','S','q2'], ['q2','0','1','R','q3'], ['q3',nil,nil,'S','q3'] ]; var operand={ new:func(symbol,changed_symbol,move,next_state){ if(move!='L' and move!='R' and move!='S') die("invalid move type:"+move); return { symbol:symbol, changed_symbol:changed_symbol, move:move, next_state:next_state }; } }; var machine={ states:{}, add:func(state,operand){ if(!contains(me.states,state)) me.states[state]=[operand]; else{ foreach(var i;me.states[state]) if(i.symbol==operand.symbol or i.symbol==nil){ println(i); die("conflict operand"); } append(me.states[state],operand); } }, load:func(data){ foreach(var opr;data){ var (nstat,sym,csym,move,nextstat)=opr; me.add(nstat,operand.new(sym,csym,move,nextstat)); } } }; var prt=func(state,pointer,paper,act=nil){ print(act!=nil?act:'','\n\t'); var s=''; foreach(var i;paper) s~=i; s~='\n\t'; for(var i=0;i