Discussion:
Variable scope in Oberon-07
(too old to reply)
August Karlstrom
2018-02-07 11:34:10 UTC
Permalink
If I compile this module with Niklaus Wirth's PO2013 compiler I get
"level error, not accessible":

MODULE M;

VAR x: INTEGER;

PROCEDURE P;
VAR x: INTEGER;

PROCEDURE Q;
BEGIN
x := 0
END Q;
END P;

END M.

Without the local declaration of x it compiles. I find this strange as
the compiler should only search the (strictly) local and the global
scope for identifier declarations. Can this restriction be found in the
language report?

-- August
August Karlstrom
2018-02-08 16:55:12 UTC
Permalink
I find this strange, as the compiler should only search the (strictly)
local and the global scope for identifier declarations.
NW's PO2013 compiler apparently only disallows access to *variables*
declared in intermediate scopes. I was under the impression that no
objects (constants, types, variables or procedures) declared in an
intermediate scope is accessible. The language report says:

"In addition to its formal parameters and locally declared objects, the
objects declared globally are also visible in the procedure."

It doesn't say that non-variable objects from intermediate scopes are
visible in a procedure.

-- August
r***@gmail.com
2018-02-09 16:48:11 UTC
Permalink
Hi,
Post by August Karlstrom
It doesn't say that non-variable objects from intermediate scopes are
visible in a procedure.
Why wouldn't they be?

AFAIK, the main advantage to this restriction (re: variables) is only
simplified stack management.
c***@gmail.com
2018-02-10 00:45:48 UTC
Permalink
Post by r***@gmail.com
Hi,
Post by August Karlstrom
It doesn't say that non-variable objects from intermediate scopes are
visible in a procedure.
Why wouldn't they be?
AFAIK, the main advantage to this restriction (re: variables) is only
simplified stack management.
FYI the original question has since been reposted and a subsequent discussion resulted on the ETH Oberon Mailing list:

http://lists.inf.ethz.ch/pipermail/oberon/2018/011549.html

Regards,
Chris Burrows
CFB Software
http://www.astrobe.com
r***@gmail.com
2018-02-09 16:45:39 UTC
Permalink
Hi,
Post by August Karlstrom
Without the local declaration of x it compiles. I find this strange as
the compiler should only search the (strictly) local and the global
scope for identifier declarations. Can this restriction be found in the
language report?
So you're not surprised it only handles strictly local or global.
You're just wondering why it even notices such a variable that
isn't accessible? So you want it to ignore it and not error out?

Who knows, maybe that is for better error-checking of old (presumably
Oberon-2) code being updated.
August Karlstrom
2018-02-10 09:22:28 UTC
Permalink
Post by r***@gmail.com
Who knows, maybe that is for better error-checking of old (presumably
Oberon-2) code being updated.
Maybe, but still it should compile. The alternative is to prevent object
shadowing altogether and require unique names, as done for instance in
Eiffel.


-- August

Loading...