:- op(500,xfy,:).
:- op(500,xfx,--->).
:- op(600,xfy,===).


% example:

S ---> [NP,VP] :-
  S:cat  === s,
  NP:cat === np,
  VP:cat === vp,
  NP:per === X,
  VP:per === X,
  NP:num === VP:num.


% meaning:

X === Y :- 
   denotes(X,Z),
   denotes(Y,Z).

denotes(Var,Var) :-
   var(Var),!.

denotes(Atom,Atom) :-
   atomic(Atom),!.

denotes(Dag:Feat,Value) :-
   pathval(Dag,Feat,Value,_).

pathval([Feat:Val1 | Rest], Feat, Val2, Rest) :-
   !, unify(Val1,Val2).

pathval([Dag | Rest], Feat, Val, [Dag | Rest2]) :-
   pathval(Rest,Feat,Val,Rest2).

% unification of two feature structures
unify(Dag,Dag) :- !.
unify([Feat:Val | Rest1], Dag) :-
   pathval(Dag,Feat,Val,Rest2),
   unify(Rest1,Rest2).


