:- module(_,_,[sr/bfall]).

% Graph example: 
% Definition of a (generic) non-deterministic, finite automaton: 
accept(S) :- initial(Q), accept_from(S, Q).

accept_from([],Q)     :- final(Q).
accept_from([C|Cs],Q) :- delta(Q, C, NewQ), accept_from(Cs,NewQ).

% A concrete automaton, defined by its initial and final states: 
initial(q0).      final(q0).              % and its transitions: 
delta(q0, a, q1). 
delta(q1, b, q0). 
delta(q1, b, q1).

%            a
%      -------------    
%      |           |   ___
%   ___|__      ___v__/   \
%   | q0 |      | q1 |     | b
%   ------      ------<    |
%      ^           |   \__/
%      |           |
%      -------------    
%            b

% Try::
% Check if these sequences accepted: 
% ?- accept([a,b,b]).
% ?- accept([a,b,b,a]).
% List all sequences of 4 chars: 
% ?- accept([A, B, C, D]).
% List all accepted sequences: 
% ?- accept(X).
