Simulating a PLC ladder diagram on arduino

sorry for not clearing that up Karma...
the keep function that i am talking about is an digital equivalent RS flip flop.

meaning that every open and close contact operation in the upper rung ( rung in simple term line) if high with result in the S portion to be high.
if the lower rung is true, the R will set HIgh and the keep will be low. R will always be a priority