Sources

Grammar changes

You may wonder why is it not “returnExpression”?
After all an expression is something that evaluates to a value (as described in the previous post ) . Doesn’t a return statement evaluate to a value?

This may seem confusing but it turns out that return does not evaulate to a value.
In Java the following code would not make sens:
int x = return 5; , and same thing is with enkel.
In other words expression is essentially something that can be assigned to a variable.
That is why the return is a statement not an expression:

You may notice that the parser did not resolve implicit return statement in fun2.
This is due to the fact that the block is empty and matching “empty” as return statement is not a good idea.
The missing return statements are added at bytecode generation phase.

Mapping antlr context objects

Parsed return statements are converted from antlr context classes into POJO ReturnStatement objects.
The purpose of this step is to feed compiler only with data required for bytecode generation.
Getting data from antlr generated objects to generate bytecode would result in ugly unreadable code.