Brainfuck, 132 bytes
+>,[[<->>+>[-]<<-]<[>+>[<+<+>>>+<-]+++++[>--------<-]>[<<+>++++[>-----<-]>[<++++
+[>------<-]>-[<++++[>--------<-]>[,>]]]]<],]<<[>]>.
Formatted:
+>,
[
[<-> >+>[-]<<-]
<
[
not matching closing bracket
>+>[<+<+>> >+<-]
+++++[>--------<-]
>
[
not open paren
<<+>
++++[>-----<-]>
[
not open angle bracket
<+++++[>------<-]>-
[
not open square bracket
<++++[>--------<-]>
[
not open brace
,>
]
]
]
]
<
]
,
]
<<[>]
>.
Expects input without a trailing newline. Prints \x00
for false and \x01
for true.
Approach: Maintain a stack starting with \x01
, and push the corresponding closing bracket whenever an opening bracket is encountered. Before checking whether the current character is an opening bracket, first check whether it's equal to the closing bracket at the top of the stack, and if so pop it. If it's neither the proper closing bracket nor an opening bracket, consume the rest of the input while moving the pointer to the right. At the end, check whether the pointer is next to the initial \x01
.