Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Chapter 10 - Function implementation. The stack implementation of function call and return is a central topic deserving deeper study. Moreover, strategies for the management of another memory area called the heap, are important to the understanding of dynamic objects like arrays. Chapter 10a presents the following content: Function declaration and call in clite, completing the clite type system, semantics of call and return. | Programming Languages 2nd edition Tucker and Noonan Chapter 10 Function Implementation In theory, there is no difference between theory and practice, but not in practice. Anonymous Contents 10.1 Function Declaration and Call in Clite 10.2 Completing the Clite Type System 10.3 Semantics of Call and Return 10.4 Formal Treatment of Types and Semantics 10.1 Function Declaration and Call Example Clite Program Fig 10.1 int h, i; void B(int w) { int j, k; i = 2*w; w = w+1; } void A(int x, int y) { bool i, j; B(h); } int main() { int a, b; h = 5; a = 3; b = 2; A(a, b); } 10.1.1 Concrete Syntax Functions and Globals (new elements underlined) Program { Type Identifier FunctionOrGlobal } MainFunction Type int | boolean | float | char | void FunctionOrGlobal ( Parameters ) { Declarations Statements } | Global Parameters [ Parameter { , Parameter } ] Global { , Identifier } ; MainFunction int main ( ) { Declarations Statements } Concrete Syntax (cont’d) Function Calls (new elements underlined) Statement ; | Block | Assignment | IfStatement | WhileStatement | CallStatement | ReturnStatement CallStatement Call ; ReturnStatement return Expression ; Factor Identifier | Literal | ( Expression ) | Call Call Identifier ( Arguments ) Arguments [ Expression { , Expression } ] 10.1.2 Abstract Syntax Program = Declarations globals; Functions functions Functions = Function* Function = Type t; String id; Declarations params, locals; Block body Type = int | boolean | float | char | void Statement = Skip | Block | Assignment | Conditional | Loop | Call | Return Call = String name; Expressions args Expressions = Expression* Return = Variable target; Expression result Expression = Variable | Value | Binary | Unary | Call Abstract Syntax for a Clite Program Fig 10.4 globals body Program Functions Declarations Function Function Function int main void A void B params locals body h i w A(a,b); a b i j x y w = w + 1; i = 2 * w; j k Block Call 10.2 Completing the Clite Type . | Programming Languages 2nd edition Tucker and Noonan Chapter 10 Function Implementation In theory, there is no difference between theory and practice, but not in practice. Anonymous Contents 10.1 Function Declaration and Call in Clite 10.2 Completing the Clite Type System 10.3 Semantics of Call and Return 10.4 Formal Treatment of Types and Semantics 10.1 Function Declaration and Call Example Clite Program Fig 10.1 int h, i; void B(int w) { int j, k; i = 2*w; w = w+1; } void A(int x, int y) { bool i, j; B(h); } int main() { int a, b; h = 5; a = 3; b = 2; A(a, b); } 10.1.1 Concrete Syntax Functions and Globals (new elements underlined) Program { Type Identifier FunctionOrGlobal } MainFunction Type int | boolean | float | char | void FunctionOrGlobal ( Parameters ) { Declarations Statements } | Global Parameters [ Parameter { , Parameter } ] Global { , Identifier } ; MainFunction int main ( ) { Declarations Statements } Concrete Syntax (cont’d) Function Calls (new elements .