BCPL

BCPL is the great-grandfather of C++. First there was CPL, then BCPL, then B, then C and finally C++. I suppose we could continue with Java and C# as well. Interestingly enough, BCPL is still a currently-maintained language, and is currently being maintained by its original inventor, Martin Richards. Here's to longevity!

The following program compiles and runs under the cintsys BCPL compiler. After you issue the "c b SieveE" command to compile the file, type SieveE and hit return to run it.

Note that the source code has the suffix ".bcpl" which must be changed to ".b" before compilation. The reason for this is I am reserving the ".b" suffix for the B language.

////////////////////////////////////////////////////////// // Name: Peter M. Maurer // Program: Sieve of Eratosthenes // Due: Never // Language: BCPL ////////////////////////////////////////////////////////// GET "libhdr" LET start() = VALOF { // define the sieve data structure LET candidates = VEC 1000 LET i,j,k = 0,0,0 FOR z = 0 TO 999 DO { // everything is potentially prime until proven otherwise candidates!z := 1 } // Neither 1 nor 0 is prime, so flag them off candidates!0 := 0 candidates!1 := 0 // start the sieve with the integer 0 i := 0 WHILE i<1000 DO { // advance to the next un-crossed out number. // this number must be a prime WHILE i < 1000 & candidates!i = 0 DO { i := i + 1 } // insure against running off the end of the data structure IF i<1000 DO { // cross out all multiples of the prime, starting with 2*p. j := 2 k := i * j WHILE k < 1000 DO { candidates!k := 0 j := j + 1 k := i * j } // advance to the next candidate i := i + 1 } } // all uncrossed-out numbers are prime (and only those numbers) // print all primes FOR z = 0 TO 999 DO { UNLESS candidates!z = 0 DO { writef("%n is prime*n", z) } } RESULTIS 0 }

Click Here for the actual code.