<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Bcpl  Time Reshared</title>
    <link>https://timereshared.com/tags/bcpl/</link>
    <description>  Bcpl  Time Reshared</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <lastBuildDate>Sun, 03 May 2026 09:04:00 +0900</lastBuildDate>
    <atom:link href="https://timereshared.com/tags/bcpl/index.xml" rel="self" type="application/rss+xml" />
    
    <item>
      <title>TOPS-10: Essex BCPL</title>
      <link>https://timereshared.com/tops-10-essex-bcpl/</link>
      <pubDate>Sun, 03 May 2026 09:04:00 +0900</pubDate>
      <guid>https://timereshared.com/tops-10-essex-bcpl/</guid>
      <description>
&lt;p&gt;
BCPL - Basic Combined Programming Language - is probably best known as
the ancestor of the C programming language made famous by Unix. But
BCPL was an important and widely used language in its own right. First
implemented by Martin Richards for CTSS, it spread to many different
architectures during the 1970s, especially in the UK where it was used
for teaching computer science, AI and in industry.&lt;/p&gt;
&lt;p&gt;
(Incidentally my first ever job, as an intern in 1990 working for the
former British semiconductor company Inmos, was writing CAD tools
using BCPL on a micro-VAX).&lt;/p&gt;
&lt;div id=&#34;outline-container-headline-1&#34; class=&#34;outline-3&#34;&gt;
&lt;h3 id=&#34;headline-1&#34;&gt;
Essex BCPL for TOPS-10
&lt;/h3&gt;
&lt;div id=&#34;outline-text-headline-1&#34; class=&#34;outline-text-3&#34;&gt;
&lt;p&gt;
The version we are looking at today for TOPS-10 is from the University
of Essex and dates from the mid 1970s. The original compiler by
Richards generated machine code for a generic stack machine, called
OCODE, and the compiler itself was available in OCODE, so it was easy
to port to new machines. Essex produced a version for the ICL 1900 to
start with, and moved this across to TOPS-10 on their new PDP-10
in 1970. They then rewrote the compiler to remove the OCODE layer and
improve performance.&lt;/p&gt;
&lt;p&gt;
This second implementation of BCPL is included in the TOPS-10 6.03
&lt;a href=&#34;https://timereshared.com/tops-10-quick-tour-simh/&#34;&gt;disk images&lt;/a&gt; we are using so there are no special set up instructions.
The compilation system recognises files with a &lt;code&gt;.BCP&lt;/code&gt; extension by
default. Here&amp;#39;s what a hello world program looks like and how to run it:&lt;/p&gt;
&lt;pre class=&#34;example&#34;&gt;
.type hello.bcp
GET &amp;#34;BCL:BCPLIB&amp;#34;
LET START() BE
$(
	WRITES(TTY,&amp;#34;Hello, world*C*L&amp;#34;)
$)

.execute hello.bcp
BCPL:  HELLO	400031/2	32%
LINK:	Loading
[LNKXCT BCPL Execution]
Hello, world

EXIT
&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id=&#34;outline-container-headline-2&#34; class=&#34;outline-3&#34;&gt;
&lt;h3 id=&#34;headline-2&#34;&gt;
TPK in BCPL
&lt;/h3&gt;
&lt;div id=&#34;outline-text-headline-2&#34; class=&#34;outline-text-3&#34;&gt;
&lt;p&gt;
Let&amp;#39;s use the compiler to run the &lt;a href=&#34;https://github.com/timereshared/project-tpk&#34;&gt;TPK algorithm&lt;/a&gt;. The source code can
be found &lt;a href=&#34;https://github.com/timereshared/project-tpk/tree/main/programs/BCPL&#34;&gt;here&lt;/a&gt;. This can be loaded onto the disk using the techniques
described in &lt;a href=&#34;https://timereshared.com/tops-10-getting-data-in-and-out/&#34;&gt;this&lt;/a&gt; article.&lt;/p&gt;
&lt;p&gt;
The TPK formula (√|x | + 5x³) is implemented as a function with a
single expression:&lt;/p&gt;
&lt;div class=&#34;src src-bcpl&#34;&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code class=&#34;language-bcpl&#34; data-lang=&#34;bcpl&#34;&gt;LET TPK(X) = SQRT(#ABS X) #+ 5.0 #* X ** 3&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
As BCPL is typeless, different operators are needed for floating point
and integer arithmetic such as &lt;code&gt;#+&lt;/code&gt; for floating point add. Note also
that &lt;code&gt;#ABS&lt;/code&gt; is a unary operator.&lt;/p&gt;
&lt;p&gt;
However, we have a problem in that &lt;code&gt;SQRT&lt;/code&gt; is not part of the language
library at this point in history. We can implement it using the
Babylonian approximation:&lt;/p&gt;
&lt;div class=&#34;src src-bcpl&#34;&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code class=&#34;language-bcpl&#34; data-lang=&#34;bcpl&#34;&gt;LET SQRT(X) = VALOF
$(
    LET X1, X2 = X, X #/ 2.0
    WHILE #ABS (X1 #- X2) #&amp;gt; 0.0001 DO
    $(
        LET OLD = X2
        X2 := 0.5 #* (X1 #+ (X2 #/ X1))
        X1 := OLD
    $)
    RESULTIS X2
$)&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
This uses a &lt;code&gt;VALOF&lt;/code&gt; expression which yields its results using
&lt;code&gt;RESULTIS&lt;/code&gt;. As there is more than one statement we use a block, marked
by &lt;code&gt;$( ... $)&lt;/code&gt;. Semicolon can be used to separate statements, but is
not needed if there is a single statement per line.&lt;/p&gt;
&lt;p&gt;
Inside the block we define a variable, &lt;code&gt;LET OLD = X2&lt;/code&gt;, but note that
assignment uses &lt;code&gt;:=&lt;/code&gt; ad plain &lt;code&gt;=&lt;/code&gt; is used for comparison.&lt;/p&gt;
&lt;p&gt;
With this, we can supply the driving logic in &lt;code&gt;START&lt;/code&gt;, BCPL&amp;#39;s
equivalent of C&amp;#39;s &lt;code&gt;main&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&#34;src src-bcpl&#34;&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code class=&#34;language-bcpl&#34; data-lang=&#34;bcpl&#34;&gt;// Define constants
MANIFEST $( N = 11; IOVS = 300 $)

// Main program
LET START() BE
$(
    LET A = VEC N
    LET IOVECTOR = VEC IOVS
    INITIALISEIO(IOVECTOR, IOVS)
    WRITE(TTY, &amp;#34;Please enter :N numbers*C*L&amp;#34;, N)
    FOR J = 0 TO N-1 DO A!J := RDF(TTY)
    WRITE(TTY, &amp;#34;Results are*C*L&amp;#34;)
    FOR J = N-1 TO 0 BY -1 DO
    $(
        LET R = TPK(A!J)
        TEST R #&amp;gt; 400.0 THEN
            WRITE(TTY, &amp;#34;Too large*C*L&amp;#34;)
        OR
            WRITE(TTY, &amp;#34;:F*C*L&amp;#34;, R)
     $)
$)&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
BCPL allows both single line comments with &lt;code&gt;//&lt;/code&gt; and block comments
with &lt;code&gt;/* ... */&lt;/code&gt;. C initially only took block comments, with single
line comments first re-implemented by C++ and coming back to C in the
1999 standard.&lt;/p&gt;
&lt;p&gt;
&lt;code&gt;MANIFEST&lt;/code&gt; sets up compile time constants, which we can use when
declaring the stack vector &lt;code&gt;LET A = VEC N&lt;/code&gt;. Elements of this vector
can be accessed using infix &lt;code&gt;!&lt;/code&gt;, eg &lt;code&gt;A!2&lt;/code&gt;. Two &lt;code&gt;FOR&lt;/code&gt; loops are used,
one counting forwards to read in numbers and the second counting
backwards to calculate and print results. BCPL has &lt;code&gt;IF&lt;/code&gt;, but it only
supports a single clause for the true case; &lt;code&gt;TEST ... THEN ... OR&lt;/code&gt;
supports both true and false cases.&lt;/p&gt;
&lt;p&gt;
I/O is done using &lt;code&gt;RDF&lt;/code&gt; to read in a single floating point value and
&lt;code&gt;WRITE&lt;/code&gt; for output. I/O is stream based, and we use the predefined
value &lt;code&gt;TTY&lt;/code&gt; to communicate with the user&amp;#39;s console. &lt;code&gt;INITIALISEIO&lt;/code&gt; is
needed before we use I/O to allocate buffers. &lt;code&gt;WRITE&lt;/code&gt; supports output
of different types using &lt;code&gt;:&lt;/code&gt; as positional markers, eg &lt;code&gt;:F&lt;/code&gt; for a
floating point number. &lt;code&gt;*C*L&lt;/code&gt; in the string means carriage return /
line feed.&lt;/p&gt;
&lt;p&gt;
A full transcript of the program execution can be found &lt;a href=&#34;https://github.com/timereshared/project-tpk/tree/main/listings/DEC%20TOPS-10&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id=&#34;outline-container-headline-3&#34; class=&#34;outline-3&#34;&gt;
&lt;h3 id=&#34;headline-3&#34;&gt;
Further information
&lt;/h3&gt;
&lt;div id=&#34;outline-text-headline-3&#34; class=&#34;outline-text-3&#34;&gt;
&lt;p&gt;
The Github PDP-10 organisation has the &lt;a href=&#34;https://github.com/PDP-10/essex-bcpl&#34;&gt;essex-bcpl&lt;/a&gt; repo which contains
the source tape and manual for the version of the language. There is
also &lt;a href=&#34;https://github.com/PDP-10/MUD1&#34;&gt;MUD1&lt;/a&gt; which is an early multi-user dungeon written in BCPL; this
looks like it needs TOPS-10 7.03 and a KI CPU to run, however.&lt;/p&gt;
&lt;p&gt;
A completely separate implementation of BCPL on TENEX from BBN can
also be found at &lt;a href=&#34;https://github.com/PDP-10/tenex-bcpl&#34;&gt;tenex-bcpl&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;
The Computer History Museum Software Preservation Group has a detailed
&lt;a href=&#34;https://softwarepreservation.computerhistory.org/BCPL/&#34;&gt;history&lt;/a&gt; of BCPL, including links to documents, papers and other
implementations.&lt;/p&gt;
&lt;p&gt;
The classic reference to BCPL (and what I originally leaned the
language from) is &amp;#34;BCPL - the language and its compiler&amp;#34; by Martin
Richards and Colin Whitby-Strevens; there&amp;#39;s a copy at the &lt;a href=&#34;https://archive.org/details/richards1979bcpl/mode/1up&#34;&gt;Internet
Archive&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;
Martin Richards continues to work on BCPL and his &lt;a href=&#34;https://www.cl.cam.ac.uk/~mr10/index.html&#34;&gt;home page&lt;/a&gt; has links
to implementations for modern computers.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id=&#34;outline-container-headline-4&#34; class=&#34;outline-3&#34;&gt;
&lt;h3 id=&#34;headline-4&#34;&gt;
Questions, corrections, comments
&lt;/h3&gt;
&lt;div id=&#34;outline-text-headline-4&#34; class=&#34;outline-text-3&#34;&gt;
&lt;p&gt;
I welcome any questions or comments, and also especially any
corrections if I have got something wrong. Please email me at
rupert@timereshared.com and I will add it here and update the main
text.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
</description>
    </item>
    
  </channel>
</rss>
