home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / c / 11431 < prev    next >
Encoding:
Internet Message Format  |  1992-07-22  |  3.7 KB

  1. Xref: sparky comp.lang.c:11431 comp.lang.c++:11322 comp.lang.objective-c:452
  2. Path: sparky!uunet!sun-barr!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!ira.uka.de!uka!i41s14!prechelt
  3. From: prechelt@i41s14.ira.uka.de (Lutz Prechelt)
  4. Newsgroups: comp.lang.c,comp.lang.c++,comp.lang.objective-c
  5. Subject: C-Refine 3.0 preprocessor available
  6. Date: 22 Jul 1992 14:53:22 GMT
  7. Organization: University of Karlsruhe, FRG
  8. Lines: 105
  9. Distribution: world
  10. Message-ID: <14jsp2INNd55@iraul1.ira.uka.de>
  11. NNTP-Posting-Host: i41s14.ira.uka.de
  12. Keywords: refinements, programming language extension
  13.  
  14.  
  15. C-Refine Version 3.0 is now available for anonymous ftp from
  16.   iraun1.ira.uka.de [129.13.10.90]
  17.   /pub/gnu/crefine.3.0.tar.Z
  18. as
  19. -rw-r--r--  1 ftp      XLINK       93217 Jul 15 10:06 crefine.3.0.tar.Z
  20.  
  21. It also appeared on comp.sources.reviewed as v02i013 to v02i19
  22. on July 15th, 1992
  23.  
  24. -----------------------------------------------------------------------------
  25.  
  26. C-Refine is a preprocessor for programs written in C or C++ or a similar
  27. language. It introduces an additional language construct called 'refinement'
  28. which allows further decomposition with symbolic names inside functions.
  29. This makes programs much easier to read and modify and is very comfortable
  30. for programming. C-Refine is very fast and fits easily into any open
  31. programming environment.
  32.  
  33. Here is the tiny example program from the manual page,
  34. so that you can grasp the idea:
  35.  
  36.  "This is a (very simple-minded) version
  37.   of the Sieve of Eratosthenes. It should not be thought
  38.   that  I  believe  the  refinement technique to be espe-
  39.   cially well suited to this problem, but  this  was  the
  40.   smallest 'real' problem I could think of to demonstrate
  41.   at least most of what  the  possibilities  of  C-Refine
  42.   are. So here it is:
  43.  
  44. /***** EXAMPLE : The Sieve of Eratosthenes *****/
  45.  
  46. #define MAX        10000
  47. #define PRIME      0
  48. #define NON_PRIME  1
  49.  
  50. static int sieve[MAX+1];
  51.  
  52. int main ()
  53. {
  54.   `initialize;
  55.   `do sieve;
  56.   `make output;
  57.   return (0);
  58.   
  59. `initialize:
  60.   int current;
  61.   for (current = 2; current <= MAX; current++)
  62.     sieve[current] = PRIME;
  63.     
  64. `do sieve:
  65.   int current_prime = 1;
  66.   for (;;) {
  67.     `find next bigger prime;  /* perhaps STOP here */
  68.     `delete all multiples of current_prime;
  69.   }
  70.  
  71. `find next bigger prime:
  72.   int current_candidate = current_prime + 1;
  73.   while (sieve[current_candidate] == NON_PRIME)
  74.     if (current_candidate == MAX)
  75.       leave `do sieve;    /* leave two refinements at once */
  76.     else
  77.       current_candidate++;
  78.   /* now current_candidate is a prime (or we leave `sieve) */
  79.   current_prime = current_candidate;
  80.   
  81. `delete all multiples of current_prime:
  82.   int current = `first multiple of current_prime;
  83.   while (current <= MAX) {
  84.     sieve[current] = NON_PRIME;
  85.     current += current_prime;
  86.   }
  87.   
  88. `first multiple of current_prime:
  89.   2 * current_prime
  90.  
  91. `make output:
  92.   int current;  /* different from 'current' above */
  93.   printf ("The primes between 2 and %d are\n", MAX);
  94.   for (current = 2; current <= MAX; current++)
  95.     if (`current is prime)
  96.       printf ("%5d ", current);
  97.  
  98. `current is prime:
  99.   sieve[current] == PRIME
  100.  
  101. } /* end of main() */
  102.  
  103. /***** End of example *****/"
  104.  
  105. Your programs are more complicated ?
  106. Fine, then C-Refine will be much more useful for them.
  107.  
  108. The installed system consists of a single executable file (crefine) and one
  109. Unix Manualpage (crefine.1). No further data files or libraries
  110. except the standard C library are needed, so C-Refine is very portable.
  111.  
  112.    Lutz 
  113.  
  114. Lutz Prechelt   (email: prechelt@ira.uka.de)            | Whenever you 
  115. Institut fuer Programmstrukturen und Datenorganisation  | complicate things,
  116. Universitaet Karlsruhe;  D-7500 Karlsruhe 1;  Germany   | they get
  117. (Voice: ++49/721/608-4317, FAX: ++49/721/694092)        | less simple.
  118.  
  119.