% -*- prolog -*-

%%% a(string) means string is accepted, ie in language.
%%% eg a([f, o, o]), assuming "foo" is in language.

%%% NFA

%%% Start state

%%% when we write this:
a(S) :- a(0, S).
%%% Prolog internally sees
% a/1(S) :- a/2(0, S).

% foo/3(a/0(), b/1(q), cons/3(d/0(), r/0(), s/0()))

%%% a(s1, string) means string is accepted starting at state s1.

%%% Accepting states:

a(Q, []) :- member(Q, [0, 30, 50]).

%%% Transitions:

a(Q, [X|S]) :- trans(Q, R, X), a(R, S).

trans(Q, R, X) :- member([Q, R, X],
	                 [[0, 31, x],
		          [0, 51, x],
			  [30, 31, x],
			  [31, 32, x],
			  [32, 30, x],
			  [50, 51, x],
			  [51, 52, x],
			  [52, 53, x],
			  [53, 54, x],
			  [54, 50, x]]).
