ArticleslgStudy

engineering

PL/0

PL/0 is a engineering topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand PL/0 rather than just read about it. In short: PL/0 is a general-purpose programming language, intended for use in education, that is similar to but much simpler than Pascal. Originally introduced in the book Algorithms + Data Structures = Programs by Niklaus Wirth in 1976, it serves as an example for compiler development.

Key takeaways

  • PL/0 belongs to engineering; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect PL/0 to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of PL/0 from memory before moving on to harder problems.

Reference excerpt

PL/0 is a general-purpose programming language, intended for use in education, that is similar to but much simpler than Pascal. Originally introduced in the book Algorithms + Data Structures = Programs by Niklaus Wirth in 1976, it serves as an example for compiler development. 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. While these limitations make writing real applications in this language impractical, it helps the compiler remain compact and simple.

Features All constants and variables used must be declared explicitly. The only data types are integers. The only operators are arithmetic and comparison operators. There is an odd function that tests whether the argument is odd. In the original implementation presented by Wirth, there are no input and output routines. The compiler prints the value as a given variable changes. So the program:

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. Flow control structures are if-then and while-do constructs and user-defined procedures. Procedures cannot accept parameters.

Grammar The following is the syntax rules of the model language defined in EBNF:

It is rather easy for students to write a recursive descent parser for such a simple syntax. Therefore, the PL/0 compiler is still widely used in courses on compiler construction throughout the world. Due to the lack of features in the original specification, students usually spend most of their time with extending the language and their compiler. They usually start with introducing REPEAT .. UNTIL and continue with more advanced features like parameter passing to procedures or data structures like arrays, strings or floating point numbers.

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. 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). 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. 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.

Compiler construction In December 1976, Wirth wrote a small booklet about compiler construction, containing the full source code of the PL/0 compiler. The syntax rules above were taken from this first edition of Wirth's book Compilerbau. In later editions of this book (under the influence of his ongoing research) Wirth changed the syntax of PL/0. He changed the spelling of keywords like const and procedure to uppercase. This change made PL/0 resemble Modula-2 more closely. At the same time, Wirth's friend and collaborator C. A. R. Hoare was working on his influential communicating sequential processes concept, which used the exclamation mark ! and the question mark ? to denote communication primitives. Wirth added both symbols to the PL/0 language, but he did not mention their semantics in the book.

Examples This program outputs the squares of numbers from 1 to 10. Most courses in compiler construction today have replaced the exclamation mark with the WriteLn procedure.

This following program prints the prime numbers from 1 to 100. The write statement corresponds to '!' statement in the EBNF syntax above.

The following example was taken from the second edition of Wirth's book Compilerbau, which appeared in 1986 in Germany.

Oberon-0 In the third and last edition of his book on compiler construction, Wirth replaced PL/0 with Oberon-0. The language Oberon-0 is much more complex than PL/0. For example, Oberon-0 offers arrays, records, type declarations and procedure parameters. 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. As of August 2017, the most recent revision available is from May 2017.

See also P-code machine City & Guilds Mnemonic Code

Notes

References

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 Archived 2017-02-18 at the Wayback Machine 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" [1] 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) Category:PL/0 Tasks implemented in PL/0 on rosettacode.org

Worked examples

Example 1 — a first encounter with PL/0

Start with the simplest possible case. Write down what PL/0 claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In engineering, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to PL/0 before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about PL/0 ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of PL/0

In research
PL/0 appears in engineering research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses PL/0 in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
PL/0 is common in secondary-school and first-year university syllabi. It links to neighbouring topics Compilers, Educational programming languages, Pascal programming language family, so understanding it makes those chapters shorter.
In everyday life
Look for PL/0 outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study PL/0 in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what PL/0 means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain PL/0 out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is PL/0 in simple terms?

PL/0 is a general-purpose programming language, intended for use in education, that is similar to but much simpler than Pascal. Originally introduced in the book Algorithms + Data Structures = Programs by Niklaus Wirth in 1976, it serves as an example for compiler development.

Why does PL/0 matter?

Because it connects several engineering ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study PL/0?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on PL/0.

Tags

  • Compilers
  • Educational programming languages
  • Pascal programming language family
  • Procedural programming languages
  • Programming languages created in 1975
  • Structured programming languages

Keep exploring