Category:PL/0

From Rosetta Code
Revision as of 00:55, 2 February 2023 by Christophoro S (talk | contribs) (Added a description.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Language
PL/0
This programming language may be used to instruct a computer to perform a task.
Lang tag(s): pl0
See Also:


Listed below are all of the tasks on Rosetta Code which have been solved using PL/0.

PL/0 is an educational programming language. It was originally introduced in the book, Algorithms + Data Structures = Programs, by Niklaus Wirth in 1976. Wirth uses PL/0 as an example of how to construct a compiler.

Syntax

The syntax rules of PL/0 can be specified in EBNF as follows:

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 ")";

Wirth in his book presents the version without ? ("receive an integer value and assign it to the variable") and ! ("display a value of the expression") statements. Instead, this version displays values of the variables after changing them. So, the program:

var a, b;

begin
  a := 0; b := 10;
  while a < 5 do 
  begin
    a := a + 1;
    b := b - 1;
  end
end.

gives the output:

         0
        10
         1
         9
         2
         8
         3
         7
         4
         6
         5
         5

Some versions use other statements for receiving and displaying data, usually read and write.

Due to typograhic conventions, Wirth uses non-ASCII symbols , , and . Some versions use # for "not equal", [ for "less or equal", and ] for "greater or equal" respectively.

Some versions accept only upper-case letters or only lower-case letters in keywords and identifiers.

External links