Bracket Matching by mskzzzz

-A:-write(A).
f:- -'failed at: '.
[]+S:-S=[9]-> -yes;f,-'EOL'.
[H|T]+[A|B]:-nth0(I,"({[<)}]>",H),(I<4->T+[I|[A|B]];(A+4=\=I->f,maplist(put,[H|T]);T+B)).
m:-open('/dev/fd/0',read,F),repeat,read_line_to_codes(F,L),(L@<f;L+[9],\+nl).

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

download

return to the top page