home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / modula2 / 1657 < prev    next >
Encoding:
Text File  |  1993-01-12  |  2.6 KB  |  74 lines

  1. Newsgroups: comp.lang.modula2
  2. Path: sparky!uunet!spool.mu.edu!caen!batcomputer!ghost.dsi.unimi.it!univ-lyon1.fr!chx400!bernina!neptune!nugget.inf.ethz.ch!marti
  3. From: marti@nugget.inf.ethz.ch (Robert Marti)
  4. Subject: Re: C to Modula2 converter?
  5. Message-ID: <1993Jan12.144358.18576@neptune.inf.ethz.ch>
  6. Sender: news@neptune.inf.ethz.ch (Mr News)
  7. Nntp-Posting-Host: nugget.inf.ethz.ch
  8. Organization: Dept. Informatik, Swiss Federal Institute of Technology (ETH), Zurich, CH
  9. References: <36762.2B50C7C3@puddle.fidonet.org> <1993Jan11.081026.25261@neptune.inf.ethz.ch> <C0qHLI.F7L@agora.rain.com>
  10. Date: Tue, 12 Jan 1993 14:43:58 GMT
  11. Lines: 61
  12.  
  13. In article <C0qHLI.F7L@agora.rain.com>, robart@agora.rain.com
  14. (Joe Bob) writes in an ongoing thread with contributions form
  15. Robert Barton (RB) and myself (RM):
  16.  
  17. RB >>> A C to Modula-2 converter is not possible, since Modula-2 does
  18. RB >>> not support set complement, structured constants, or null
  19. RB >>> procedure variables.
  20.  
  21. RM >>  Not possible is a bit strongly worded, considering that I can think
  22. RM >>  of solutions to all three problems.
  23.  
  24. JB >   The lack of structured constants can be worked around to an extent
  25. JB >   by using variables and a long sequence of assignments.  There are
  26. JB >   no substitutes for the other two problems, though.
  27.  
  28.  
  29. Let's see.
  30.  
  31.  
  32. Set complement:
  33.  
  34. The set complement of an expression expr of type
  35.     FooSet = SET OF [lb .. ub]
  36. is
  37.     {lb .. ub} - expr
  38. (see sections 5 and 8.2.3 of the report).
  39.  
  40.  
  41. Null procedure variables:
  42.  
  43. A "clean" solution would be to generate a
  44.     PROCEDURE NullProcT(p1: T1, ... , pn: Tn): RetT;
  45.       BEGIN
  46.         (* you may need to return something of type RetT here *)
  47.       END NullProcT
  48. for each
  49.     TYPE ProcT = PROCEDURE (T1, ... , Tn): RetT
  50. and replace tests
  51.     p = NIL  (or p # NIL, respectively their C counterparts)
  52. for a variable p of type ProcT with tests
  53.     p = NullProcT  (or p # NullProcT).
  54.  
  55. Another possibility is to generate an additional type
  56.     ProcTWithNull = RECORD CASE BOOLEAN OF
  57.                       TRUE:  proc: ProcT
  58.                     | FALSE: adr:  SYSTEM.ADDRESS
  59.                     END
  60. for each type ProcT, declare all respective procedure variables p
  61. to be of type ProcTWithNull (not of type ProcT!), write all calls as
  62.     p.proc(...)
  63. and write all tests for NULL (or NIL) as
  64.     p.adr = NIL  (or p.adr # NIL)
  65.  
  66. Disclaimer: I haven't tried the latter solution, but I think
  67. it should work.  In any case, it's a hack.
  68.  
  69. -- 
  70. Robert Marti                    |  Phone:    +41 1 254 72 60
  71. Informationssysteme             |  FAX:      +41 1 262 39 73
  72. ETH-Zentrum                     |  E-Mail:   marti@inf.ethz.ch
  73. CH-8092 Zurich, Switzerland     |
  74.