kids encyclopedia robot

BCPL facts for kids

Kids Encyclopedia Facts
Quick facts for kids
BCPL
Paradigm procedural, imperative, structured
Designed by Martin Richards
First appeared 1967; 58 years ago (1967)
Typing discipline typeless (everything is a word)
Influenced by
CPL
Influenced
B, C, Go

BCPL (which stands for "Basic Combined Programming Language") is a type of programming language. It helps computers follow instructions in a step-by-step way.

BCPL was first made to write compilers. Compilers are special programs that translate code from one language into another. Even though BCPL isn't used much today, it's very important. This is because it led to the creation of the B language, which then led to the super popular C programming language. BCPL also introduced cool features, like using curly braces `{}` to group code. Martin Richards from the University of Cambridge created BCPL in 1967.

How BCPL Was Designed

BCPL was made so that its compilers could be small and simple. Some of these compilers could even run using only 16 kilobytes of memory! This was a tiny amount of memory for computers back then.

One big reason BCPL was so useful was its design. The compiler was split into two parts. The first part read the code and turned it into an "intermediate language." The second part then translated this into code the computer could understand. This made it easy to use BCPL on different types of computers. You only had to change a small part of the compiler for a new machine. This smart idea later became common for other languages like Pascal and Java.

Working with Data

BCPL is unique because it only has one type of data, called a "word." A word is a fixed number of bits, like a small chunk of computer memory. For many computers at the time, a word was 16 bits long.

The computer understood what a "word" meant based on how you used it. For example, if you used the `+` sign, it treated the words as numbers to add them. If you used `!`, it treated the word as a memory address. BCPL didn't check if you were using the right type of data, which gave programmers a lot of freedom.

Sometimes, computers work with smaller pieces of data called "bytes." BCPL handled this by having special tools to pack and unpack words into bytes. It also added special operators to work with parts of a word or with bytes directly.

Sharing Information

BCPL had a special way for different parts of a program to share information. Instead of global variables, it used a "global vector." Think of this as a shared list where all common data is stored. This made it easy to load different parts of a program and have them work together. It also allowed programmers to easily replace or add new parts to the standard library.

Special Features

BCPL was the first language to use curly braces (`{}`) to mark blocks of code. This idea was so good that it's now a common feature in many programming languages. Back then, some keyboards didn't have curly braces, so people used `$( `and `$)` instead.

Another cool feature BCPL had was single-line comments using `//`. While the C language didn't use this at first, it later reappeared in C++ and newer versions of C.

The people who created BCPL believed in giving programmers a lot of freedom. They thought BCPL should be like a helpful assistant, not a strict boss. It would try its best to do what the programmer asked, even if it seemed a bit strange. This meant programmers had a lot of control over their code.

History of BCPL

Martin Richards first created BCPL in 1967 at the University of Cambridge. He made it because an earlier language, CPL, was too hard to compile. Richards simplified CPL by removing features that made it difficult. He wrote the first compiler for BCPL while visiting the Massachusetts Institute of Technology.

BCPL is famous for being the language where the very first ""Hello, World!" program was written. This simple program just prints "Hello, World!" on the screen. The first online multiplayer game, MUD1, was also written in BCPL.

Many early operating systems, like TRIPOS and early versions of AmigaDOS, used BCPL. It was also the first language used in the Xerox PARC Alto project. The Alto was one of the first modern personal computers. A document writing program called Bravo was also written in BCPL for the Alto.

By the early 1970s, BCPL could run on many different types of computers. This showed how flexible and portable the language was.

In the 1980s, versions of BCPL were made for popular home computers like the BBC Micro, Amstrad CPC, and Amstrad PCW. There was even a version for the Apple Macintosh.

BCPL's design and ideas greatly influenced the B language, which then influenced the C language. Today, C++ is often seen as the next step after C.

Over time, as C became more popular, BCPL was used less often. However, Martin Richards still keeps a modern version of BCPL available on his website. He even uses it for his own research!

Examples

Hello World

Here's how the famous "Hello, World!" program looks in BCPL:

GET "LIBHDR"
LET START() BE WRITES("Hello, World")

More Examples

Here's a program that calculates and prints factorials (like 5! = 5 * 4 * 3 * 2 * 1):

GET "LIBHDR"

LET START() = VALOF $(
        FOR I = 1 TO 5 DO
                WRITEF("%N! = %I4*N", I, FACT(I))
        RESULTIS 0
$)

AND FACT(N) = N = 0 -> 1, N * FACT(N - 1)

This program solves the N queens problem. It finds how many ways you can place N queens on a chessboard so that none of them can attack each other:

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("%I2-QUEENS PROBLEM HAS %I5 SOLUTIONS*N", I, COUNT)
                ALL := 2 * ALL + 1
        $)
        RESULTIS 0
$)
kids search engine
BCPL Facts for Kids. Kiddle Encyclopedia.