% Lesson 3, Foils 11 and 16 
% Basic recognizer and generator for FSM

test(Words) :-
        initial(Node),
        recognize(Node,Words).

recognize(Node,[]) :-
        final(Node).
recognize(FromNode,String) :-
        arc(FromNode,Label,ToNode),
        traverse(Label,String,NewString),
        recognize(ToNode,NewString).

traverse(First,[First|Rest],Rest).

generate :-
        test(X),
        write(X),
        nl,
        fail.
