%---------------------------------------------------------------- % First, define the basic machine behavior... % this part is common to all FSA definitions %---------------------------------------------------------------- %--- vocal running... show the parse ---------------------------- parse(Word) :- start(St), crank(St,Word). crank(St,[]) :- final(St), write(St), write(' '), write([]), nl. crank(St,[H|T]) :- delta(St,H,Nx), write(St), write(' '), write([H|T]), nl, crank(Nx,T). %--- silent running... just say yes or no ----------------------- accept(Word) :- start(State), run(State,Word). run(State,[]) :- final(State). run(State,[X|Xs]) :- delta(State,X,Next), run(Next,Xs). %----------------------------------------------------------------- % Now, this specific FSA graph definition % this is the data table for the generic machine above % % language: b* a+ b (a|b)* %----------------------------------------------------------------- start(0). final(2). delta(0,a,1). delta(0,b,0). delta(1,a,1). delta(1,b,2). delta(2,a,2). delta(2,b,2). %----------------------------------------------------------------- % draw the diagram... it will help you see the language %-----------------------------------------------------------------