Bracket Matching by m.ukai

open String;;while 1=1do
let o,a,p,u=print_endline,read_line(),"failed at: ","(<[{}]>)"in
let rec(@)l i=try let q=index u a.[i]in q<4&u.[7-q]::l@i+1||List.hd l=a.[i]&List.tl l@i+1||()=o(p^sub a i(length a-i))with _->l=['0']&()=o"yes"||()=o(p^"EOL")in['0']@0done

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page