For faster navigation, this Iframe is preloading the Wikiwand page for B语言.

B语言

B语言
设计者肯·汤普森
实作者肯·汤普森丹尼斯·利奇
发行时间1969年,​55年前​(1969[1]
型态系统无类型(所有东西都是
文件扩展名.b
启发语言
BCPL, PL/I, TMG英语TMG (language)
影响语言
C语言

B语言是一种通用的程序设计语言。自从被C语言取代之后,它几乎已遭弃置。

B语言大约是于1969年时由美国贝尔实验室电脑科学家──肯·汤普森丹尼斯·利奇的支持下设计出来的。肯·汤普森最初想在UNIX上开发一个Fortran编译器,但后来引进了BCPL的风格,形成一个新的语言。

后来,丹尼斯·利奇以B语言为基础开发出C语言,至此C语言渐渐发展成为目前世界上最常用的编程语言之一。

例子

下面是肯·汤普森在《B用户参考》中提供的源代码[2]

/* The following function will print a non-negative number, n, to
   the base b, where 2<=b<=10.  This routine uses the fact that
   in the ASCII character set, the digits 0 to 9 have sequential
   code values.  */

printn(n, b) {
    extrn putchar;
    auto a;
    /* Wikipedia note: auto declares a variable with automatic
       storage (lifetime is function scope), not "automatic typing"
       as in C++11. */

    if (a = n / b) /* assignment, not test for equality */
        printn(a, b); /* recursive */
    putchar(n % b + '0');
}
/* The following program will calculate the constant e-2 to about
   4000 decimal digits, and print it 50 characters to the line in
   groups of 5 characters.  The method is simple output conversion
   of the expansion
     1/2! + 1/3! + ... = .111....
   where the bases of the digits are 2, 3, 4, . . . */

main() {
    extrn putchar, n, v;
    auto i, c, col, a;

    i = col = 0;
    while(i<n)
        v[i++] = 1;
    while(col<2*n) {
        a = n+1 ;
        c = i = 0;
        while (i<n) {
            c =+ v[i] *10;
            v[i++]  = c%a;
            c =/ a--;
        }
        putchar(c+'0');
        if(!(++col%5))
            putchar(col%50?' ': '*n');
    }
    putchar('*n*n');
}
v[2000];
n 2000;

参见

引用

  1. ^ B - computer programming language. [2021-03-14]. (原始内容存档于2015-02-10). 
  2. ^ Thompson, Ken. Users' Reference to B (PDF). Bell Laboratories. 7 January 1972 [21 March 2014]. (原始内容 (PDF)存档于17 March 2015). 

外部链接

{{bottomLinkPreText}} {{bottomLinkText}}
B语言
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?