[Oberon] LONGINT, RETURN & etc.
Jörg
joerg.straube at iaeth.ch
Sat Jun 17 07:08:41 CEST 2017
Wojtek
no, no you are still allowed to write RETURN 1+2.
The „thing“ you are allowed to write behind RETURN is still an (expression) with all bells and whistles.
You are still allowed to write e.g. RETURN ( f(23, 4) + 17H ) DIV x
But this "RETURN (expression)" thing has to be the LAST token before the end of the function.
Formerly the allowed syntax of a procedure was
Previous syntax
ProcedureBody = DeclarationSequence [ "BEGIN" StatementSequence ] "END".
StatementSequence = statement { ";“ statement }.
statement = [ assignment | IfStatement | … | "RETURN" [ expression] ].
New syntax
ProcedureBody = DeclarationSequence [ "BEGIN" StatementSequence ] [ "RETURN" [ expression] ] "END".
StatementSequence = statement { ";“ statement }.
statement = [ assignment | IfStatement | … ].
The production RETURN [ expression ] was moved from production statement to production ProcedureBody.
The reason behind this was to make the flow of the program clearer, more straight forward, as with the previous syntax you could stop execution of a procedure anywhere in a procedure, even within an nested IF or WHILE. If you had quite a long procedure, it was hard to immediately find what the output value of this procedure was.
Now, you can just look at the end of the procedure and be sure: the last and only RETURN tells me what value the procedure wants to return.
br
Jörg
> Am 17.06.2017 um 02:05 schrieb Skulski, Wojciech <skulski at pas.rochester.edu>:
>
>
>> Now the syntax
>> "RETURN" (expression)
>> still exists but not as part of (statement). Due to this syntax change
>> it is only allowed to
>> be used ONCE in a PROCEDURE block.
>>
>> Did this explanation help?
>
> It did help, but it is not an explanation. It is a declaration. I read it as
> "for whatever reason RETURN is only allowed to be used ONCE
> in a PROCEDURE block". I will try to memorize.
> If I fail to memorize, the compiler will kindly remind me of the rule.
>
> So OK, I take it that in the past I could write RETURN 1+2,
> and now I am allowed to write RETURN 3. Just another rule.
> It probably helps in writing a better compiler. I am fine with this.
>
> W.
> --
> 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