:- module(addTree,[]).

translate((L --> R),(Ltr --> Rtr)) :-
   translate1(L,Ltr,Baum),
   translate2(R,Rtr,Baumliste),  
   Baum = [L|Baumliste].
% translate1(+Kategorie,-Term,?Baum)

translate1(Kategorie,Term,Baum) :-
    Kategorie =.. [Funktor|Argumente],
    append(Argumente,[Baum],MehrArgumente),
    Term =.. [Funktor|MehrArgumente].

% translate2(+Cat,-CatTr,-Bäume)

translate2((A,B),((Atr,Btr),{Code}),Baeume) :-
    !, translate2(A,Atr,BaeumeA),
       translate2(B,Btr,BaeumeB),
    Code = append(BaeumeA,BaeumeB,Baeume).

translate2((A;B),(Atr;Btr),Baeume) :-
    !, translate2(A,Atr0,BaeumeA),
       translate2(B,Btr0,BaeumeB),
    Atr = (Atr0,{ Baeume=BaeumeA }),
    Btr = (Btr0,{ Baeume=BaeumeB }).

translate2([],[],[]) :- !.
translate2([Atom],[Atom],[Atom]) :- !.

translate2({Prolog},{Prolog},[]) :- !.

translate2(Cat,CatTr,[Baum]) :-
    !, translate1(Cat,CatTr,Baum).

