Stack Based State Machine working