1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162(**************************************************************************)(* *)(* OCaml *)(* *)(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)(* *)(* Copyright 1996 Institut National de Recherche en Informatique et *)(* en Automatique. *)(* *)(* All rights reserved. This file is distributed under the terms of *)(* the GNU Lesser General Public License version 2.1, with the *)(* special exception on linking described in the file LICENSE. *)(* *)(**************************************************************************)typet=PidentofIdent.t|Pdotoft*string*int|Papplyoft*tletrecsamep1p2=match(p1,p2)with|Pidentid1,Pidentid2->id1=id2|Pdot(p1,s1,_),Pdot(p2,s2,_)->s1=s2&&samep1p2|Papply(fun1,arg1),Papply(fun2,arg2)->samefun1fun2&&samearg1arg2|_,_->falseletreccomparep1p2=match(p1,p2)with|Pidentid1,Pidentid2->ifid1<id2then-1elseifid1>id2then1else0|Pident_,_->-1|_,Pident_->1|Pdot(p1,s1,_),Pdot(p2,s2,_)->letc=String.compares1s2inifc<>0thencelsecomparep1p2|Pdot_,_->-1|_,Pdot_->1|Papply(fun1,arg1),Papply(fun2,arg2)->letc=comparefun1fun2inifc<>0thencelsecomparearg1arg2letkfalse_=false(* For printing *)letrecname?(paren=kfalse)=function|Pidentid->Ident.nameid|Pdot(p,s,_pos)->name~parenp^ifparensthen".( "^s^" )"else"."^s|Papply(p1,p2)->name~parenp1^"("^name~parenp2^")"letrecbinding_time=function|Pident_->0|Pdot(p,_,_)->binding_timep+1|Papply(p,_)->binding_timepletrecisfreeid=function|Pidentid'->id=id'|Pdot(p,_,_)->isfreeidp|Papply(p1,p2)->isfreeidp1||isfreeidp2letrechead=function|Pidentid->id|Pdot(p,_,_)->headp|Papply(p,_)->headp