Oberon Report Update 2016-05-01

Topics related to the use of Oberon language features
augustk
Posts: 54
Joined: Mon Sep 05, 2011 5:21 pm
Location: Sweden

Oberon Report Update 2016-05-01

Post by augustk » Sun May 01, 2016 3:05 pm

The Oberon Report has been updated again. The changes are:

1. The three grammar productions

Code: Select all

TypeDeclaration = identdef "=" StrucType.
StrucType = ArrayType | RecordType | PointerType | ProcedureType.
type = qualident | StrucType.
have been reduced to

Code: Select all

TypeDeclaration = identdef "=" type.
type = qualident | ArrayType | RecordType | PointerType | ProcedureType.
(I assume that qualident still cannot be a basic type.)

2. Strings assigned to character arrays are always null-terminated.

3. Open arrays can be assigned to arrays with the same base type.

kevinhely
Posts: 29
Joined: Wed May 18, 2011 3:35 am

Re: Oberon Report Update 2016-05-01

Post by kevinhely » Sun May 01, 2016 6:48 pm

(I assume that qualident still cannot be a basic type.)
Why? INTEGER is a qualident.

cfbsoftware
Site Admin
Posts: 493
Joined: Fri Dec 31, 2010 12:30 pm
Contact:

Re: Oberon Report Update 2016-05-01

Post by cfbsoftware » Mon May 02, 2016 3:12 am

augustk wrote:(I assume that qualident still cannot be a basic type.)
qualident can be a basic type. There is an example of this use in the FileDir module in Project Oberon 2013 :

DiskAdr = INTEGER;

It is even possible to write

REAL = INTEGER;

but I wouldn't recommend it ;)

This feature, i.e. being able to rename / alias types, is already implemented in the current versions of Astrobe. We we will only have to update the documentation as it is no longer considered to be a language extension.

augustk
Posts: 54
Joined: Mon Sep 05, 2011 5:21 pm
Location: Sweden

Re: Oberon Report Update 2016-05-01

Post by augustk » Mon May 02, 2016 7:13 am

cfbsoftware wrote:qualident can be a basic type. There is an example of this use in the FileDir module in Project Oberon 2013
If my memory serves me correctly, I have read somewhere a text by Niklaus Wirth where he says that the right hand side of a type declaration must be a structured type. My "default" understanding would be that any type is allowed. Do you remember if an earlier version of the language had this restriction? Otherwise it must be something I have made up.

augustk
Posts: 54
Joined: Mon Sep 05, 2011 5:21 pm
Location: Sweden

Re: Oberon Report Update 2016-05-01

Post by augustk » Mon May 02, 2016 8:17 am

As I understand it, the decision between "null-terminated if needed" and "always null-terminated" character arrays is a trade off between declaration interpretation complexity and algorithm complexity.

Let's consider the declaration

Code: Select all

name: ARRAY 32 OF CHAR
With the "null-terminated if needed" approach the variable can hold a name of up to 32 characters; as simple and obvious as can be. On the other hand, with the "always null-terminated" approach we need to (remember to) subtract one element and conclude that the array can hold a name of only up to 31 characters. The alternative is to add one element explicitly as a remainder:

Code: Select all

name: ARRAY 31 + 1 OF CHAR
Now, let's look at the code for computing the length of the character array. With the "null-terminated if needed" approach we need to look for both the the null character and the end of the array:

Code: Select all

i := 0;
WHILE (i < LEN(name)) & (name[i] # 0X) DO
	INC(i)
END
With the "always null-terminated" approach we only need to look for the null character:

Code: Select all

i := 0;
WHILE name[i] # 0X DO
	INC(i)
END
The latter is more efficient and regular.

Are there any aspects I have missed?

Stefano
Posts: 4
Joined: Fri May 17, 2013 7:34 am

Re: Oberon Report Update 2016-05-01

Post by Stefano » Mon May 02, 2016 8:28 am

cfbsoftware wrote:
augustk wrote:(I assume that qualident still cannot be a basic type.)
qualident can be a basic type. There is an example of this use in the FileDir module in Project Oberon 2013 :

DiskAdr = INTEGER;

It is even possible to write

REAL = INTEGER;

but I wouldn't recommend it ;)

This feature, i.e. being able to rename / alias types, is already implemented in the current versions of Astrobe. We we will only have to update the documentation as it is no longer considered to be a language extension.
Isn't REAL a predeclared type so that REAL = INTEGER is a redeclaration?

cfbsoftware
Site Admin
Posts: 493
Joined: Fri Dec 31, 2010 12:30 pm
Contact:

Re: Oberon Report Update 2016-05-01

Post by cfbsoftware » Mon May 02, 2016 8:35 am

augustk wrote:If my memory serves me correctly, I have read somewhere a text by Niklaus Wirth where he says that the right hand side of a type declaration must be a structured type. My "default" understanding would be that any type is allowed. Do you remember if an earlier version of the language had this restriction? Otherwise it must be something I have made up.
It wasn't something you made up. The original Oberon Report (e.g. Revision 1. 10. 90) specified:

TypeDeclaration = identdef "=" type.
type = qualident | ArrayType | RecordType | PointerType | ProcedureType.

i.e. any type was allowed. The restriction to only allow structured types was introduced in Oberon-07:

TypeDeclaration = identdef "=" StrucType.
StrucType = ArrayType | RecordType | PointerType | ProcedureType.
type = qualident | StrucType.

This has now changed. The restriction has been removed in the latest (1.5.2016) revision of the report and we are back to the original definitions:

TypeDeclaration = identdef "=" type.
type = qualident | ArrayType | RecordType | PointerType | ProcedureType.

cfbsoftware
Site Admin
Posts: 493
Joined: Fri Dec 31, 2010 12:30 pm
Contact:

Re: Oberon Report Update 2016-05-01

Post by cfbsoftware » Mon May 02, 2016 8:46 am

Stefano wrote:Isn't REAL a predeclared type so that REAL = INTEGER is a redeclaration?
It's a predefined type e.g. like ABS. It is not a reserved word like BEGIN. e.g. in earlier versions of Oberon-07 you could have written:

PROCEDURE REAL(i: INTEGER);
BEGIN
END REAL;

Stefano
Posts: 4
Joined: Fri May 17, 2013 7:34 am

Re: Oberon Report Update 2016-05-01

Post by Stefano » Mon May 02, 2016 8:53 am

cfbsoftware wrote:
Stefano wrote:Isn't REAL a predeclared type so that REAL = INTEGER is a redeclaration?
It's a predefined type e.g. like ABS. It is not a reserved word like BEGIN. e.g. in earlier versions of Oberon-07 you could have written:

PROCEDURE REAL(i: INTEGER);
BEGIN
END REAL;
Section 6.1 states

6.1. Basic types
The following basic types are denoted by predeclared identifiers.

augustk
Posts: 54
Joined: Mon Sep 05, 2011 5:21 pm
Location: Sweden

Re: Oberon Report Update 2016-05-01

Post by augustk » Mon May 02, 2016 10:22 am

cfbsoftware wrote:The restriction to only allow structured types was introduced in Oberon-07:

Code: Select all

TypeDeclaration = identdef "=" StrucType.
StrucType = ArrayType | RecordType | PointerType | ProcedureType.
type = qualident | StrucType.
Ah, of course. It's evident from the grammar. My bad.

Allowing only structured types in type declarations and having "null-terminated if needed" character arrays are obviously two of many changes to the Oberon language that Wirth has tried but reverted when they have turned out not to be beneficial in practice. I wonder if there are any changes that have been introduced, reverted and then reintroduced?

Post Reply