Category:PL/0: Difference between revisions
Added features.
(Added a description.) |
(Added features.) |
||
Line 1:
{{language|PL/0
|tags=pl0}}
'''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. This language has little constructs. Writing real applications in PL/0 is not practical, but the compiler can remain compact and simple.
==
One must explicitly declare all used constants and variables.
The syntax rules of PL/0 can be specified in [[extended Backus–Naur form|EBNF]] as follows:▼
The only data type are integer numbers. The only operators are arithmetical and comparison ones. There is a function <code>odd</code> which examines if the integer argument is odd.
<syntaxhighlight lang="ebnf">▼
program = block "." ;▼
In the original implementation presented by Wirth, there are no input and output routines. The compiler prints the new value of each variable when it becomes changed. So, the program:
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 ")";▼
</syntaxhighlight>▼
Wirth in his book presents the version without <code>?</code> ("receive an integer value and assign it to the variable") and <code>!</code> ("display a value of the expression") statements. Instead, this version displays values of the variables after changing them. So, the program:▼
<syntaxhighlight lang="pascal">
var a, b;
begin
a := 0; b := 10;
Line 57 ⟶ 35:
5
</pre>
Most implementations have single input and single output routines.
The flow control structures are ''if-then'' and ''while-do'' constructs, and procedures defined by the user. Procedures cannot accept any parameters.
== Syntax ==
▲The syntax rules of PL/0 can be specified in [[extended Backus–Naur form|EBNF]] as follows:
▲<syntaxhighlight lang="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 ")";
▲</syntaxhighlight>
▲Wirth in his book presents the
Due to typograhic conventions, Wirth uses non-ASCII symbols <code>≠</code>, <code>≤</code>, and <code>≥</code>. Some
Some
== External links==
|