Contents | Prev | Next | Index


Procedure or Function Calls

The purpose of a procedure call is to activate a procedure, execute its code, return to the caller and continue execution at the point immediately following the procedure call. Pascal also permits nested procedure calls. The procedure call may contain a list of actual parameters which replace the corresponding formal parameters defined in the procedure declaration. The correspondence is established by the positions of the parameters in the actual and formal parameter lists. There are two kind of parameters: Variable parameters and value parameters. If the procedure is a function, it returns a value after the call, which can be used whereever an expression is allowed. In this compiler, a function call may ignore the return value and be treated like a proper procedure call.  

If a formal parameter is a variable parameter, the corresponding actual parameter must be a designator denoting a variable. If it denotes an element of a structured variable, the component selectors are evaluated when the formal/actual parameter substitution takes place, which is normally just before the execution of the procedure. If a formal parameter is a value parameter, the corresponding actual parameter must be an assignment compatible expression. The value of this expression is assigned to the formal parameter.

Procedure Call
procedure_call    ::= proc_designator                   
                  ::= proc_designator actual_parameters 
proc_designator   ::= expr_designator                   
actual_parameters ::= ( param_list )                    
param_list        ::= param_list , param_expr           
                  ::= param_expr                        
param_expr        ::= expr                              
                  ::= expr : precision                  
                  ::= expr : precision : precision      
precision         ::= expr                              

Function Call
factor          ::= primary
primary ::= expr_designator
::= proc_designator actual_parameters

An actual value parameter may be followed by one or two precision specifiers. These are integer values standing for the output size and the number of digits after the decimal point. They are only allowed for integer and real values when calling the standard procedure WRITE or WRITELN for text files.


Contents | Prev | Next | Index

Canterbury Pascal for JVM  (Last documentation update Sep 02, 2004)
Copyright © 1999-2004 J.Neuhoff - mhccorp.com  . All rights reserved.
Please send any comments or corrections to neuhoff@mhccorp.com