
module main {
    type state_t = enum { RED, GREEN, YELLOW, PENDING };

    var state : state_t;
    var count : int;
    input pedestrian : boolean;
    output sigG : boolean;
    output sigY : boolean;
    output sigR : boolean;

    init {
        state = RED;
        count = 0;
        sigG = false;
        sigY = false;
        sigR = true;
    }

    next {
        if (count < 60) {
            count' = count + 1;
        } else {
            count' = 0;
            if (state == RED) {
                state' = GREEN;
            } else if (state == GREEN && pedestrian) {
                state' = YELLOW;
            } else if (state == GREEN) {
                state' = PENDING;
            } else if (state == PENDING) {
                state' = YELLOW;
            } else if (state == YELLOW && count < 5) {
                state' = YELLOW;
            } else {
                state' = RED;
            }
        }

        sigG' = (state == GREEN);
        sigY' = (state == YELLOW);
        sigR' = (state == RED);
    }
}
