[Oberon] Oberon-2 type bound procedure scope
Jörg
joerg.straube at iaeth.ch
Sun Dec 10 04:59:10 CET 2023
August
After PROCEDURE P; is parsed, the compiler
- declares P in the global scope.
- opens a new P-scope (that ends at END P;)
- puts the P-scope in front of the global scope (for searching)
After PROCEDURE Q; is parsed, the compiler
- declares Q in the P-scope
- opens the Q-scope that ends at END Q;
- puts the Q-scope in front of the P-scope (for searching)
When the compiler sees „Q“ in Q, it searches the local Q-scope for „Q“ —> not found
It goes on and searches „Q“ in the next P-scope —> found. Generates a call to Q that happens to be recursive.
br, Jörg
> Am 10.12.2023 um 01:53 schrieb August Karlstrom <fusionfile at gmail.com>:
>
> On 2023-12-09 20:09, Diego Sardina wrote:
>> By definition: "The scope extends textually from the point of the
>> declaration to the end of the block (procedure or module)". By saying
>> that, "within its declaration" can be considered the same "within its
>> scope".
> The complete sentence is
>
> "The scope extends textually from the point of the declaration to the end of the block (procedure or module) to which the declaration belongs and hence to which the object is local."
>
> Let's take this procedure as an example:
>
> PROCEDURE P;
> PROCEDURE Q;
> ...
> END Q;
> BEGIN
> ...
> END P
>
> The quoted sentence says that the scope of Q starts at line two and extends to the end of the procedure P. To my understanding an identifier cannot live in two scopes at the same time, so Q belongs to the local scope defined by P and not to the local scope defined by Q. Therefor, according to the scope rules alone a local procedure (in this case Q) cannot call itself since its identifier lives in an intermediate scope.
>
> /August
> --
> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
> https://lists.inf.ethz.ch/mailman/listinfo/oberon
More information about the Oberon
mailing list