%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Patrick Blackburn, 1999.
% Kristina Striegnitz, 2002.
%
% This file contains the code for a FSA parser that can handle
% category symbols/abreviations on the arcs.
%
% Usage: testparse3(?Symbols,-Parse)
%        Symbols: a list; input/output tape
%        Parse: a list; path through the states of the FSA
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


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


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


%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% traverse3(+Label,?List, -List)
%%% Instead of comparing directly whether the next symbol
%%% on the input tape and on the arc are the same, make a
%%% lexical lookup to find the category of the next symbol
%%% on the input tape.

traverse3('#',String,String).
traverse3(Label,[Symbol|Symbols],Symbols) :-
	lex(Symbol,Label).



%%%%%%%%%%%%%%%%%%%%%%%%%
%%% two driver predicates

testparse3(Symbols,Parse) :-
    initial(Node),
    parse3(Node,Symbols,Parse).

genparse3(Symbols,Parse) :-
   testparse3(Symbols,Parse).

