PL/0
|
There are at least two programming langages known as PL/0. One is a subset of IBM's general purpose programming language PL/I.
The other PL/0 is a simplified version of the general-purpose programming language programming language Pascal, intended as an educational programming language. It serves as an example how to construct a compiler. It was originally introduced in a famous and well written book, Algorithms + Data Structures = Programs, by Niklaus Wirth in 1975. It features quite limited language constructs: there are no real number, very few basic arithmetic operations and no control-flow constructs other than if and while blocks. While the limitation makes writing real applications in this language impractical, it helps the compiler remain compact and simple.
The example is used in a book by Niklaus Wirth called Compilerbau.
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 ")".
The following example is taken from [1] (http://www.ntecs.de/old-hp/uu9r/lang/html/pl0.en.html).
VAR x, squ; PROCEDURE square; BEGIN squ := x * x END; BEGIN x := 1; WHILE x <= 10 DO BEGIN CALL square; !squ END END.
This program outputs the squares from 1 to 10.
Web links
- The compiler (http://www.246.dk/pl0.html) written in PascalTemplate:Compu-lang-stub