BCPL - Wikiwand

BCPL

维基百科，自由的百科全书

编程范型 过程式，命令式，结构化 马丁·理察德 1966 CPL B语言（间接影响C语言）

Richards试著移除了CPL中最复杂的组成，第一支BCPL compiler在IBM 7094电脑中完成。

BCPL
```LET FUNC foo(a) =  VALOF
{ b := a + 1
RESULTIS b }
```
C语言改良自BCPL
```for (int i =  0; i < 10; i++)
{
printf("%d", i);
}
```

范例

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)
```
```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
}
```

参考文献

• 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