%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Patrick Blackburn, 1999.
% Kristina Striegnitz, 2002.
%
% This file contains the code for a simple finite state transducer
% with two tapes.
%
% Usage: testtrans1(?List,?List)
%        The Lists represent the two tapes.
%
% Main predicate: transduce1(+Node,?SymbolList,?SymbolList)
%                 SymbolList:  the two tapes
%                 Node:  number of the node you wish to start from
%
% This file furthermore defines:
% + the driver predicate testtrans1(?SymbolList,?SymbolList)
% + traverse1/5
%
% NOTE: traverse1 cannot handle jump arcs.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% transduce1(+Node,?List,?List)
%%% Simulates the steps of the transducer. Evaluates to true, iff a
%%% final state is reached when both tapes have been read completely.

% the base case
transduce1(Node,[],[]) :-
    final(Node).

% the recursive clause: the transducer makes one step and then
% the predicate is called recursively with the rest of the tapes.
transduce1(Node_1,String_left,String_right) :-
    arc(Node_1,Node_2,Label),
    traverse1(Label,String_left,NewString_left,String_right,NewString_right),
    transduce1(Node_2,NewString_left,NewString_right).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% traverse1(+Symbol:Symbol,+List,-List,+List,-List)
%%% Tests whether the two symbold provided by the first argument
%%% match with the first Elements in the input lists (args 2 and 4).
%%% Returns the tail of the input lists in args 3 and 5.

traverse1(Sym_left:Sym_right,[Sym_left|Rest_left],Rest_left,
                               [Sym_right|Rest_right],Rest_right).


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

testtrans1(Left,Right) :-
    initial(Node),
    transduce1(Node,Left,Right).
