编程范型 | 过程式,指令式,结构化 |
---|---|
設計者 | 馬丁·理察德 |
发行时间 | 1967年[1] |
型態系統 | 无类型(所有东西都是字) |
網站 | www |
啟發語言 | |
CPL | |
影響語言 | |
B语言(间接影响C语言) |
基本組合編程語言(英語:Basic Combined Programming Language),是一種電腦程式設計語言,源自更早的CPL語言,1967年由劍橋大學的馬丁·理察德所發展出來的[1] 。
Richards試著移除了CPL中最複雜的組成,第一支BCPL compiler在IBM 7094電腦中完成。身為早期程式語言的BCPL,如今已不再廣泛使用,但它的影響卻是深遠的,今日流行的C語言即是參考BCPL所設計[2]。BCPL被认定为第一个花括号编程语言[3],作为BCPL后代语言,C语言使用花括号来表示块结构。
下列是馬丁查理斯的BCPL发行中的范例。
打印阶乘:
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)
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
$)
Historically BCPL used the symbols$(
and$)
to bracket commands and declarations. These symbols are called section brackets and are allowed to be followed by tags composed of letters, digits, dots and underlines. A tagged closing section bracket is forced to match with its corresponding open section bracket by the automatic insertion of extra closing brackets. Use of this mechanism is no longer recommended since it often leads to obscure programming errors. BCPL has been extended to allow all untagged section brackets to be replaced by{
and}
as appropriate.