[an error occurred while processing this directive] [an error occurred while processing this directive]

CPS710

[an error occurred while processing this directive] (none) Assignment 3

Ryerson University
[an error occurred while processing this directive]

(none)

[an error occurred while processing this directive]

HL Functions

[an error occurred while processing this directive]

(none)

[an error occurred while processing this directive]

Due: (none)

UNDER CONSTRUCTION!


Contents


General Function Call Evaluation Rules

  1. The parameters are evaluated.
  2. The function body is evaluated with all references to the parameters replaced by their value.
  3. If the function returns a value, the last statement executed must be a return statement with a parameter of the same type as the function type.
  4. If the function does not return a value, return statements are not necessary, but can be used.
  5. The value of the function call is the value of the return statement. If the function call was used as a statement rather than an expression, its return value is ignored by the clause or body where it is used.

Parameter Passing


Return statements

Return statements are only meaningful inside function definitions. return statements which are not inside function definitions are syntax errors. This will be checked in assignment 4.

A return statement which is inside nested function definitions applies to the innermost function definition. (This is standard in most programming languages. The only reason that this is explicitly stated is to distinguish the semantics of return statements from the semantics of the stop statement). For example, in the program:

return a; // this is an invalid return
fun a()
	fun b()
		...
		return; // this is a return from b
		nuf;
	...
	return; // this is a return from a
	nuf;

The parameter of the return statement must evaluate to a value of the same type as the return type as the function. If the function has no return type, its return statements should not have parameters. This will be checked in assignment 4.


Built-In Functions

HL has 5 built-in functions: Since these functions are built into the HL language, they cannot be redefined.
You may decide to make their names tokens and define the function calls in the grammar if you like, but that is optional. Also you may decide to define some but not all of them in the grammar (for example print and println but not the others).


This page is maintained by Sophie Quigley (cps710@scs.ryerson.ca)
Last modified Sunday, 06-Nov-2016 21:03:28 EST