PL/0
PL/0 is a general-purpose programming language intended for use in education, that is similar to but much simpler than Pascal.[src] Originally introduced in the book Algorithms + Data Structures = Programs by Niklaus Wirth in 1976, it serves as an example for compiler development.[src] The language features a limited number of constructs: there are no real numbers, very few basic arithmetic operations and, for control flow, only "if" and "while" blocks.[src] While these limitations make writing real applications in this language impractical, it helps the compiler remain compact and simple.[src]
PL/0 is a general-purpose programming language intended for use in education, that is similar to but much simpler than Pascal.[src] Originally introduced in the book Algorithms + Data Structures = Programs by Niklaus Wirth in 1976, it serves as an example for compiler development.[src] The language features a limited number of constructs: there are no real numbers, very few basic arithmetic operations and, for control flow, only "if" and "while" blocks.[src] While these limitations make writing real applications in this language impractical, it helps the compiler remain compact and simple.[src] var i, s; begin i := 0; s := 0; while i gives the output: 0 0 1 1 2 5 3 14 4 30 5 55 However, most implementations have single input and single output routines.[src] Flow control structures are if-then and while-do constructs and user-defined procedures.[src] Procedures cannot accept parameters.[src] ==Grammar== The following is the syntax rules of the model language defined in EBNF: program = block "." ; block = [ "const" ident "=" number {"," ident "=" number} ";"] [ "var" ident {"," ident} ";"] { "procedure" ident ";" block ";" } statement ; statement = [ ident ":=" expression | "call" ident | "?" ident | "!" expression | "begin" statement {";" statement } "end" | "if" condition "then" statement | "while" condition "do" statement ]; condition = "odd" expression | expression ("="|"#"|" "|">=") expression ; expression = [ "+"|"-"] term { ("+"|"-") term}; term = factor {("*"|"/") factor}; factor = ident | number | "(" expression ")"; It is rather easy for students to write a recursive descent parser for such a simple syntax.[src] Therefore, the PL/0 compiler is still widely used in courses on compiler construction throughout the world.[src] Due to the lack of features in the original specification, students usually spend most of their time with extending the language and their compiler.[src] They usually start with introducing REPEAT ..[src] UNTIL and continue with more advanced features like parameter passing to procedures or data structures like arrays, strings or floating point numbers.[src] ==Use in education== The main article on compilers honours PL/0 for introducing several influential concepts (stepwise refinement, recursive descent parsing, EBNF, P-code, T-diagrams) to the field by educating students to use these concepts.[src] Over the last 3 decades, most university courses on compiler construction that used PL/0 have followed Wirth strictly in employing these techniques (see references below).[src] Some years ago university courses deviated from the course set by Wirth with the replacement of the classical recursive descent parsing technique by a (nonetheless classical) Unix-like approach of employing lex and yacc.[src] Only recently an implementation (PL/0 Language Tools) along this way has also combined modern concepts like object-orientation and design patterns with a modern scripting language (Python), allowing students to consume the source text of the implementation in a contemporary programming style.[src] ==Compiler construction== In December 1976, Wirth wrote a small booklet about compiler construction, containing the full source code of the PL/0 compiler.[src] The syntax rules above were taken from this first edition of Wirth's book Compilerbau.[src] In later editions of this book (under the influence of his ongoing research) Wirth changed the syntax of PL/0.[src] He changed the spelling of keywords like const and procedure to uppercase.[src] This change made PL/0 resemble Modula-2 more closely.[src] At the same time, Wirth's friend and collaborator C.[src] A.[src] R.[src] Hoare was working on his influential communicating sequential processes concept, which used the exclamation mark ![src] and the question mark ?[src] to denote communication primitives.[src] Wirth added both symbols to the PL/0 language, but he did not mention their semantics in the book.[src] ==Examples== This program outputs the squares of numbers from 1 to 10.[src] Most courses in compiler construction today have replaced the exclamation mark with the WriteLn procedure.[src] VAR x, squ; PROCEDURE square; BEGIN squ:= x * x END; BEGIN x := 1; WHILE x This following program prints the prime numbers from 1 to 100.[src] The write statement corresponds to '!' statement in the EBNF syntax above.[src] const max = 100; var arg, ret; procedure isprime; var i; begin ret := 1; i := 2; while i The following example was taken from the second edition of Wirth's book Compilerbau, which appeared in 1986 in Germany.[src] VAR x, y, z, q, r, n, f; PROCEDURE multiply; VAR a, b; BEGIN a := x; b := y; z := 0; WHILE b > 0 DO BEGIN IF ODD b THEN z := z + a; a := 2 * a; b := b / 2 END END; PROCEDURE divide; VAR w; BEGIN r := x; q := 0; w := y; WHILE w y DO BEGIN q := 2 * q; w := w / 2; IF w 1 THEN BEGIN f := n * f; n := n - 1; CALL fact END END; BEGIN ?x; ?y; CALL multiply; !z; ?x; ?y; CALL divide; !q; !r; ?x; ?y; CALL gcd; !z; ?n; f := 1; CALL fact; !f END.[src] ==Oberon-0== In the third and last edition of his book on compiler construction, Wirth replaced PL/0 with Oberon-0.[src] The language Oberon-0 is much more complex than PL/0.[src] For example, Oberon-0 offers arrays, records, type declarations and procedure parameters.[src] The publisher of Wirth's books (Addison-Wesley) has decided to phase out all his books, but Wirth has published revised editions of his book beginning in 2004.[src] , the most recent revision available is from May 2017.[src] ==Notes== ==References== Liffick, Blaise W., Ed (1979), The Byte Book of Pascal, Wirth, Niklaus (1975), Algorithms + Data Structures = Programs, Wirth, Niklaus (1986), Compilerbau, B.G.[src] Teubner, Stuttgart ==External links== The compiler (.pas file) from the first edition of the Compilerbau book, written in Pascal Another copy of the compiler at Pascal for small machines site The interpreter from "Algorithms + Data Structures = Programs" book, written in Pascal Development of a PL/0 style compiler based on 'Compiler construction' written in Mocka (Modula-2 for Linux) A paper explaining the use of PL/0 at the University of Rochester The homepage of the PL/0 reference book, "Algorithms + Data Structures = Programs" *https://sourceforge.net/projects/pl0-compiler (written in C/C++, uses QT framework) https://modernc.org/pl0 (written in Go, runs in terminal, cross platform) https://github.com/dodobyte/plzero (a very small compiler produces windows executable) https://github.com/hindermath/TinyPl0 (modern port of PL/0 with Agentic-AI to .Net10/C# 14) https://github.com/MarcRochkind/pl0compiler (compiler for IBM 701 written in C; generates 701 assembler) [http://rosettacode.org/wiki/Category:PL/0 Category:PL/0 Tasks implemented in PL/0 on rosettacode.org[src]
45 sentences · 45 cited inline · 0 references stored
References
No reference rows published for this article.
Cite this article
MLA
"PL/0." encyclopegia.org, 2026, https://encyclopegia.org/wiki/pl-0. Accessed 28 November 2026.
Chicago
"PL/0." encyclopegia.org. Accessed November 28, 2026. https://encyclopegia.org/wiki/pl-0.
APA
encyclopegia.org. (2026). PL/0. Retrieved November 28, 2026, from https://encyclopegia.org/wiki/pl-0
Accessed November 28, 2026 · CC BY-SA 4.0 · citation page · JSON
Claims
| Predicate | Value | Source |
|---|---|---|
| publication date | 2004 | Wikipedia |