[Oberon] Intermediate scopes in Oberon-07

Jörg joerg.straube at iaeth.ch
Sun Feb 25 08:42:05 CET 2018


Diego

As you know Expression (indirectly) calls Factor, and Factor calls Expression.
There might be more but I know THREE different techniques how to solve this circular reference, what to declare first
1) Nesting, with the compiler „problem“ of static link
2) Forward reference with the compiler „problem" of fixing the jump
3) Procedure variables. In the compiler, this comes for free.

3) is now the way how ProjectOberon does it. Personally, I find it quite appealing.

br
Jörg


> Am 25.02.2018 um 01:12 schrieb Diego Sardina <dsar at eml.cc>:
> 
> I have 4 - 5 books about Compilers in Pascal and Modula-2 and the procedures Term, Factor and SimpleExpression are *always* nested inside Expression. But they aren't in Project Oberon.
> Are these authors just fools because they used a such (in your opinion) useless technique? I don't think so.
> 
> Saying more, these nested procedures don't even need intermediate global procedures, so they can be nested also in Oberon-07 (2016).
> The parser of expressions is a very GOOD example where nested procedures are ELEGANT and makes sense. Factor, Term and SimpleExpression don't make any sense in the global scope.
> 
> 
> (* This code is properly formatted with a fixed-width font *)
> 
> PROCEDURE Expression(...);
> 
>  PROCEDURE SimpleExpression(...);
> 
>    PROCEDURE Term(...);
> 
>      PROCEDURE Factor(...);
>      BEGIN
>        (* Strictly locals/globals : Factor, Expression.     *)
>        (* Intemediate globals     : Term, SimpleExpression. *)
>        (* Used                    : Factor, Expression.     *)
>      END Factor;
> 
>    BEGIN (* Term *)
>      (* Strictly locals/globals : Term, Factor, Expression. *)
>      (* Intermediate globals    : SimpleExpression.         *)
>      (* Used                    : Factor.                   *)
>    END Term;
> 
>  BEGIN (* SimpleExpression *)
>    (* Strictly locals/globals : SimpleExpression, Term, Expression. *)
>    (* Intermediate globals    : (none)                              *)
>    (* Used                    : Term.                               *)
>  END SimpleExpression;
> 
> BEGIN (* Expression *)
>  (* Strictly locals/globals : SimpleExpression, Expression. *)
>  (* Intermediate globals    : (none)                        *)
>  (* Used                    : SimpleExpression.             *)
> END Expression;
> --
> 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