Discussion:
Assignment 5 - Return statement
(too old to reply)
Johnny Yip
2004-07-09 03:41:19 UTC
Permalink
Hi,

From the spec
"This statement consists of the keyword return optionally followed by
an expression"

Looking at the production for returnStmt:
returnstmt ::= RETURN expr;

Since expr is non nullable, I cannot put "return;" in my SL code

Should returnstmt be
returnstmt ::= RETURN expr | RETURN;
instead?

Thanks,
Johnny
Troy Mark Gonsalves
2004-07-09 20:12:44 UTC
Permalink
Yes that's true.
you could also use:

returnstmt ::= RETURN expropt;

Which I prefer. I've asked Tiuley to update SL.cup accordingly.
Note that you're free to edit the productions yourself if you think
there's a better way.

Also not that the procudtion for variables have been updated (no
multi-dimensional arrays).

Troy
Post by Johnny Yip
Hi,
From the spec
"This statement consists of the keyword return optionally followed by
an expression"
returnstmt ::= RETURN expr;
Since expr is non nullable, I cannot put "return;" in my SL code
Should returnstmt be
returnstmt ::= RETURN expr | RETURN;
instead?
Thanks,
Johnny
Loading...