B (programming language): Difference between revisions
Citation bot (talk | contribs) Add: website. | Use this bot. Report bugs. | Suggested by Whoop whoop pull up | Category:Programming languages | #UCB_Category 95/202 |
→Examples: typo Tags: Mobile edit Mobile web edit |
||
(22 intermediate revisions by 20 users not shown) | |||
Line 1: | Line 1: | ||
{{Short description|Procedural programming language}} |
{{Short description|Procedural programming language}} |
||
{{about|a language developed at Bell Labs|"b" language of Meertens and Pemberton|ABC (programming language)|other uses|B (disambiguation)}} |
{{about|a programming language developed at Bell Labs|"b" language of Meertens and Pemberton|ABC (programming language)|other uses|B (disambiguation)}} |
||
{{Infobox programming language |
{{Infobox programming language |
||
| name |
| name = B |
||
| logo |
| logo = |
||
| caption |
| caption = |
||
| paradigm |
| paradigm = |
||
| year |
| year = {{start date and age|1969}}<ref>{{cite web|url=http://www.britannica.com/EBchecked/topic/1663863/B|title=B - computer programming language}}</ref> |
||
| designer |
| designer = [[Ken Thompson (computer programmer)|Ken Thompson]] |
||
| developer |
| developer = [[Ken Thompson (computer programmer)|Ken Thompson]], [[Dennis Ritchie]] |
||
| latest_release_version = |
| latest_release_version = |
||
| latest_release_date |
| latest_release_date = |
||
| latest_test_version |
| latest_test_version = |
||
| latest_test_date |
| latest_test_date = |
||
| turing-complete |
| turing-complete = yes |
||
| typing |
| typing = typeless (everything is a [[Word (computer architecture)|word]]) |
||
| implementations |
| implementations = |
||
| dialects |
| dialects = |
||
| influenced_by |
| influenced_by = [[BCPL]], [[PL/I]], [[TMG (language)|TMG]] |
||
| influenced |
| influenced = [[C (programming language)|C]] |
||
| operating_system |
| operating_system = |
||
| license |
| license = |
||
| website |
| website = |
||
| file_ext |
| file_ext = .b |
||
}} |
}} |
||
'''B''' is a [[programming language]] developed at [[Bell Labs]] circa 1969 |
'''B''' is a [[programming language]] developed at [[Bell Labs]] circa 1969 by [[Ken Thompson (computer programmer)|Ken Thompson]] and [[Dennis Ritchie]]. |
||
B was derived from [[BCPL]], and its name may possibly be a contraction of BCPL. Thompson's coworker Dennis Ritchie speculated that the name might be based on Bon, an earlier, but unrelated, programming language that Thompson designed for use on [[Multics]].{{refn|group=note|"Its name most probably represents a contraction of BCPL, though an alternate theory holds that it derives from Bon [Thompson 69], an unrelated language created by Thompson during the Multics days. Bon in turn was named either after his wife Bonnie or (according to an encyclopedia quotation in its manual), after [[Bon|a religion]] whose rituals involve the murmuring of magic formulas."<ref name="chist">{{cite journal| first = Dennis M.| last = Ritchie| author-link = Dennis Ritchie| title = The Development of the C Language| date=March 1993 | journal = ACM SIGPLAN Notices| volume = 28 | issue = 3| pages = 201–208| url = http://www.bell-labs.com/usr/dmr/www/chist.html| doi = 10.1145/155360.155580}}</ref>}} |
B was derived from [[BCPL]], and its name may possibly be a contraction of BCPL. Thompson's coworker Dennis Ritchie speculated that the name might be based on Bon, an earlier, but unrelated, programming language that Thompson designed for use on [[Multics]].{{refn|group=note|"Its name most probably represents a contraction of BCPL, though an alternate theory holds that it derives from Bon [Thompson 69], an unrelated language created by Thompson during the Multics days. Bon in turn was named either after his wife Bonnie or (according to an encyclopedia quotation in its manual), after [[Bon|a religion]] whose rituals involve the murmuring of magic formulas."<ref name="chist">{{cite journal| first = Dennis M.| last = Ritchie| author-link = Dennis Ritchie| title = The Development of the C Language| date=March 1993 | journal = ACM SIGPLAN Notices| volume = 28 | issue = 3| pages = 201–208| url = http://www.bell-labs.com/usr/dmr/www/chist.html| doi = 10.1145/155360.155580|doi-access = free}}</ref>}} |
||
B was designed for recursive, non-numeric, machine-independent applications, such as system and language software.<ref name=bur>{{cite web |
B was designed for recursive, non-numeric, machine-independent applications, such as system and language software.<ref name=bur>{{cite web |
||
Line 42: | Line 42: | ||
}}</ref> It was a typeless language, with the only data type being the underlying machine's natural [[memory word]] format, whatever that might be. Depending on the context, the word was treated either as an [[integer]] or a [[memory address]]. |
}}</ref> It was a typeless language, with the only data type being the underlying machine's natural [[memory word]] format, whatever that might be. Depending on the context, the word was treated either as an [[integer]] or a [[memory address]]. |
||
As machines with [[ASCII]] processing became common, notably the [[DEC PDP-11]] that arrived at Bell, support for character data stuffed in memory words became important. The typeless nature of the language was seen as a disadvantage, which led Thompson and Ritchie to develop an expanded version of the language supporting new internal and user-defined types, which became the [[C programming language]]. |
As machines with [[ASCII]] processing became common, notably the [[DEC PDP-11]] that arrived at Bell Labs, support for character data stuffed in memory words became important. The typeless nature of the language was seen as a disadvantage, which led Thompson and Ritchie to develop an expanded version of the language supporting new internal and user-defined types, which became the [[C programming language]]. |
||
== History == |
== History == |
||
{{rquote|quote=BCPL semantics with a lot of SMALGOL syntax|author=Ken Thompson|source=<ref name=Ars>{{cite web |last1=Jensen |first1=Richard |title="A damn stupid thing to do"—the origins of C |url=https://arstechnica.com/features/2020/12/a-damn-stupid-thing-to-do-the-origins-of-c/ |website=Ars Technica |access-date=2022-03-28 |language=en-us |date=9 December 2020}}</ref>}} |
|||
Circa 1969, Ken Thompson<ref name=chist /> and later Dennis Ritchie<ref name=bur /> developed B basing it mainly on the [[BCPL]] language Thompson used in the [[Multics]] project. B was essentially the BCPL system stripped of any component Thompson felt he could do without in order to make it fit within the memory capacity of the minicomputers of the time. The BCPL to B transition also included changes made to suit Thompson's preferences (mostly along the lines of reducing the number of non-whitespace characters in a typical program).<ref name=chist /> Much of the typical [[ALGOL]]-like syntax of BCPL was rather heavily changed in this process. The assignment operator <code>:=</code> reverted to the <code>=</code> of [[Heinz Rutishauser|Rutishauser]]'s [[Superplan]], and the equality operator <code>=</code> was replaced by <code>==</code>. |
Circa 1969, Ken Thompson<ref name=chist /> and later Dennis Ritchie<ref name=bur /> developed B basing it mainly on the [[BCPL]] language Thompson used in the [[Multics]] project. B was essentially the BCPL system stripped of any component Thompson felt he could do without in order to make it fit within the memory capacity of the minicomputers of the time. The BCPL to B transition also included changes made to suit Thompson's preferences (mostly along the lines of reducing the number of non-whitespace characters in a typical program).<ref name=chist /> Much of the typical [[ALGOL]]-like syntax of BCPL was rather heavily changed in this process. The assignment operator <code>:=</code> reverted to the <code>=</code> of [[Heinz Rutishauser|Rutishauser]]'s [[Superplan]], and the equality operator <code>=</code> was replaced by <code>==</code>. |
||
Line 54: | Line 56: | ||
In Thompson's words: "B and the old old C were very very similar languages except for all the types [in C]".<ref name="ken"/> |
In Thompson's words: "B and the old old C were very very similar languages except for all the types [in C]".<ref name="ken"/> |
||
Early implementations were for the DEC [[PDP-7]] and [[PDP-11]] minicomputers using early [[Unix]], and [[Honeywell]] {{nowrap|[[GE-600 series|GE 645]]}}<ref name="Evolution">{{cite journal |first=Dennis M. |last=Ritchie |title=The Evolution of the Unix Time-sharing System |url=https://www.bell-labs.com/usr/dmr/www/hist.html |archive-url=https://web.archive.org/web/20150611114353/https://www.bell-labs.com/usr/dmr/www/hist.html |archive-date=11 June 2015 |journal=AT&T Bell Laboratories Technical Journal |volume=63 |number=6 Part 2 |year=1984 |pages=1577–1593|doi=10.1002/j.1538-7305.1984.tb00054.x }}</ref> 36-bit mainframes running the operating system [[General Comprehensive Operating System|GCOS]]. The earliest PDP-7 implementations compiled to [[threaded code]], and Ritchie wrote a compiler using [[TMG (language)|TMG]] which produced machine code.<ref>{{cite web |url=http://www.multicians.org/tmg.html |title=TMG |publisher=multicians.org}}</ref><ref>{{cite web |url=https://www.bell-labs.com/usr/dmr/www/chist.html |archive-url=https://web.archive.org/web/20150611114355/https://www.bell-labs.com/usr/dmr/www/chist.html |archive-date=11 June 2015 |title=The Development of the C Language |first=Dennis M. |last=Ritchie |author-link=Dennis Ritchie |publisher=Bell Labs/Lucent Technologies}}</ref><ref name="reader">{{cite |
Early implementations were for the DEC [[PDP-7]] and [[PDP-11]] minicomputers using early [[Unix]], and [[Honeywell]] {{nowrap|[[GE-600 series|GE 645]]}}<ref name="Evolution">{{cite journal |first=Dennis M. |last=Ritchie |title=The Evolution of the Unix Time-sharing System |url=https://www.bell-labs.com/usr/dmr/www/hist.html |archive-url=https://web.archive.org/web/20150611114353/https://www.bell-labs.com/usr/dmr/www/hist.html |archive-date=11 June 2015 |journal=AT&T Bell Laboratories Technical Journal |volume=63 |number=6 Part 2 |year=1984 |pages=1577–1593|doi=10.1002/j.1538-7305.1984.tb00054.x }}</ref> 36-bit mainframes running the operating system [[General Comprehensive Operating System|GCOS]]. The earliest PDP-7 implementations compiled to [[threaded code]], and Ritchie wrote a compiler using [[TMG (language)|TMG]] which produced machine code.<ref>{{cite web |url=http://www.multicians.org/tmg.html |title=TMG |publisher=multicians.org}}</ref><ref>{{cite web |url=https://www.bell-labs.com/usr/dmr/www/chist.html |archive-url=https://web.archive.org/web/20150611114355/https://www.bell-labs.com/usr/dmr/www/chist.html |archive-date=11 June 2015 |title=The Development of the C Language |first=Dennis M. |last=Ritchie |author-link=Dennis Ritchie |publisher=Bell Labs/Lucent Technologies}}</ref><ref name="reader">{{cite tech report |first1=M. D. |last1=McIlroy |author-link1=Douglas McIlroy |year=1987 |url=http://www.cs.dartmouth.edu/~doug/reader.pdf |archive-url=https://ghostarchive.org/archive/20221009/http://www.cs.dartmouth.edu/~doug/reader.pdf |archive-date=2022-10-09 |url-status=live |title=A Research Unix reader: annotated excerpts from the Programmer's Manual, 1971–1986 |series=CSTR |number=139 |institution=Bell Labs}}</ref> In 1970 a PDP-11 was acquired and threaded code was used for the port; an assembler, {{samp|[[dc (Unix)|dc]]}}, and the B language itself were written in B to [[Bootstrapping|bootstrap]] the computer. An early version of [[yacc]] was produced with this PDP-11 configuration. Ritchie took over maintenance during this period.<ref name=chist />{{r|reader}} |
||
The typeless nature of B made sense on the Honeywell, PDP-7 and many older computers, but was a problem on the PDP-11 because it was difficult to elegantly access the character data type that the PDP-11 and most modern computers fully support. Starting in 1971 Ritchie made changes to the language while converting its compiler to produce machine code, most notably adding data typing for variables. During 1971 and 1972 B evolved into "New B" (NB) and then C.<ref name=chist /> |
The typeless nature of B made sense on the Honeywell, PDP-7 and many older computers, but was a problem on the PDP-11 because it was difficult to elegantly access the character data type that the PDP-11 and most modern computers fully support. Starting in 1971 Ritchie made changes to the language while converting its compiler to produce machine code, most notably adding data typing for variables. During 1971 and 1972 B evolved into "New B" (NB) and then C.<ref name=chist /> |
||
Line 81: | Line 83: | ||
/* The following function will print a non-negative number, n, to |
/* The following function will print a non-negative number, n, to |
||
the base b, where 2<=b<=10. This routine uses the fact that |
the base b, where 2<=b<=10. This routine uses the fact that |
||
in the |
in the ANSCII character set, the digits 0 to 9 have sequential |
||
code values. */ |
code values. */ |
||
printn(n, |
printn(n,b) { |
||
extrn putchar; |
|||
auto a; |
|||
/* Wikipedia note: the auto keyword 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'); |
|||
} |
} |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
Line 100: | Line 102: | ||
/* The following program will calculate the constant e-2 to about |
/* The following program will calculate the constant e-2 to about |
||
4000 decimal digits, and print it 50 characters to the line in |
4000 decimal digits, and print it 50 characters to the line in |
||
groups of 5 characters. The method is simple output |
groups of 5 characters. The method is simple output conver- |
||
of the expansion |
sion of the expansion |
||
1/2! + 1/3! + ... = .111 |
1/2! + 1/3! + ... = .111... |
||
where the bases of the digits are 2, 3, 4, . |
where the bases of the digits are 2, 3, 4, ... */ |
||
main() { |
main() { |
||
extrn putchar, n, v; |
|||
auto i, c, col, a; |
|||
i = col = 0; |
|||
while(i<n) |
|||
v[i++] = 1; |
|||
⚫ | |||
⚫ | |||
⚫ | |||
while (i<n) { |
|||
⚫ | |||
⚫ | |||
⚫ | |||
} |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
while(i<n) { |
|||
} |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
} |
|||
⚫ | |||
⚫ | |||
⚫ | |||
} |
|||
⚫ | |||
} |
} |
||
v[2000]; |
v[2000]; |
||
n 2000; |
n 2000; |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
== See also == |
|||
⚫ | |||
== Notes == |
== Notes == |
||
Line 141: | Line 141: | ||
== External links == |
== External links == |
||
* |
* [http://man.cat-v.org/unix-1st/1/b Manual page for b(1) from Unix First Edition] |
||
* |
* [https://www.bell-labs.com/usr/dmr/www/chist.html The Development of the C Language], [[Dennis Ritchie|Dennis M. Ritchie]]. Puts B in the context of [[BCPL]] and [[C (programming language)|C]]. |
||
* ''[https://www.bell-labs.com/usr/dmr/www/kbman.html Users' Reference to B]'', Ken Thompson. Describes the [[PDP-11]] version. |
* ''[https://www.bell-labs.com/usr/dmr/www/kbman.html Users' Reference to B]'', Ken Thompson. Describes the [[PDP-11]] version. |
||
* |
* [https://www.bell-labs.com/usr/dmr/www/bintro.html The Programming Language B], S. C. Johnson & B. W. Kernighan, Technical Report CS TR 8, [[Bell Labs]] (January 1973). The [[General Comprehensive Operating System|GCOS]] version on [[Honeywell]] equipment. |
||
* |
* [http://www.thinkage.ca/english/gcos/expl/b/index.html B Language Reference Manual], Thinkage Ltd. The production version of the language as used on GCOS, including language and runtime library. |
||
{{Ken Thompson navbox}} |
{{Ken Thompson navbox}} |
||
{{Programming languages}} |
{{Programming languages}} |
||
⚫ | |||
[[Category:Procedural programming languages]] |
[[Category:Procedural programming languages]] |
Latest revision as of 23:06, 17 August 2024
Designed by | Ken Thompson |
---|---|
Developer | Ken Thompson, Dennis Ritchie |
First appeared | 1969[1] |
Typing discipline | typeless (everything is a word) |
Filename extensions | .b |
Influenced by | |
BCPL, PL/I, TMG | |
Influenced | |
C |
B is a programming language developed at Bell Labs circa 1969 by Ken Thompson and Dennis Ritchie.
B was derived from BCPL, and its name may possibly be a contraction of BCPL. Thompson's coworker Dennis Ritchie speculated that the name might be based on Bon, an earlier, but unrelated, programming language that Thompson designed for use on Multics.[note 1]
B was designed for recursive, non-numeric, machine-independent applications, such as system and language software.[3] It was a typeless language, with the only data type being the underlying machine's natural memory word format, whatever that might be. Depending on the context, the word was treated either as an integer or a memory address.
As machines with ASCII processing became common, notably the DEC PDP-11 that arrived at Bell Labs, support for character data stuffed in memory words became important. The typeless nature of the language was seen as a disadvantage, which led Thompson and Ritchie to develop an expanded version of the language supporting new internal and user-defined types, which became the C programming language.
History
[edit]BCPL semantics with a lot of SMALGOL syntax
— Ken Thompson, [4]
Circa 1969, Ken Thompson[2] and later Dennis Ritchie[3] developed B basing it mainly on the BCPL language Thompson used in the Multics project. B was essentially the BCPL system stripped of any component Thompson felt he could do without in order to make it fit within the memory capacity of the minicomputers of the time. The BCPL to B transition also included changes made to suit Thompson's preferences (mostly along the lines of reducing the number of non-whitespace characters in a typical program).[2] Much of the typical ALGOL-like syntax of BCPL was rather heavily changed in this process. The assignment operator :=
reverted to the =
of Rutishauser's Superplan, and the equality operator =
was replaced by ==
.
Thompson added "two-address assignment operators" using x =+ y
syntax to add y to x (in C the operator is written +=
). This syntax came from Douglas McIlroy's implementation of TMG, in which B's compiler was first implemented (and it came to TMG from ALGOL 68's x +:= y
syntax).[2][5] Thompson went further by inventing the increment and decrement operators (++
and --
). Their prefix or postfix position determines whether the value is taken before or after alteration of the operand. This innovation was not in the earliest versions of B. According to Dennis Ritchie, people often assumed that they were created for the auto-increment and auto-decrement address modes of the DEC PDP-11, but this is historically impossible as the machine didn't exist when B was first developed.[2]
The semicolon version of the for loop was borrowed by Ken Thompson from the work of Stephen Johnson.[6]
B is typeless, or more precisely has one data type: the computer word. Most operators (e.g. +
, -
, *
, /
) treated this as an integer, but others treated it as a memory address to be dereferenced. In many other ways it looked a lot like an early version of C. There are a few library functions, including some that vaguely resemble functions from the standard I/O library in C.[3]
In Thompson's words: "B and the old old C were very very similar languages except for all the types [in C]".[6]
Early implementations were for the DEC PDP-7 and PDP-11 minicomputers using early Unix, and Honeywell GE 645[7] 36-bit mainframes running the operating system GCOS. The earliest PDP-7 implementations compiled to threaded code, and Ritchie wrote a compiler using TMG which produced machine code.[8][9][10] In 1970 a PDP-11 was acquired and threaded code was used for the port; an assembler, dc, and the B language itself were written in B to bootstrap the computer. An early version of yacc was produced with this PDP-11 configuration. Ritchie took over maintenance during this period.[2][10]
The typeless nature of B made sense on the Honeywell, PDP-7 and many older computers, but was a problem on the PDP-11 because it was difficult to elegantly access the character data type that the PDP-11 and most modern computers fully support. Starting in 1971 Ritchie made changes to the language while converting its compiler to produce machine code, most notably adding data typing for variables. During 1971 and 1972 B evolved into "New B" (NB) and then C.[2]
B is almost extinct, having been superseded by the C language.[11] However, it continues to see use on GCOS mainframes (as of 2014[update])[12] and on certain embedded systems (as of 2000[update]) for a variety of reasons: limited hardware in small systems, extensive libraries, tooling, licensing cost issues, and simply being good enough for the job.[11] The highly influential AberMUD was originally written in B.
Examples
[edit]The following examples are from the Users' Reference to B by Ken Thompson:[3]
/* 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 ANSCII character set, the digits 0 to 9 have sequential
code values. */
printn(n,b) {
extrn putchar;
auto a;
/* Wikipedia note: the auto keyword 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 conver-
sion 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;
Notes
[edit]- ^ "Its name most probably represents a contraction of BCPL, though an alternate theory holds that it derives from Bon [Thompson 69], an unrelated language created by Thompson during the Multics days. Bon in turn was named either after his wife Bonnie or (according to an encyclopedia quotation in its manual), after a religion whose rituals involve the murmuring of magic formulas."[2]
References
[edit]- ^ "B - computer programming language".
- ^ a b c d e f g Ritchie, Dennis M. (March 1993). "The Development of the C Language". ACM SIGPLAN Notices. 28 (3): 201–208. doi:10.1145/155360.155580.
- ^ a b c d Thompson, Ken (7 January 1972). "Users' Reference to B" (PDF). Bell Laboratories. Archived from the original (PDF) on 17 March 2015. Retrieved 21 March 2014.
- ^ Jensen, Richard (9 December 2020). ""A damn stupid thing to do"—the origins of C". Ars Technica. Retrieved 2022-03-28.
- ^ Michael S. Mahoney (18 August 1989). "Interview with M.D. McIlroy". Princeton.edu. Murray Hill.
- ^ a b Ken Thompson. "VCF East 2019 -- Brian Kernighan interviews Ken Thompson". YouTube. Archived from the original on 2021-11-23. Retrieved 2020-11-16.
I saw Johnson's semicolon version of the for loop and I put that in [B], I stole it.
- ^ Ritchie, Dennis M. (1984). "The Evolution of the Unix Time-sharing System". AT&T Bell Laboratories Technical Journal. 63 (6 Part 2): 1577–1593. doi:10.1002/j.1538-7305.1984.tb00054.x. Archived from the original on 11 June 2015.
- ^ "TMG". multicians.org.
- ^ Ritchie, Dennis M. "The Development of the C Language". Bell Labs/Lucent Technologies. Archived from the original on 11 June 2015.
- ^ a b McIlroy, M. D. (1987). A Research Unix reader: annotated excerpts from the Programmer's Manual, 1971–1986 (PDF) (Technical report). CSTR. Bell Labs. 139. Archived (PDF) from the original on 2022-10-09.
- ^ a b Johnson and Kernighan. "THE PROGRAMMING LANGUAGE B". Bell Laboratories. Archived from the original on 11 June 2015. Retrieved 21 March 2014.
- ^ "Thinkage UW Tools Package". Thinkage, Ltd. Retrieved 26 March 2014.
External links
[edit]- Manual page for b(1) from Unix First Edition
- The Development of the C Language, Dennis M. Ritchie. Puts B in the context of BCPL and C.
- Users' Reference to B, Ken Thompson. Describes the PDP-11 version.
- The Programming Language B, S. C. Johnson & B. W. Kernighan, Technical Report CS TR 8, Bell Labs (January 1973). The GCOS version on Honeywell equipment.
- B Language Reference Manual, Thinkage Ltd. The production version of the language as used on GCOS, including language and runtime library.