home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / lifeos2.zip / LIFE-1.02 / TESTS / LF / CHAPLA.LF < prev    next >
Text File  |  1996-06-04  |  2KB  |  108 lines

  1. %
  2. %
  3. %            Implementation of Chadha and Plaisted's algorithm to compute
  4. %            attribute directions.
  5. %
  6. %
  7.  
  8. %
  9. % This operator avoids using project
  10. %
  11.  
  12. % op(400,yfx,##)?
  13. % X##Y -> project(Y,X).
  14.  
  15.  
  16. %
  17. % hierarchy of directions (dual of that of the lattice)
  18. %
  19.  
  20. inh <| syn.
  21.  
  22. %
  23. % going "up" the directions
  24. %
  25.  
  26. up1(X) :-  [X] = children(X).
  27.  
  28. %
  29. % DATA STRUCTURES
  30. %
  31.  
  32. :: attribute(direction => syn, 
  33.              occurrences => list % of positions 
  34.              ).
  35.  
  36. :: position( attrib => A:attribute, 
  37.              pos    => N:int, % N = 0 si on est en tete de clause,
  38.                   %   = 1..n en corps.
  39.  
  40.              share  => list   % of positions
  41.            ).
  42.  
  43. :: program ( positions => list, % of positions 
  44.              attributes => list % of attributes 
  45.            ).
  46.  
  47.  
  48. %
  49. % PROGRAM
  50. %                         
  51.  
  52. chapla(Pgm) :- updateCP(Pgm.positions).
  53.  
  54. updateCP([]).
  55. updateCP([Pos|ListofPos]) :- modifCP(Pos,ModifList),
  56.                              updateCP(append(ModifList,ListofPos)&list).
  57.  
  58. modifCP(Pos1,ModifList) :- (  Pos1.pos > 0, 
  59.                               depend(Pos1,Pos2),
  60.                               (%
  61.                    % Case 1
  62.                                %
  63.                                  N2 = Pos2.pos,
  64.                                  N2 > 0 ,
  65.                                  N2 =< Pos1.pos 
  66.                               ;
  67.                                %
  68.                    % Case 2
  69.                                %
  70.                                  N2 =:= 0 ,
  71.                                  Pos2.attrib.direction :=< inh 
  72.                               ),
  73.                               !,
  74.                               A1= Pos1.attrib,
  75.                               up1(A1.direction),
  76.                               ModifList = A1.occurrences 
  77.                            );
  78.                            ModifList = [].
  79.                                
  80.                           
  81.  
  82. depend(P1,P2) :- orient(P1.attrib.direction,P1.pos) = in, 
  83.                  umember( P2, P1.share).
  84.  
  85.  
  86.  
  87. orient(Dir:syn, K) -> { (in  | ( K=:=0 , Dir :=< inh , !));
  88.                         (out | ( K=\=0 , Dir :=< inh , !));
  89.                         (out | ( K=:= 0 , ! )) ;
  90.                         in }.
  91. umember(X,[Y|L]) :- ( X=Y ; umember(X,L)).
  92.  
  93.  
  94. writeout(A:attribute) -> true | (A.direction :=< inh, !, Dir = "inherited" ;
  95.                                  Dir = "synthesized"),
  96.                                  write( " This attribute is ", Dir), nl.
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.