CPS710

Assignment 5

Toronto Metropolitan University University

Semantics of HL - Part 2


This page contains additional HL semantics for this assignment. Note that they will not explicitly be enforced in this assignment, but in the next one as part of error management.

Contents


Declarations and Types


Scoping

In static scoping, there are no scope blocks for loops, only functions (and the global scope, of course).

HL defines one additional special scope: in a set former expression, the set former variable is implicitly declared as a NUM variable whose scope is the condition of set former only, i.e. between the vertical bar and the closing curly bracket of the set former. Note that this scope does not include the set former's domain because the definition would end up being self-referential.


Loops


Set Formers

Sets defined using the set former structure { idnum in expression | condition } are evaluated as follows:

General Function Call Evaluation Rules

Function are evaluated as follows:
  1. The parameters are evaluated (see next section).
  2. The function body is evaluated with all references to the parameters replaced by their value.
  3. This evaluation must be ended by a return statement.
They are used in the following context:

Parameter Passing


Return Statements

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

A return statement which is inside nested function definitions applies to the innermost function definition, as is standard in most programming languages. For example, in the program:

return x; // this is an invalid return
function a()
  function b()
		...
		return y; // this is a return from b
		end;
	...
	return z; // this is a return from a
	end;

The parameter of the return statement, when there is one, must evaluate to a value of the same type as the return type as the function. The value of that parameter is the value of the entire function call.

When the return statement doesn't have any parameters, the value of the entire function call is null.


This page is maintained by Sophie Quigley (cps710@cs.torontomu.ca)
Last modified Thursday, 28-Nov-2024 12:28:02 EST