% Grammar 1
% =========

% Multifile declarations. 
% :- multifile '##'/2. 
% :- multifile '~~>'/2. 
:- multifile if/2.

% load phonology and tree output
% :- [trale_home(tree_extensions)].
% :- [trale_home(debugger)].

% specify signature file
signature(signature).

% phrase structure rule
subject_head_rule rule
(phrase, synsem:(category:(head:H,
                          subcat:[]),
                content:Content),
 dtr1:Subj, dtr2:Head,
 dtrs:[Subj,Head],
 phon:MotherPhon)
   ===>
cat> (Subj,
      synsem:Synsem,
      phon:SubjPhon),
cat> (Head,
      synsem:(category:(head:H,
		        subcat:[Synsem]),
		        content:Content),
      phon:HeadPhon),
goal> append(SubjPhon,HeadPhon,MotherPhon).

% lexical entries
she ---> (word,
	  phon:[(a_ she)],
	  synsem:(category: (head:case:nom,
                            subcat:e_list),
                 content: (index: (X, (person:third,
                                       number:sing,
                                       gender:fem))),
                 context: (backgr:[(relation:female,arg1:X)]))).

walks ---> (word,
	    phon:[(a_ walks)],
	    synsem: (category: (head:vform:fin,
                             subcat:[(category:head:case:nom,
                                     content:index: (X,(person:third,
                                                       number:sing
                                                      )))]),
                    content:(relation:walk,
                             arg1:X),
		    context:backgr:e_list)).


%----------------------

append(X,Y,Z) if
   when(  ( X=(e_list;ne_list)
          ; Y=e_list
          ; Z=(e_list;ne_list)
                ),
            undelayed_append(X,Y,Z)).

undelayed_append(L,[],L) if true.
undelayed_append([],(L,ne_list),L) if true.
undelayed_append([H|T1],(L,ne_list),[H|T2]) if
  append(T1,L,T2).
