From Seo Wiki - Search Engine Optimization and Programming Languages

Jump to: navigation, search
Paradigm procedural, imperative, structured
Appeared in 1966
Designed by Martin Richards
Influenced by CPL
Influenced B (indirectly C)

BCPL (Basic Combined Programming Language) is a computer programming language designed by Martin Richards of the University of Cambridge in 1966.



Originally intended for writing compilers for other languages, BCPL is no longer in common use. However, its influence is still felt because a stripped down version of BCPL, called B, was the language upon which the C programming language was based. BCPL was the first curly bracket programming language, and the curly brackets survived the syntactical changes and have become a common means of denoting program source code statements. In practice, on limited keyboards of the day, source programs often used the sequences $( and $) in place of the symbols { and }. The single-line '//' comments of BCPL, which were not taken up in C, reappeared in C++, and later in C99.

BCPL was a response to difficulties with its predecessor CPL, created during the early 1960s; Richards created BCPL by "removing those features of the full language which make compilation difficult". The first compiler implementation, for the IBM 7094 under CTSS, was written while Richards was visiting Project MAC at MIT in the spring of 1967. The language was first described in a paper presented to the 1969 Spring Joint Computer Conference.

The language is clean, powerful, and portable. It therefore proved possible to write small and simple compilers for it; reputedly some compilers could be run in 16 kilobytes. In addition, the Richards compiler, itself written in BCPL, was easily portable. BCPL was therefore a popular choice for bootstrapping a system.

A major reason for the compiler's portability lay in its structure. It was split into two parts: the front end parsed the source and generated O-code for a virtual machine, and the back end took the O-code and translated it into the code for the target machine. Only 1/5th of the compiler's code needed to be rewritten to support a new machine, a task that usually took between 2 and 5 man-months. Soon afterwards this structure became fairly common practice, cf. Pascal or Java, but the Richards BCPL compiler was the first to define a virtual machine for this purpose.

The language is unusual in having only one data type: a word, a fixed number of bits, usually chosen to align with the architecture's machine word and of adequate capacity to represent any valid storage address. For many machines of the time, this data type was a 16-bit word. This choice later proved to be a significant problem when BCPL was used on machines in which the smallest addressable item was not a word, but a byte or on machines with larger word sizes: 32-bit and 64-bit words, which allowed them to manage large address spaces.

The interpretation of any value was determined by the operators used to process the values. (For example, + added two values together treating them as integers; ! indirected through a value, effectively treating it as a pointer.) In order for this to work, the implementation provided no type checking. The Hungarian Notation was developed to help programmers avoid inadvertent type errors.

The mismatch between BCPL's word orientation and byte-oriented hardware was addressed in a number of ways. One was the provision of standard library routines for packing and unpacking words into byte strings. Later, two language features—the bit-field selection operator and the infix byte indirection operator (denoted by the '%' character) – were added.

BCPL handles bindings spanning separate compilation units in a unique way. There are no user-declarable global variables; instead there is a global vector, which is similar to "blank common" in Fortran. All data shared between different compilation units comprises scalars and pointers to vectors stored in a pre-arranged place in the global vector. Thus the header files (files included during compilation using the "GET" directive) become the primary means of synchronizing global data between compilation units, containing "GLOBAL" directives that present lists of symbolic names, each paired with a number that associates the name with the corresponding numerically addressed word in the global vector. As well as variables, the global vector also contains bindings for external procedures. This makes dynamic loading of compilation units very simple to achieve. Instead of relying on the link loader of the underlying implementation, effectively BCPL gives the programmer control of the linking process.

The global vector also made it very simple to replace or augment standard library routines. A program could save the pointer from the global vector to the original routine and replace it with a pointer to an alternative version. The alternative might call the original as part of its processing. This could be used as a quick ad-hoc debugging aid.

BCPL is reputedly the language in which the original hello world program was written.[citation needed] The first MUD was also written in BCPL [1].

Several operating systems were written partially or wholly in BCPL (for example, TRIPOS and significant parts of AmigaOS, including Kickstart and the earliest versions of AmigaDOS). BCPL was also the initial language used in the seminal Xerox PARC Alto project, the first modern personal computer; among other projects, the Bravo document preparation system was written in BCPL.

By 1970, implementations existed for the Honeywell 635 and 645, the IBM 360, the TX-2, the CDC 6400, the Univac 1108, the PDP-9, the KDF 9 and the Atlas 2. There was also a version produced for the BBC Micro in the mid 1980s by a Richards Computer Products, a company run mainly by the brother of Dr. Martin Richards. The BBC Domesday Project made use of the language. Versions of BCPL for the Amstrad CPC and Amstrad PCW computers were also released in 1986 by UK software house Arnor Ltd.

In 1979 implementations of BCPL existed for at least 25 architectures; in 2001 it sees little use.

The philosophy of BCPL can be summarised by quoting from the book BCPL, the language and its compiler:

The philosophy of BCPL is not one of the tyrant who thinks he knows best and lays down the law on what is and what is not allowed; rather, BCPL acts more as a servant offering his services to the best of his ability without complaint, even when confronted with apparent nonsense. The programmer is always assumed to know what he is doing and is not hemmed in by petty restrictions.

The design, and philosophy, of BCPL strongly influenced B, which in turn influenced C.


These complete and compilable examples are from Martin Richards' BCPL distribution.

Printing factorials:

GET "libhdr"

LET start() = VALOF
$( FOR i = 1 TO 5 DO writef("fact(%n) = %i4*n", i, fact(i))

AND fact(n) = n=0 -> 1, n*fact(n-1)

Counting solutions to the N queens problem:

GET "libhdr"
GLOBAL $( count:200; all:201  $)
LET try(ld, row, rd) BE TEST row=all

                        THEN count := count + 1

                        ELSE $( LET poss = all & ~(ld | row | rd)
                               UNTIL poss=0 DO
                               $( LET p = poss & -poss
                                 poss := poss - p
                                 try(ld+p << 1, row+p, rd+p >> 1)

LET start() = VALOF
$( all := 1
  FOR i = 1 TO 12 DO
  $( count := 0
    try(0, 0, 0)
    writef("Number of solutions to %i2-queens is %i5*n", i, count)
    all := 2*all + 1



  • Martin Richards, The BCPL Reference Manual (Memorandum M-352, Project MAC, Cambridge, July, 1967)
  • Martin Richards, BCPL - a tool for compiler writing and systems programming (Proceedings of the Spring Joint Computer Conference, Vol 34, pp 557–566, 1969)
  • Martin Richards, Arthur Evans, Robert F. Mabee, The BCPL Reference Manual (MAC TR-141, Project MAC, Cambridge, 1974)
  • Martin Richards, C. Whitby-Strevens, BCPL, the language and its compiler (Cambridge University Press, 1980) ISBN 0-521-28681-6

External links

ca:BCPL da:BCPL de:Basic Combined Programming Language es:BCPL fa:بی‌سی‌پی‌ال fr:BCPL gl:BCPL id:BCPL it:BCPL nl:BCPL ja:BCPL pl:BCPL pt:BCPL ru:BCPL fi:BCPL zh:BCPL

Personal tools

Served in 0.210 secs.