This challenge is to golf an implementation of SKI formal combinator calculus.
I are terms.
If x and y are terms then
(xy) is a term.
The following three steps will be repeated until none of them apply. In these, x, y, and z must be terms.
(Ix) will be replaced by
((Kx)y) will be replaced by
(((Sx)y)z) will be replaced by
A string or array, you do not have to parse the strings in the program.
The input is assumed to be a term.
If the simplification does not terminate, the program should not terminate.
(((SI)I)K) should evaluate to
The evaluation order is up to you.
This is code-golf. Shortest program in bytes wins.