《编译原理》课程教学资源:第五章(5-2)过程激活

Chapter 5 Procedure activations 过程活动要点 参数传递机伟 宏扩展
Chapter 5 Procedure Activations 过程活动要点 ◼参数传递机制 ◼宏扩展

PROCEDURES(过程) When a procedure is called, the body is executed. Each execution of the body is called an activation of the body. Two forms of procedures: functions Functions extend the built-in operators of a language. procedures Procedures extend the built-in actions or statements
PROCEDURES(过程) When a procedure is called, the body is executed. Each execution of the body is called an activation of the body. Two forms of procedures: • functions Functions extend the built-in operators of a language. • procedures Procedures extend the built-in actions or statements

ELEMENTS OF A PROCEDURE 过程的要素 A procedure declaration makes explicit the elements or parts of a procedure: procedure name(过程名), a name for the declared procedure foma/ parameters(形式参数) placeholders for actual parameters result type(返回值类型), which is optional ocedure body(过程体), consisting of local declarations and a statement
ELEMENTS OF A PROCEDURE 过程的要素 A procedure declaration makes explicit the elements or parts of a procedure: • procedure name(过程名), a name for the declared procedure • formal parameters(形式参数), placeholders for actual parameters • result type(返回值类型), which is optional • procedure body(过程体), consisting of local declarations and a statement

HE ELEMENTS OFA FUNCTION PROCEDURE FORMAL RESULT NAME PARAMIETER TYPE function square(x: integer): integer; PROCEDURE egll BODY sguare:II ell
THE ELEMENTS OF A FUNCTION

A COMPLETE PASCAL PROGRAM WITH TWO FUNCTIONS, SQUARE AND AREA program trap(input, output; var result: real function square(x: integer): integer: begin square.dx end function area( a, b: real function f(x: real): real): real; DegIn dre:=(b-a)*(f(a)+f(b)/2 en d begin result: area(2, 5, square) writen 2, 5, result en d 带函数参数
A COMPLETE PASCAL PROGRAM WITH TWO FUNCTIONS, SQUARE AND AREA 带函数参数

BENEFITS OF PROCEDURES The user of a procedure needs to know what a procedure does, not how the procedure works. The benefits of procedures include the following Procedure abstraction(过程抽象) Implementation hiding(实现隐藏) Modular programs(模块化编程) Libraries(库)
BENEFITS OF PROCEDURES The user of a procedure needs to know what a procedure does, not how the procedure works. The benefits of procedures include the following: – Procedure abstraction(过程抽象) – Implementation hiding(实现隐藏) – Modular programs(模块化编程) – Libraries(库)

PARAMETERPASSING METHODS 参数传递机制 Parameter passing refers to the matching of actuals(实际参数) with formals(形式参数) when a procedure call occurs
PARAMETER-PASSING METHODS 参数传递机制 Parameter passing refers to the matching of actuals(实际参数) with formals(形式参数) when a procedure call occurs

Possible interpretations of a procedure call like P(A[i]) include the following: ca∥- by-value(值传递) Pass the value of Ali Ca∥-by- reference(引用传递 Pass the location of A[i Ca∥-by- value- result(值结果传递) actuals are initially copied into the formals and the formals are eventually copied back thethe actuals Ca∥- by-name(名字传递) Pass the text Ali itself, while avoiding name clashes
Possible interpretations of a procedure call like P(A[i]) include the following: – Call-by-value(值传递) Pass the value of A[i]. – Call-by-reference(引用传递) Pass the location of A[i]. – Call-by-value-result(值结果传递) actuals are initially copied into the formals and the formals are eventually copied back the the actuals. – Call-by-name(名字传递) Pass the text A[i] itself, while avoiding ``name clashes

CALL-BY-VALUE(值传递) Under call-by-value, a formal parameter corresponds to the value of an actual parameter. call by-value is the primary parameter passing method in C and Pascal. 传递了实际参数的一个副本给形参
CALL-BY-VALUE(值传递) Under call-by-value, a formal parameter corresponds to the value of an actual parameter. Callby-value is the primary parameterpassing method in C and Pascal. 传递了实际参数的一个副本给形参

Example: procedure muchAddx, y: 7: varz:万 egin 2:XX:yy:=2 end A call muchAdo (a, b) has the following effect X: =a,i pass the value of a to Xy y:=b,i pass the value of b to y) Z:=XX: =Ny: =Z a and b are unchanged y The program segment does not change a or b, though the values of x and y are indeed exchanged 如果想用此方法来交换两个数的值可能达不到目的
Example: procedure muchAdo(x, y : T); var z : T; begin z := x; x := y; y := z; end A call muchAdo(a,b) has the following effect: x := a; { pass the value of a to x } y := b; { pass the value of b to y } z := x; x := y; y := z; { a and b are unchanged } The program segment does not change a or b, though the values of x and y are indeed exchanged. 如果想用此方法来交换两个数的值可能达不到目的
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 《编译原理》课程教学资源:第六章 属性文法.ppt
- 《编译原理》课程教学资源:第八章 符号表.ppt
- 《编译原理》课程教学资源:第四章 对象和环境.ppt
- 《编译原理》课程教学资源:第五章 YACC.ppt
- 《编译原理》课程教学资源:第二章(2-4-1)One parse tree only.ppt
- 《编译原理》课程教学资源:第二章(2-4)语法分析一自上而下分析.ppt
- 《JavaScript》权威指南简介.ppt
- 《编译原理》课程教学资源:第三章 正则表达式常应用于文本匹配:.ppt
- 《编译原理》课程教学资源:第二章(2-3-1)对于词法分析器的要求.ppt
- 《编译原理》课程教学资源:第二章 词法分析 2.6 利用Lex自动生成扫描程序.ppt
- 《编译原理》课程教学资源:第二章 语言描述与实现 Language Description and Implementation 2.1 程序语言的语法描述.ppt
- 《编译原理》课程教学资源:第一章(1-2)编译简介.ppt
- 《编译原理》课程教学资源:语义分析和中间代码产生.ppt
- 《编译原理》课程教学资源:Chapter 5 Procedure Activations.ppt
- 《互联网软件应用与开发》综合复习材料.doc
- 《计算机电路基础》课程教学资源(PPT课件讲稿)第四章 门电路.ppt
- 《计算机电路基础》课程教学资源(PPT课件讲稿)第六章 时序逻辑电路.ppt
- 《计算机电路基础》课程教学资源(PPT课件讲稿)第五章 组合逻辑电路.ppt
- 《计算机电路基础》课程教学资源(PPT课件讲稿)第二章 半导体基本器件.ppt
- 《计算机电路基础》课程教学资源(PPT课件讲稿)第三章 开关理论基础.ppt
- 《编译原理》课程教学资源:第二章 语言描述与实现 Language Description and Implementation 2.5 语法分析——自下而上分析.ppt
- 《编译原理》课程教学资源:教学计划.doc
- 《编译原理》课程教学资源:第十章 优化.ppt
- 《编译原理》课程教学资源:属性文法.ppt
- 《体系结构》第二章 计算机指令集结构设计.doc
- 《体系结构》第三章 流水线技术.doc
- 《体系结构》第五章 存储层次.doc
- 《体系结构》第六章 输入输出系统.doc
- 《体系结构》第一章 计算机体系结构的基本概念.doc
- USB系统研究(学位论文)USB System Study.pdf
- 《微型计算机原理与接口技术》第10章 串行通信接口.ppt
- 《微型计算机原理与接口技术》第11章 人机交互接口技术.ppt
- 《微型计算机原理与接口技术》第12章 模拟量输入输出接口技术.ppt
- 《微型计算机原理与接口技术》第1章 微型计算机基础知识.ppt
- 《微型计算机原理与接口技术》第2章 典型微处理器.ppt
- 《微型计算机原理与接口技术》第3章 指令系统与汇编语言程序设计.ppt
- 《微型计算机原理与接口技术》第4章 半导体存储器及其接口.ppt
- 《微型计算机原理与接口技术》第5章 总线技术.ppt
- 《微型计算机原理与接口技术》第6章 基本输入输出接口技术.ppt
- 《微型计算机原理与接口技术》第7章 中断控制技术.ppt