unit i · 2017. 4. 5. · parameter passing methods 1. call by value : copy going into the...
TRANSCRIPT
-
Programming Language Syntax and semantics
UNIT I
BB yy
Kainjan Sanghavi
-
Contents
• Routines
• Generic Routines
• Aliasing and Overloading
• Parameter Passing Methods
-
Routines
In programming language routines come
into two forms :
1. Procedures : does not return a value
2. Functions : Return a value
-
Assembly language
• Subprograms
FORTRAN
• Subroutines
Pascal
• Procedures
Ada , C
• Functions
Routines Routines are called as : follows depending upon the programming language :
-
Routines Routines have
1. Name : Routine declaration
2. Scope : From starting of function till closing
3. Type : Routines header defines its routine
type…….i.e method signature
4. L-value : Reference to the memory area which
stores the routines executable statements
int (*ps)(int) ; ps = ∑
1. R-value : Executable statements : int i = (*ps)(5);
-
Generic Routines means templates
Refer :
https://kainjan1.wordpress.com/oop-course-file/oop-
notes/
Lec37 : 16-8-2016FunctionTemplates Lec38 : 19-8-2016ClassTemplates Lec39:20-8-2016OverloadingTemplates
https://kainjan1.wordpress.com/oop-course-file/oop-notes/https://kainjan1.wordpress.com/oop-course-file/oop-notes/https://kainjan1.wordpress.com/oop-course-file/oop-notes/https://kainjan1.wordpress.com/oop-course-file/oop-notes/https://kainjan1.wordpress.com/oop-course-file/oop-notes/https://kainjan1.wordpress.com/oop-course-file/oop-notes/https://kainjan1.wordpress.com/oop-course-file/oop-notes/https://kainjan1.wordpress.com/oop-course-file/oop-notes/https://kainjan1.files.wordpress.com/2016/06/16-8-2016templates.pdfhttps://kainjan1.files.wordpress.com/2016/06/16-8-2016templates.pdfhttps://kainjan1.files.wordpress.com/2016/06/16-8-2016templates.pdfhttps://kainjan1.files.wordpress.com/2016/06/16-8-2016templates.pdfhttps://kainjan1.files.wordpress.com/2016/06/16-8-2016templates.pdfhttps://kainjan1.files.wordpress.com/2016/06/19-8-2016classtemplates.pdfhttps://kainjan1.files.wordpress.com/2016/06/19-8-2016classtemplates.pdfhttps://kainjan1.files.wordpress.com/2016/06/19-8-2016classtemplates.pdfhttps://kainjan1.files.wordpress.com/2016/06/19-8-2016classtemplates.pdfhttps://kainjan1.files.wordpress.com/2016/06/19-8-2016classtemplates.pdfhttps://kainjan1.files.wordpress.com/2016/06/22-8-2016overloadingtemplates.pdfhttps://kainjan1.files.wordpress.com/2016/06/22-8-2016overloadingtemplates.pdfhttps://kainjan1.files.wordpress.com/2016/06/22-8-2016overloadingtemplates.pdfhttps://kainjan1.files.wordpress.com/2016/06/22-8-2016overloadingtemplates.pdfhttps://kainjan1.files.wordpress.com/2016/06/22-8-2016overloadingtemplates.pdf
-
Aliasing
• In computing, aliasing describes a situation in which a data location in memory can be accessed through different symbolic names in the program.
• Thus, modifying the data through one name implicitly
modifies the values associated with all aliased names, which may not be expected by the programmer.
-
Aliasing
• As a result, aliasing makes it particularly difficult to
understand, analyze and optimize programs.
• Aliasing analyzers intend to make and compute
useful information for understanding aliasing in
programs.
-
Overloading
Refer : https://kainjan1.wordpress.com/oop-course-file/oop-notes/ Lec16:9-7-2016Function Overloading Lec 17,18 :12-7-2016: UNIT II OperatorOverloading
https://kainjan1.wordpress.com/oop-course-file/oop-notes/https://kainjan1.wordpress.com/oop-course-file/oop-notes/https://kainjan1.wordpress.com/oop-course-file/oop-notes/https://kainjan1.wordpress.com/oop-course-file/oop-notes/https://kainjan1.wordpress.com/oop-course-file/oop-notes/https://kainjan1.wordpress.com/oop-course-file/oop-notes/https://kainjan1.wordpress.com/oop-course-file/oop-notes/https://kainjan1.files.wordpress.com/2016/06/9-7-2016function-overloading.pdfhttps://kainjan1.files.wordpress.com/2016/06/9-7-2016function-overloading.pdfhttps://kainjan1.files.wordpress.com/2016/06/9-7-2016function-overloading.pdfhttps://kainjan1.files.wordpress.com/2016/06/9-7-2016function-overloading.pdfhttps://kainjan1.files.wordpress.com/2016/06/9-7-2016function-overloading.pdfhttps://kainjan1.files.wordpress.com/2016/06/operatoroverloading12-7-2016.pdfhttps://kainjan1.files.wordpress.com/2016/06/operatoroverloading12-7-2016.pdfhttps://kainjan1.files.wordpress.com/2016/06/operatoroverloading12-7-2016.pdfhttps://kainjan1.files.wordpress.com/2016/06/operatoroverloading12-7-2016.pdfhttps://kainjan1.files.wordpress.com/2016/06/operatoroverloading12-7-2016.pdfhttps://kainjan1.files.wordpress.com/2016/06/operatoroverloading12-7-2016.pdfhttps://kainjan1.files.wordpress.com/2016/06/operatoroverloading12-7-2016.pdfhttps://kainjan1.files.wordpress.com/2016/06/operatoroverloading12-7-2016.pdf
-
Parameter Passing
Methods 1. call by value : copy going into the procedure 2. call by result : copy going out of the procedure 3. call by value-result : copy going in, and again
going out 4. call by reference : pass a pointer to the actual
parameter, and indirect through the pointer 5. call by name : re-evaluate the actual parameter on every use.
For actual parameters that are simple variables, this is the same as call by reference. For actual parameters that are expressions, the expression is re-evaluated on each access
-
Parameter Passing
Methods
• Fortran uses call by reference
• Algol 60 has call by name, call by value
• Lisp and Smalltalk use call-by-value with
pointer semantics.
• Java uses call-by-value
-
Example 1: illustrates call by
value, value-result, reference
begin integer n; procedure p(k: integer); begin n := n+1; k := k+4; print(n); end; n := 0; p(n); print(n); end;
Note that when using call by reference, n and k are aliased. Output: call by value: 1 1 call by value-result: 1 4 call by reference: 5 5
-
Example 2: Call by value and
call by name
begin integer n; procedure p(k: integer); begin print(k); n := n+1; print(k); end; n := 0; p(n+10); end;
Output: call by value: 10 10 call by name: 10 11
-
Example 3: Call by value and call by
name (with evaluation errors)
begin integer n; procedure p(k: integer); begin print(n); end; n := 5; p(n/0); end;
Output: call by value: divide by zero error call by name: 5
-
Thank You!
Angelin