home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / cplus / 18961 < prev    next >
Encoding:
Internet Message Format  |  1993-01-11  |  7.6 KB

  1. Xref: sparky comp.lang.c++:18961 comp.lang.eiffel:1416
  2. Newsgroups: comp.lang.c++,comp.lang.eiffel
  3. Path: sparky!uunet!wupost!cs.uiuc.edu!sparc0b!ctaylor
  4. From: ctaylor@cs.uiuc.edu (Conrad Taylor)
  5. Subject: Help with Simula program conversion...???
  6. Message-ID: <C0pGss.CoJ@cs.uiuc.edu>
  7. Sender: news@cs.uiuc.edu
  8. Organization: University of Illinois at Urbana-Champaign
  9. Date: Mon, 11 Jan 1993 19:58:03 GMT
  10. Lines: 258
  11.  
  12.  
  13.  
  14.          Yes, I was wondering if anyone would be so kind to assist me in the
  15. conversion of a very small program to Eiffel or Pascal or C?  I don't have
  16. any backround in Simula and there's not a Simula system on the machines that
  17. I'm working.  Thanks in advance to all that reply to this post.
  18.  
  19. -Conrad
  20.  
  21. ps:  My e-mail is ctaylor@silver.lcs.mit.edu or
  22.      taylor1@wse.eecs.uic.edu.
  23.  
  24. The code is as follows:
  25.  
  26. ----------------------------------------------------------------
  27. "comment" ------------- tree printing algorithms -----------;
  28.  
  29. head "class" genhead;
  30. "begin"
  31.    "integer" arcs;
  32. "end" *** genhead ***;
  33.  
  34. link "class" node(p);
  35.    "ref"(individu) p;
  36. "begin"
  37.    "integer" tarcs,barcs;
  38.    "integer" dup,pos;
  39.  
  40.    "procedure" into(l); "ref"(genhead) l;
  41.    "begin"
  42.       "ref"(node) pp;
  43.       "integer" i;
  44.       "this" link.into(l);
  45.       pp:-pred;
  46.       "if" pp=="none" "then" pos:=-999999
  47.       "else" pos:=pp.pos+2;
  48.       i:=1;
  49.       "while"("if" pp=/="none"
  50.               "then" pp.p =/= p
  51.               "else" "false")
  52.       "do" "begin" pp:-pp.pred; i:=i+1 "end";
  53.       "if" pp=/="none" "then" dup:=i;
  54.    "end";
  55.  
  56.    "procedure" printyear(e); "ref"(event) e;
  57.    "inspect" e "do"
  58.       "if" year=0 "then" outchar($?$) "else" outint(year,4)
  59.    "otherwise" outchar($?$);
  60.  
  61.    "procedure" outkey(ln,w); "integer" ln,w;
  62.    "begin"
  63.       "integer" npos;
  64.       npos:= sysout.pos+w;
  65.       outchar($ $);
  66.       "inspect" p "do"
  67.          "if" ln=1 "then"
  68.             "begin" outtext(nom); printref "end"
  69.          "else""if" ln=2 "then"
  70.             outtext(prenom)
  71.          "else""if" dup "ne" 0 "then"
  72.             outtext(""<--dup--"")
  73.          "else""begin"
  74.             outchar($($);
  75.             printyear(birth);
  76.             outchar($-$);
  77.             printyear(death);
  78.             outchar($)$);
  79.          "end";
  80.       setpos(npos);
  81.    "end" *** outkey ***;
  82.  
  83. "end" *** node ***;
  84.  
  85. "procedure" treeprint;
  86. "if" "not" liste.empty "then"
  87. "begin"
  88.    "ref"(genhead) "array" generation[- 20:20];
  89.    "integer" firstgen,lastgen;
  90.    "procedure" checkgen(g);  "integer" g;
  91.       "if" generation[g]=="none" "then"
  92.       "begin"
  93.          generation[g]:-"new" genhead;
  94.          "if" g>lastgen"then" lastgen:=g
  95.          "else""if" g<firstgen "then" firstgen:=g;
  96.       "end" *** checkgen ***;
  97.  
  98.    "text" vertline,horline,leftend,rightend,cross;
  99.    "procedure" outblank;  setpos(pos+keywidth);
  100.  
  101.    "integer" l,c,r,
  102.       arcs,
  103.       minpos,maxpos,
  104.       startpos,endpos,p,np,i,
  105.       keywidth,pagewidth,
  106.       g,line;
  107.  
  108. "ref"(node) "procedure" position(p,g,pos);
  109.    "ref"(individu) p;
  110.    "integer" g, pos;
  111. "begin"
  112.    "ref"(node) pnode,pn,lnode,rnode;
  113.    "ref"(individu) pere,mere;
  114.  
  115.    "procedure" insert(set,member);
  116.       "name" set; "integer" set,member;
  117.       set:= or(set,member);
  118.  
  119.    pnode:- "new" node(p);
  120.    checkgen(g);
  121.    pnode.into(generation[g]);
  122.    "if" pnode.pos>pos "then" pos:=pnode.pos;
  123.  
  124.    "if" pnode.dup=0 "then"
  125.    "begin"
  126.       "inspect" mariage[p.parents] "do"
  127.       "begin"
  128.          pere:- person[husband];
  129.          mere:- person[wife];
  130.       "end";
  131.       "if" pere=="none" "and" mere == "none" "then"
  132.          pnode.pos:=pos
  133.       "else"
  134.       "begin"
  135.          "if" pere=/="none" "and" mere=/="none" "then"
  136.          "begin"
  137.             lnode:-position(pere,g-1,pos-1);
  138.             rnode:-position(mere,g-1,pos+1);
  139.          "end"
  140.          "else"
  141.             lnode:-rnode:-
  142.                position("if" pere=="none""then" mere "else" pere,
  143.                         g-1,pos);
  144.          pos:=(lnode.pos+rnode.pos) "div" 2;
  145.          "if" pos>pnode.pos
  146.             "then" pnode.pos := pos
  147.             "else" pos := pnode.pos ;
  148.          insert(pnode.tarcs,c);
  149.          "for" pn:-("if" lnode.pos<rnode.pos
  150.                        "then" lnode "else" rnode),
  151.                   pn.suc "while" pn=/="none" "do"
  152.          "begin"
  153.             pn.barcs:= or(pn.barcs,c);
  154.             "if" pn.pos<pos "then"
  155.                "begin" insert(pn.barcs,r); insert(pnode.tarcs,l) "end"
  156.             "else""if" pn.pos>pos "then"
  157.                "begin" insert(pn.barcs,l); insert(pnode.tarcs,r) "end";
  158.          "end"
  159.       "end"
  160.    "end"
  161.    "else""if" pnode.dup < 3 "then"
  162.    "begin"
  163.       pn:-("if" pnode.dup=1 "then" pnode.pred "else" pnode.pred.pred);
  164.       "if" pnode.dup=1 "or" pnode.pred"qua"node.barcs "ne" c "then"
  165.       "begin"
  166.          pnode.out; pnode:-pn;
  167.          pos:=pnode.pos;
  168.       "end"
  169.       "else" pnode.pos:=pos;
  170.    "end";
  171.  
  172.    "if" pos>maxpos "then" maxpos:= pos "else"
  173.    "if" pos<minpos "then" minpos:= pos;
  174.    position:- pnode;
  175. "end"  *** position ***;
  176.  
  177.    "ref"(genhead) h;
  178.    "ref"(node) tl,bl;
  179.  
  180.    l:=1; c:=2; r:=4;
  181.    vertline :- copy(""    !     "");
  182.    horline  :- copy(""----------"");
  183.    leftend  :- copy(""    +-----"");
  184.    rightend :- copy(""----+     "");
  185.    cross    :- copy(""----+-----"");
  186.    keywidth := 10;
  187.    pagewidth:= 132 "div" keywidth -1;
  188.    lpp:=150; linesperpage(151);
  189.  
  190.    tl:-position(liste.first ,0,0);
  191.    generation[lastgen+1] :- "new" genhead;
  192.    "for" i:= firstgen "step" 1 "until" lastgen+1 "do"
  193.    "begin"
  194.       tl:-"new" node("none");  tl.pos:= 999999;
  195.       tl "qua" link .into(generation[i]);
  196.    "end";
  197.  
  198.    startpos := minpos;
  199.    "while" startpos <= maxpos "do"
  200.    "begin"
  201.      newpage;
  202.      endpos := startpos+pagewidth;
  203.      "for" g:= firstgen "step" 1 "until" lastgen "do"
  204.      "begin"
  205.         h:- generation [g];
  206.         bl:- generation [g+1].first;
  207.         "for" i:=1 "step" 1 "until" 6 "do"
  208.         "begin"
  209.           tl:-h.first;
  210.           p:= startpos;
  211.           "while" p < endpos "do"
  212.           "begin"
  213.             np:=tl.pos;
  214.             "if" i < 6 "then"
  215.             "begin"
  216.               "if" np>= endpos "then" p:= endpos
  217.               "else" "if" p "ne" np "then" outblank
  218.               "else""if" i=1 "and" and(c,tl.tarcs) "ne" 0 "or"
  219.                          i=5 "and" and(c,tl.barcs) "ne" 0 "then"
  220.                     outtext(vertline)
  221.               "else""if" i>1 "and" i<5 "then" tl.outkey(i-1,keywidth)
  222.               "else" outblank;
  223.  
  224.               "if" p=np "then" tl:-tl.suc;
  225.             "end"
  226.             "else""begin"
  227.               "if" np>bl.pos "then" np:=bl.pos;
  228.               "if" p "ne" np "then" arcs:= h.arcs
  229.               "else""begin"
  230.                  arcs:=0;
  231.                  "if" tl.pos=p "then""begin"
  232.                        arcs:= or(arcs,tl.barcs);  tl:- tl.suc;
  233.                        tl.pred.out;
  234.                     "end";
  235.                  "if" bl.pos = p "then""begin"
  236.                        arcs := or(arcs,bl.tarcs);  bl:-bl.suc;
  237.                     "end";
  238.                  "if" and(c,arcs)=0
  239.                     "then" arcs:= h.arcs
  240.                  "else""if" and(r,arcs)=r "then"
  241.                     h.arcs:= l+r
  242.                  "else"
  243.                     h.arcs:=0;
  244.               "end";
  245.  
  246.               "if" arcs = l+r+c          "then" outtext(cross)
  247.               "else""if" arcs = l+r      "then" outtext(horline)
  248.               "else""if" and(l,arcs) = l "then" outtext(rightend)
  249.               "else""if" and(r,arcs) = r "then" outtext(leftend)
  250.               "else""if" and(c,arcs) = c "then" outtext(vertline)
  251.               "else""if" np>= endpos "then" p:= endpos
  252.               "else" outblank;
  253.             "end";
  254.             p:=p+1;
  255.           "end";
  256.           nl(1);
  257.         "end";
  258.      "end";
  259.      startpos:= endpos;
  260.    "end";
  261.    lpp:=63; lines per page(64);
  262. "end" *** treeprint ***;
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.