BCPL
Encyclopedia
BCPL is a procedural
Procedural programming
Procedural programming can sometimes be used as a synonym for imperative programming , but can also refer to a programming paradigm, derived from structured programming, based upon the concept of the procedure call...

, imperative
Imperative programming
In computer science, imperative programming is a programming paradigm that describes computation in terms of statements that change a program state...

, and structured
Structured programming
Structured programming is a programming paradigm aimed on improving the clarity, quality, and development time of a computer program by making extensive use of subroutines, block structures and for and while loops - in contrast to using simple tests and jumps such as the goto statement which could...

 computer
Computer
A computer is a programmable machine designed to sequentially and automatically carry out a sequence of arithmetic or logical operations. The particular sequence of operations can be changed readily, allowing the computer to solve more than one kind of problem...

 programming language
Programming language
A programming language is an artificial language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely....

 designed by Martin Richards of the University of Cambridge
University of Cambridge
The University of Cambridge is a public research university located in Cambridge, United Kingdom. It is the second-oldest university in both the United Kingdom and the English-speaking world , and the seventh-oldest globally...

 in 1966.

Design

Originally intended for writing compiler
Compiler
A compiler is a computer program that transforms source code written in a programming language into another computer language...

s for other languages, BCPL is no longer in common use. However, its influence is still felt because a stripped down and syntactically changed version of BCPL, called B, was the language on which the C programming language
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....

 was based. This important fact led many C programmers to humorously issue the backronym
Backronym
A backronym or bacronym is a phrase constructed purposely, such that an acronym can be formed to a specific desired word. Backronyms may be invented with serious or humorous intent, or may be a type of false or folk etymology....

 Before C Programming Language. BCPL was the first brace programming language, and the braces 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
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....

, reappeared in C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...

, and later in C99
C99
C99 is a modern dialect of the C programming language. It extends the previous version with new linguistic and library features, and helps implementations make better use of available computer hardware and compiler technology.-History:...

.

BCPL was a response to difficulties with its predecessor Combined Programming Language
Combined Programming Language
CPL was a multi-paradigm programming language, that was developed in the early 1960s.- Design :...

 (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 Compatible Time-Sharing System (CTSS), was written while Richards was visiting Project MAC at the Massachusetts Institute of Technology
Massachusetts Institute of Technology
The Massachusetts Institute of Technology is a private research university located in Cambridge, Massachusetts. MIT has five schools and one college, containing a total of 32 academic departments, with a strong emphasis on scientific and technological education and research.Founded in 1861 in...

 (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, consistent, powerful, and portable. It thus proved possible to write small and simple compilers for it; reputedly some compilers could be run in 16 kilobyte
Kilobyte
The kilobyte is a multiple of the unit byte for digital information. Although the prefix kilo- means 1000, the term kilobyte and symbol KB have historically been used to refer to either 1024 bytes or 1000 bytes, dependent upon context, in the fields of computer science and information...

s. Further, the Richards compiler, itself written in BCPL, was easily portable. BCPL was thus a popular choice for bootstrapping
Bootstrapping (compilers)
In computer science, bootstrapping is the process of writing a compiler in the target programming language which it is intended to compile...

 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
O-code machine
The O-code machine is a virtual machine that was developed by Martin Richards in the late 1960s to give machine independence to BCPL, the low-level forerunner to C and C++. The concept behind the O-Code machine was to create O-code output through the BCPL compiler. The O-code was then either...

 for a virtual machine
Virtual machine
A virtual machine is a "completely isolated guest operating system installation within a normal host operating system". Modern virtual machines are implemented with either software emulation or hardware virtualization or both together.-VM Definitions:A virtual machine is a software...

, and the back end took the O-code and translated it into the code for the target machine. Only 1/5 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. This approach became common practice later, e.g., Pascal
Pascal (programming language)
Pascal is an influential imperative and procedural programming language, designed in 1968/9 and published in 1970 by Niklaus Wirth as a small and efficient language intended to encourage good programming practices using structured programming and data structuring.A derivative known as Object Pascal...

 or Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...

, 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
Data type
In computer programming, a data type is a classification identifying one of various types of data, such as floating-point, integer, or Boolean, that determines the possible values for that type; the operations that can be done on values of that type; the meaning of the data; and the way values of...

: 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
Byte
The byte is a unit of digital information in computing and telecommunications that most commonly consists of eight bits. Historically, a byte was the number of bits used to encode a single character of text in a computer and for this reason it is the basic addressable element in many computer...

 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 integer
Integer
The integers are formed by the natural numbers together with the negatives of the non-zero natural numbers .They are known as Positive and Negative Integers respectively...

s; ! 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
Hungarian notation
Hungarian notation is an identifier naming convention in computer programming, in which the name of a variable or function indicates its type or intended use...

 was developed to help programmers avoid inadvertent type errors.

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

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
Fortran
Fortran is a general-purpose, procedural, imperative programming language that is especially suited to numeric computation and scientific computing...

. 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 the language in which the original hello world program
Hello world program
A "Hello world" program is a computer program that outputs "Hello world" on a display device. Because it is typically one of the simplest programs possible in most programming languages, it is by tradition often used to illustrate to beginners the most basic syntax of a programming language, or to...

 was written. The first MUD
MUD
A MUD , pronounced , is a multiplayer real-time virtual world, with the term usually referring to text-based instances of these. MUDs combine elements of role-playing games, hack and slash, player versus player, interactive fiction, and online chat...

 was also written in BCPL.

Several operating system
Operating system
An operating system is a set of programs that manage computer hardware resources and provide common services for application software. The operating system is the most important type of system software in a computer system...

s were written partially or wholly in BCPL (for example, TRIPOS
TRIPOS
TRIPOS is a computer operating system. Development started in 1976 at the Computer Laboratory of Cambridge University and it was headed by Dr. Martin Richards. The first version appeared in January 1978 and it originally ran on a PDP-11. Later it was ported to the Computer Automation LSI4 and the...

 and the earliest versions of AmigaDOS
AmigaDOS
AmigaDOS is the disk operating system of the AmigaOS, which includes file systems, file and directory manipulation, the command-line interface, and file redirection....

, a part of AmigaOS
AmigaOS
AmigaOS is the default native operating system of the Amiga personal computer. It was developed first by Commodore International, and initially introduced in 1985 with the Amiga 1000...

). BCPL was also the initial language used in the seminal Xerox PARC
Xerox PARC
PARC , formerly Xerox PARC, is a research and co-development company in Palo Alto, California, with a distinguished reputation for its contributions to information technology and hardware systems....

 Alto project, the first modern personal computer
Personal computer
A personal computer is any general-purpose computer whose size, capabilities, and original sales price make it useful for individuals, and which is intended to be operated directly by an end-user with no intervening computer operator...

; among other projects, the Bravo
Bravo (software)
Bravo was the first WYSIWYG document preparation program. It provided multi-font capability using the bitmap displays on the Xerox Alto personal computer...

 document preparation system was written in BCPL.

By 1970, implementations existed for the Honeywell 635 and Honeywell 645
GE-600 series
The GE-600 series was a family of 36-bit mainframe computers originating in the 1960s, built by General Electric . When GE left the mainframe business the line was sold to Honeywell, who built similar systems into the 1990s as the division moved to Groupe Bull and then NEC.-Architecture:The 600...

, the IBM 360, the TX-2
TX-2
The MIT Lincoln Laboratory TX-2 computer was the successor to the Lincoln TX-0 and was known for its role in advancing both artificial intelligence and human-computer interaction.- Specifications :...

, the CDC 6400
CDC 6400
The CDC 6400, a member of the CDC 6000 series, was a mainframe computer made by Control Data Corporation in the 1960s. The central processing unit was architecturally compatible with the CDC 6600...

, the UNIVAC 1108, the PDP-9, the KDF 9 and the Atlas 2. There was also a version produced for the BBC Micro
BBC Micro
The BBC Microcomputer System, or BBC Micro, was a series of microcomputers and associated peripherals designed and built by Acorn Computers for the BBC Computer Literacy Project, operated by the British Broadcasting Corporation...

 in the mid 1980s by Richards Computer Products, a company started by John Richards, the brother of Dr. Martin Richards. The BBC Domesday Project
BBC Domesday Project
The BBC Domesday Project was a partnership between Acorn Computers Ltd, Philips, Logica and the BBC to mark the 900th anniversary of the original Domesday Book, an 11th century census of England...

 made use of the language. Versions of BCPL for the Amstrad CPC
Amstrad CPC
The Amstrad CPC is a series of 8-bit home computers produced by Amstrad between 1984 and 1990. It was designed to compete in the mid-1980s home computer market dominated by the Commodore 64 and the Sinclair ZX Spectrum, where it successfully established itself primarily in the United Kingdom,...

 and Amstrad PCW
Amstrad PCW
The Amstrad PCW series was a range of personal computers produced by British company Amstrad from 1985 to 1998, and also sold under licence in Europe as the "Joyce" by the German electronics company Schneider in the early years of the series' life. When it was launched, the cost of a PCW system was...

 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 design, and philosophy, of BCPL strongly influenced B, which in turn influenced C
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....

.

There are rumours that BCPL actually stood for "Bootstrap Cambridge Programming Language", however CPL was never created since development stopped at BCPL, and the acronym was reinterpreted for the BCPL book.

Examples

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))
RESULTIS 0
}

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
}

RESULTIS 0
}

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK