Talk:PL/0

From Wikipedia, the free encyclopedia

>The example is used in a book by Niklaus Wirth called Compilerbau.

I'm wondering if this (the origin of the EBNF for PL/0 listed in the article) is correct. I have the Algorithms + Data Structures = Programs book by Wirth, which does have the above EBNF. I do not have Compilerbau, but I did find a web reference that claims to have the EBNF for PL/0 v2 from Compilerbau, and the EBNF looks quite different from that listed in the article:

Das PL/0-System soll das Programmieren von Compilern demonstrieren. Siehe : N.Wirth, Compilerbau, Teubner Studienbuecher Informatik, [3]1984.

PL/0 Syntax (Version 2.0)

Program          = "PROGRAM" Ident ";" Block Ident ".".
Block            = {ConstDeclaration | VarDeclaration | ProcDeclaration}
                   BlockBody.
ConstDeclaration = "CONST" Ident "=" Number {"," Ident "=" Number} ";".
VarDeclaration   = "VAR" Ident {"," Ident} ";".
ProcDeclaration  = "PROCEDURE" Ident [":" Ident] ";" Block Ident ";".
BlockBody        = "BEGIN" StatementSequence "END".
StatementSequence= Statement {";" Statement}.
Statement        = Assignment |
                   StandardProcCall |
                   ProcedureCall |
                   IfStatement |
                   WhileStatement |
                   RepeatStatement |
                   ReturnStatement |
                   .
Assignment       = Ident ":=" Expression.
StandardProcCall = "Read" Ident |
                   "WriteLn" |
                   "Write" "(" Expression {"," Expression} ")".
ProcedureCall    = Ident.
IfStatement      = "IF" Condition "THEN" StatementSequence
                   {"ELSIF" Condition "THEN" StatementSequence}
                   ["ELSE" StatementSequence]
                   "END".
WhileStatement   = "WHILE" Condition "DO" StatementSequence "END".
RepeatStatement  = "REPEAT" StatementSequence "UNTIL" condition.
ReturnStatement  = "RETURN".
Condition        = "ODD" Expression |
                   Expression
                   ("=" | "#" | "<>" | "<" | "<=" | ">" | ">=") Expression.
Expression       = ["+" | "-"] Term {("+" | "-") Term}.
Term             = Factor {("*" | "/" | "DIV" | "%" | "MOD") Factor}.
Factor           = Ident | Number | "(" Expression ")".
Number           = Digit {Digit}.
Digit            = "0" | .. | "9".
Ident            = Letter {Letter | Digit}.
Letter           = "a" | .. | "z" | "A" | .. | "Z".

PL/0 Fakten

===========

Kommentare sind in (* ... *) einzuschliežen; keine Kommentarschachtelung.

Alle Variablen sind vom Typ LONGINT, d.h. 32 bit breit.

"Read x" entspricht "read(x)" in PASCAL,
"Write(x,...)" entspricht "write(x,...)",
"WriteLn" ebenso.

Funktionsprozeduren sind zul„ssig, wie z.B.:
"PROCEDURE Function_Example: Return_Value;"
Return_Value ist dann zu behandeln wie eine normale Variable und wird
an den Rufer zurckgegeben.
Rekursive Prozeduraufrufe sind zul„ssig.

January 11, 2006

The EBNF listed does not agree with the compiler source. Specifically, the constant declarations don't agree. Look at the original compiler in Algorithms + Data Structures = Programs (page 344, program 5.6), or look at the compiler at http://www.246.dk/pl0.html (referenced in the wiki PL/0 article). Here is the section of code that parses a constant declaration:

 if sym = constsym then
 begin getsym;
    repeat constdeclaration;
       while sym = comma do
          begin getsym; constdeclaration
          end;
       if sym = semicolon then getsym else error(5)
    until sym <> ident
 end;

The EBNF listed with the wiki article is:

block = ["CONST" ident "=" number {"," ident "=" number} ";"] ...

A careful inspection of the relevant source code (above), will show that the EBNF should be:

block = [const = "const" constdeclaration ";" {constdeclaration ";"}] ...

constdeclaration = ident "=" number {"," ident "=" number}

From looking at Wirth's syntax diagrams in Algorithms + Data Structures = Programs, it appears he meant the former, but he actually coded the latter.

So, which one is right?

Sam


May 5, 2006

I just looked up the source code in the Compilerbau book. Keywords are really lowercase, like "const", "begin". Lowercase is used both in the EBNF grammar and also in the source code. Wirth's PL/0 example programs also use lowercase. So, everything is consistent.

But why are there so many "wrong" example programs around there today ? The Compilerbau was written in the early 1970s. Since the late 1970s, Wirth used his language MODULA for implementing compilers. MODULA itself had all keywords in uppercase and variables in lowercase. It looks like Wirth took over this habit to later versions of PL/0.In the 1986 edition of Compilerbau, all PL/0 examples use uppercase.

[edit] Dead link

During several automated bot runs the following external link was found to be unavailable. Please check if the link is in fact down and fix or remove it in that case!


maru (talk) contribs 04:29, 27 July 2006 (UTC)

Yep, dead. removed. JonHarder 13:42, 27 July 2006 (UTC)