/*
 * --------------------------------------------------
 * Logische Programmierung, ueb 6.1-6.2, 16.12.2002
 * (c)Marc Dörflinger, Roger Nösberger, Philip Iezzi
 * --------------------------------------------------
 */

% fsa wird mit der liste aus den wörtern des zu parsenden satzes aufgerufen

fsa(List) :-
	initial(A),
	fsa(List, A).
	
% wenn die liste leer ist und State dem endzustand entspricht, dann ist fertig

fsa([], State) :-
	final(State).


% wenn es einen übergang von State nach NewState mit Element gibt, dann wird die fsa mit 
% dem NewState und dem rest der Liste aufgerufen. 

fsa([Element|List], State) :-
	transition(State, Element, NewState),
	fsa(List, NewState).


% Folge von Symbolen:
% [the, cat, is, on, the, mat, '.']
% [the, dog, is, on, the, mat, '.']

initial(z0).
final(e).
transition(z0, the, z1).
transition(z1, cat, z2).
transition(z1, dog, z2).   % nicht-deterministisch!
transition(z2, is,  z3).
transition(z3, on,  z4).
transition(z4, the, z5).
transition(z5, mat, z6).
transition(z6, '.', e).




/*
 * --------------------------------------------------
 * Logische Programmierung, ueb 6.3, 16.12.2002
 * --------------------------------------------------
 */

initial([the, cat, is, on, the, mat, '.']).
initial([the, dog, is, on, the, mat, '.']).

fsa(List) :-
	initial(StartState),
	accept(List, StartState).
	
accept([], []).

accept([H|Tail1], [H|Tail2]) :-
	accept(Tail1, Tail2).






/*
 * --------------------------------------------------
 * Logische Programmierung, ueb 6.4, 16.12.2002
 * --------------------------------------------------
 */

fsa(List) :-
	states(T),
	fsa(List, T).

fsa([], []).

fsa([Element|List], [CurrentState|OtherStates]) :-
	T =.. [CurrentState, Element],
	T,
	fsa(List, OtherStates).

% Grammatik
states([article, noun, verb, preposition, article, noun, punctuation]).

% Syntax
article(the).
article(a).
noun(cat).
noun(dog).
noun(mat).
verb(is).
preposition(on).
punctuation('.').

