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


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% parse2(+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

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


%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% traverse2(+Label,?List, -List)
%%% same as for recognize2.pl

traverse2('#',String,String).
traverse2(Label,[Label|Symbols],Symbols).


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

testparse2(Symbols,Parse) :-
    initial(Node),
    parse2(Node,Symbols,Parse).

genparse2(Symbols,Parse) :-
   testparse2(Symbols,Parse).
