%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Patrick Blackburn, 1999.
% Kristina Striegnitz, 2002.
%
% This file contains the code for a FSA parser based on 
% recognisz1 (the first recognizer from lecture1 that could not 
% handle jump arcs).
%
% Usage: testparse1(?Symbols,-Parse)
%        Symbols: a list; input/output tape
%        Parse: a list; path through the states of the FSA
%
% Note: Cannot handle jump arcs.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% parse1(+Node,?List,-List)
%%% 1st arg: current state of the FSA
%%% 2nd arg: rest of the input/output tape
%%% 3rd arg: collects the states the FSA passes through

parse1(Node,[],[Node]) :-
    final(Node).
parse1(Node_1,String,[Node_1,Label|Path]) :-
    arc(Node_1,Node_2,Label),
    traverse1(Label,String,NewString),
    parse1(Node_2,NewString,Path).


%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% traverse1(+Label,?List, -List)
%%% exactly the same as in recognize1.pl

traverse1(Label,[Label|Symbols],Symbols).


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% the driver predicate

testparse1(Symbols,Parse) :-
    initial(Node),
    parse1(Node,Symbols,Parse).

genparse1(Symbols,Parse) :-
   testparse1(Symbols,Parse).

