Introduction to Scientific Computing Languages

Similar documents
Introduction to Scientific Computing Languages

Programming Languages, Summary CSC419; Odelia Schwartz

Concepts of Programming Languages

8/27/17. CS-3304 Introduction. What will you learn? Semester Outline. Websites INTRODUCTION TO PROGRAMMING LANGUAGES

Programming Languages 2nd edition Tucker and Noonan"

Principles of Programming Languages. Lecture Outline

Outline. Programming Languages 1/16/18 PROGRAMMING LANGUAGE FOUNDATIONS AND HISTORY. Current

General Concepts. Abstraction Computational Paradigms Implementation Application Domains Influence on Success Influences on Design

Principles in Programming: Orientation & Lecture 1. SWE2004: Principles in Programming Spring 2014 Euiseong Seo

9/7/17. Outline. Name, Scope and Binding. Names. Introduction. Names (continued) Names (continued) In Text: Chapter 5

Concepts in Programming Languages

Programmiersprachen (Programming Languages)

CS321 Languages and Compiler Design I. Winter 2012 Lecture 1

Topic I. Introduction and motivation References: Chapter 1 of Concepts in programming languages by J. C. Mitchell. CUP, 2003.

St. MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

LECTURE 1. Overview and History

Introduction. A. Bellaachia Page: 1

Continuations provide a novel way to suspend and reexecute

Com S 541. Programming Languages I

Chapter 5. Names, Bindings, and Scopes

Chapter 8 ( ) Control Abstraction. Subprograms Issues related to subprograms How is control transferred to & from the subprogram?

1. true / false By a compiler we mean a program that translates to code that will run natively on some machine.

COSC 2P90 Programming Languages & Object-Orientation

Informal Semantics of Data. semantic specification names (identifiers) attributes binding declarations scope rules visibility

Chapter 1. Preliminaries

A Tour of Language Implementation

Chapter 1. Preliminaries

Chapter 1 Preliminaries

Comp 333: Concepts of Programming Languages Fall 2016

SKILL AREA 304: Review Programming Language Concept. Computer Programming (YPG)

G Programming Languages - Fall 2012

9/21/17. Outline. Expression Evaluation and Control Flow. Arithmetic Expressions. Operators. Operators. Notation & Placement

The role of semantic analysis in a compiler

INSTITUTE OF AERONAUTICAL ENGINEERING

NOTE: Answer ANY FOUR of the following 6 sections:

Chapter 3:: Names, Scopes, and Bindings (cont.)

Question No: 1 ( Marks: 1 ) - Please choose one One difference LISP and PROLOG is. AI Puzzle Game All f the given

Lecture 1: Course Introduction

SOFTWARE ARCHITECTURE 6. LISP

Principles in Programming: Orientation & Lecture 1. SWE2004: Principles in Programming Spring 2015 Euiseong Seo

Seminar in Programming Languages

Imperative Programming

LECTURE 18. Control Flow

CSCI 3136 Principles of Programming Languages

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler Front-End

CS101 Introduction to Programming Languages and Compilers

Lecture 15: Iteration and Recursion

Why are there so many programming languages? Why do we have programming languages? What is a language for? What makes a language successful?

Organization of Programming Languages (CSE452) Why are there so many programming languages? What makes a language successful?

Informatica 3 Syntax and Semantics

Lecture 1: Course Introduction

Early computers (1940s) cost millions of dollars and were programmed in machine language. less error-prone method needed

Implementing Algorithms in MIPS Assembly

Logic Programming II & Revision

Chapter 3:: Names, Scopes, and Bindings (cont.)

Compiling and Interpreting Programming. Overview of Compilers and Interpreters

Outline. Introduction to Programming (in C++) Introduction. First program in C++ Programming examples

Programs are: CMPSCI 105/119/120: Programming, Flowchar<ng, and Running Program Flowcharts

Chapter 1. Preview. Reason for Studying OPL. Language Evaluation Criteria. Programming Domains

Stop coding Pascal. Saturday, April 6, 13

8/16/12. Computer Organization. Architecture. Computer Organization. Computer Basics

Software II: Principles of Programming Languages. Why Expressions?

Static Semantics. Lecture 15. (Notes by P. N. Hilfinger and R. Bodik) 2/29/08 Prof. Hilfinger, CS164 Lecture 15 1

Lecture 16: Static Semantics Overview 1

Chapter 2 Preview. Preview. History of Programming Languages. History of Programming Languages. History of Programming Languages

LECTURE 17. Expressions and Assignment

Concepts of Programming Languages

G Programming Languages - Fall 2012

SE352b: Roadmap. SE352b Software Engineering Design Tools. W3: Programming Paradigms

MIDTERM EXAM (Solutions)

CSC 533: Organization of Programming Languages. Spring 2005

HANDLING NONLOCAL REFERENCES

Programming Paradigms

CS2303 C14 Systems Programming Concepts. Bob Kinicki

Answer: Early binding generally leads to greater efficiency (compilation approach) Late binding general leads to greater flexibility

Low-Level Languages. Computer Programs and Programming Languages

Programming Languages and Program Development Life Cycle Fall Introduction to Information and Communication Technologies CSD 102

CS508-Modern Programming Solved MCQ(S) From Midterm Papers (1 TO 22 Lectures) BY Arslan

CS 314 Principles of Programming Languages

CS 314 Principles of Programming Languages

Chapter 11 Introduction to Programming in C

Chapter 5 Names, Binding, Type Checking and Scopes

Programming Languages and Program Development

COP4020 Programming Languages. Compilers and Interpreters Robert van Engelen & Chris Lacher

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University

Data Types. (with Examples In Haskell) COMP 524: Programming Languages Srinivas Krishnan March 22, 2011

4 Bindings and Scope. Bindings and environments. Scope, block structure, and visibility. Declarations. Blocks. 2004, D.A. Watt, University of Glasgow

Programming Languages

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

CMPT 379 Compilers. Anoop Sarkar.

CS 565: Programming Languages. Spring 2008 Tu, Th: 16:30-17:45 Room LWSN 1106

6. Names, Scopes, and Bindings

Lecture 09. Ada to Software Engineering. Mr. Mubashir Ali Lecturer (Dept. of Computer Science)

COMP 201: Principles of Programming

CS 345. Functions. Vitaly Shmatikov. slide 1

Functional Programming. Big Picture. Design of Programming Languages

Why study Programming Language Concepts? Chapter One. Language Evaluation Criteria. Programming Domains. Readability Writability Reliability Cost

Chapter 7. - FORTRAN I control statements were based directly on IBM 704 hardware


G Programming Languages Spring 2010 Lecture 4. Robert Grimm, New York University

Transcription:

1 / 1 Introduction to Scientific Computing Languages Prof. Paolo Bientinesi pauldj@aices.rwth-aachen.de

Languages for Scientific Computing 2 / 1 What is a programming language?

Languages for Scientific Computing 2 / 1 What is a programming language? A set of instructions and constructs for communicating with a computing device. Instructions and constructs are combined and organized into programs.

Languages for Scientific Computing 2 / 1 What is a programming language? A set of instructions and constructs for communicating with a computing device. Instructions and constructs are combined and organized into programs. Examples: Basic, Pascal, Cobol, Fortran, C, C++, Lisp, Prolog, SQL, Java, Perl, Python, Ruby,...

Languages for Scientific Computing 2 / 1 What is a programming language? A set of instructions and constructs for communicating with a computing device. Instructions and constructs are combined and organized into programs. Examples: Basic, Pascal, Cobol, Fortran, C, C++, Lisp, Prolog, SQL, Java, Perl, Python, Ruby,... Computing device?

Languages for Scientific Computing 2 / 1 What is a programming language? A set of instructions and constructs for communicating with a computing device. Instructions and constructs are combined and organized into programs. Examples: Basic, Pascal, Cobol, Fortran, C, C++, Lisp, Prolog, SQL, Java, Perl, Python, Ruby,... Computing device? sequential processors, embedded processors,..., parallel computers, supercomputers.

Processor s Components 3 / 1 Arithmetic Logic Unit (ALU) (control signals, inputs, outputs), Floating Point Unit (FPU), Prefetching Unit, Registers,...

Processor s Components 3 / 1 Languages let the users specify how to use these components. Arithmetic Logic Unit (ALU) (control signals, inputs, outputs), Floating Point Unit (FPU), Prefetching Unit, Registers,...

Processor s Components 3 / 1 Languages let the users specify how to use these components. Only Assembly operates on components: Low-level language. Arithmetic Logic Unit (ALU) (control signals, inputs, outputs), Floating Point Unit (FPU), Prefetching Unit, Registers,...

Processor s Components 3 / 1 Languages let the users specify how to use these components. Only Assembly operates on components: Low-level language. High-level languages only specify the computations to be performed. Arithmetic Logic Unit (ALU) (control signals, inputs, outputs), Floating Point Unit (FPU), Prefetching Unit, Registers,... A compiler and/or an interpreter translates high-level programs into a sequence of component actions.

4 / 1 Assembly Low-level language

4 / 1 Assembly Low-level language Very fast! Not the lowest level. Not directly executable.

4 / 1 Assembly Low-level language Very fast! Not the lowest level. Not directly executable. Assembler translates assembly into machine code. Executable.

4 / 1 Assembly Low-level language Very fast! Not the lowest level. Not directly executable. Assembler translates assembly into machine code. Executable. Assembly consists of mnemonic codes. Machine code: only numbers. Translation Assembly machine code is almost 1-1. This is not true for high-level languages. Assembler is hardware-specific. Control over chips components.

5 / 1 Assembly Example poly: Loop: Exit:.text.globl poly li.s $f0, 0.0 # y = 0, running & return result mtc1 $6 $f12 # x, move to float register mul.s $f14, $f12, $f0 # compute (x * y) mul $2, $5, 4 # $5 = i, compute address of a[i] addu $3, $2, $4 # a + (i*4) l.s $f16, 0($3) # a[i], load coefficient add.s $f0, $f16, $f14 # y = a[i] + (x*y) addi $5, $5, -1 # decrease i slt $2, $5, $0 # $2 = 1 if i < 0 beq $2, $0, Loop # goto Loop if i >= 0 j $31

Assembly Example poly: Loop: Exit:.text.globl poly li.s $f0, 0.0 # y = 0, running & return result mtc1 $6 $f12 # x, move to float register mul.s $f14, $f12, $f0 # compute (x * y) mul $2, $5, 4 # $5 = i, compute address of a[i] addu $3, $2, $4 # a + (i*4) l.s $f16, 0($3) # a[i], load coefficient add.s $f0, $f16, $f14 # y = a[i] + (x*y) addi $5, $5, -1 # decrease i slt $2, $5, $0 # $2 = 1 if i < 0 beq $2, $0, Loop # goto Loop if i >= 0 j $31 # Evaluate the value of a polynomial using Horner s algorithm. # f = a[0] + a[1] * x + a[2] * x^2 +... + a[n] * x^n 5 / 1

History 6 / 1 What is the oldest programming language still in use?

History 6 / 1 What is the oldest programming language still in use? FORTRAN 1957, 1977, 1995,...

History 6 / 1 What is the oldest programming language still in use? FORTRAN 1957, 1977, 1995,... late 50s Fortran( 57)..., Algol( 58), Lisp( 59) 60s Cobol( 61), Basic( 64) 70s Pascal( 70), C( 72), Prolog( 72), SQL( 78), Matlab( 78) 80s C++( 83), Perl( 87), Mathematica( 87) 90s Python( 91), Ruby( 93), Java( 95)

History 6 / 1 What is the oldest programming language still in use? FORTRAN 1957, 1977, 1995,... late 50s Fortran( 57)..., Algol( 58), Lisp( 59) 60s Cobol( 61), Basic( 64) 70s Pascal( 70), C( 72), Prolog( 72), SQL( 78), Matlab( 78) 80s C++( 83), Perl( 87), Mathematica( 87) 90s Python( 91), Ruby( 93), Java( 95) Oldest programming language?

History 6 / 1 What is the oldest programming language still in use? FORTRAN 1957, 1977, 1995,... late 50s Fortran( 57)..., Algol( 58), Lisp( 59) 60s Cobol( 61), Basic( 64) 70s Pascal( 70), C( 72), Prolog( 72), SQL( 78), Matlab( 78) 80s C++( 83), Perl( 87), Mathematica( 87) 90s Python( 91), Ruby( 93), Java( 95) Oldest programming language? Plankalkül (1940s). For the Z1 computer, by Konrad Zuse.

History of Programming Languages 1954 1960 1965 1970 1975 1980 WEB 7 / 1

Compiled vs. Interpreted Languages 8 / 1 Compiled Languages

Compiled vs. Interpreted Languages 8 / 1 Compiled Languages The program is first compiled, i.e., reduced to architecture-dependent instructions and stored in an executable file.

Compiled vs. Interpreted Languages 8 / 1 Compiled Languages The program is first compiled, i.e., reduced to architecture-dependent instructions and stored in an executable file. The program can then be executed separately, at a later time. The executable is portable only to compatible platforms. The program?

Compiled vs. Interpreted Languages 8 / 1 Compiled Languages The program is first compiled, i.e., reduced to architecture-dependent instructions and stored in an executable file. The program can then be executed separately, at a later time. The executable is portable only to compatible platforms. The program? Speed! Examples: C, Fortran.

Compiled vs. Interpreted Languages 8 / 1 Compiled Languages The program is first compiled, i.e., reduced to architecture-dependent instructions and stored in an executable file. The program can then be executed separately, at a later time. The executable is portable only to compatible platforms. The program? Speed! Examples: C, Fortran. Interpreted Languages The instructions are parsed and executed in real time by an interpreter.

Compiled vs. Interpreted Languages 8 / 1 Compiled Languages The program is first compiled, i.e., reduced to architecture-dependent instructions and stored in an executable file. The program can then be executed separately, at a later time. The executable is portable only to compatible platforms. The program? Speed! Examples: C, Fortran. Interpreted Languages The instructions are parsed and executed in real time by an interpreter. No generated code. The interpreter is always needed.

Compiled vs. Interpreted Languages 8 / 1 Compiled Languages The program is first compiled, i.e., reduced to architecture-dependent instructions and stored in an executable file. The program can then be executed separately, at a later time. The executable is portable only to compatible platforms. The program? Speed! Examples: C, Fortran. Interpreted Languages The instructions are parsed and executed in real time by an interpreter. No generated code. The interpreter is always needed. Ease! Examples: Matlab, Mathematica, Python.

Computer Programs 9 / 1

Computer Programs 9 / 1 Program: sequence of instructions expressing the operations to be performed on a target computing platform. Each program P has a meaning. It implements a function. {Initial State} P {Final State}.

Computer Programs 9 / 1 Program: sequence of instructions expressing the operations to be performed on a target computing platform. Each program P has a meaning. It implements a function. {Initial State} P {Final State}. [[P]] is the semantics of the program P. [[ ]] = Semantics operator. Operational, Denotational, Axiomatic. Out of the scope of this class. Generally, we want P to compute f(i), with i I. f is a mathematical function, a procedure, a simulation,...

Computer Programs 9 / 1 Program: sequence of instructions expressing the operations to be performed on a target computing platform. Each program P has a meaning. It implements a function. {Initial State} P {Final State}. [[P]] is the semantics of the program P. [[ ]] = Semantics operator. Operational, Denotational, Axiomatic. Out of the scope of this class. Generally, we want P to compute f(i), with i I. f is a mathematical function, a procedure, a simulation,... The question is: does P implement the function that we have in mind?

Computer Programs 9 / 1 Program: sequence of instructions expressing the operations to be performed on a target computing platform. Each program P has a meaning. It implements a function. {Initial State} P {Final State}. [[P]] is the semantics of the program P. [[ ]] = Semantics operator. Operational, Denotational, Axiomatic. Out of the scope of this class. Generally, we want P to compute f(i), with i I. f is a mathematical function, a procedure, a simulation,... The question is: does P implement the function that we have in mind? A program P is correct if i I, P(i) f(i).

Computer Programs 9 / 1 Program: sequence of instructions expressing the operations to be performed on a target computing platform. Each program P has a meaning. It implements a function. {Initial State} P {Final State}. [[P]] is the semantics of the program P. [[ ]] = Semantics operator. Operational, Denotational, Axiomatic. Out of the scope of this class. Generally, we want P to compute f(i), with i I. f is a mathematical function, a procedure, a simulation,... The question is: does P implement the function that we have in mind? A program P is correct if i I, P(i) f(i). Surprisingly... when working with floating point numbers, correctness is not enough!

Subroutines 10 / 1 subroutine = function = procedure = subprogram (= module = method)

Subroutines 10 / 1 subroutine = function = procedure = subprogram (= module = method) Portions of the code that perform one specific task and that are reusable.

Subroutines 10 / 1 subroutine = function = procedure = subprogram (= module = method) Portions of the code that perform one specific task and that are reusable. They are very much like mathematical functions: result := routine_name( arguments )

Subroutines 10 / 1 subroutine = function = procedure = subprogram (= module = method) Portions of the code that perform one specific task and that are reusable. They are very much like mathematical functions: result := routine_name( arguments ) BUT! One difference: side-effects. Many languages allow subroutines to have side-effects. The routine alters the state of the system even after its completion.

Side Effects 11 / 1 { (res =...) State } res := routine_name( args ); { (res =...) State } If ( State = State ) no side-effects. Most languages allow constructs with side-effects. Print statements; iterative constructs;...

More on Subroutines 12 / 1 Subroutines are good! Improve readability: code is shorter.

More on Subroutines 12 / 1 Subroutines are good! Improve readability: code is shorter. Enable modularity: programs are built as a composition of functionalities. Avoid reinventing the wheel.

More on Subroutines 12 / 1 Subroutines are good! Improve readability: code is shorter. Enable modularity: programs are built as a composition of functionalities. Avoid reinventing the wheel. Optimization: They solve a smaller and well-defined task. Better suited to be optimized.

More on Subroutines 12 / 1 Subroutines are good! Improve readability: code is shorter. Enable modularity: programs are built as a composition of functionalities. Avoid reinventing the wheel. Optimization: They solve a smaller and well-defined task. Better suited to be optimized. Structure: routine_name( args ) // body // return( value ) args, body and value are optional, depending on the language.

Questions about Subroutines 13 / 1 routine_name_1(args_1) routine_name_2(args_2) // // body_1 body_2 // // return( value2 ) return( value_2 ) Can body_1 include a call to routine_name_1?

Questions about Subroutines 13 / 1 routine_name_1(args_1) routine_name_2(args_2) // // body_1 body_2 // // return( value2 ) return( value_2 ) Can body_1 include a call to routine_name_1? Yes! Recursion.

Questions about Subroutines 13 / 1 routine_name_1(args_1) routine_name_2(args_2) // // body_1 body_2 // // return( value2 ) return( value_2 ) Can body_1 include a call to routine_name_1? Yes! Recursion. Recursion Limit? Termination?

Questions about Subroutines 13 / 1 routine_name_1(args_1) routine_name_2(args_2) // // body_1 body_2 // // return( value2 ) return( value_2 ) Can body_1 include a call to routine_name_1? Yes! Recursion. Recursion Limit? Termination? No Iteration.

Questions about Subroutines 13 / 1 routine_name_1(args_1) routine_name_2(args_2) // // body_1 body_2 // // return( value2 ) return( value_2 ) Can body_1 include a call to routine_name_1? Yes! Recursion. Recursion Limit? Termination? No Iteration. Fortran 77. What if body_1 includes a call to routine_name_2 and body_2 includes a call to routine_name_1?

Questions about Subroutines 13 / 1 routine_name_1(args_1) routine_name_2(args_2) // // body_1 body_2 // // return( value2 ) return( value_2 ) Can body_1 include a call to routine_name_1? Yes! Recursion. Recursion Limit? Termination? No Iteration. Fortran 77. What if body_1 includes a call to routine_name_2 and body_2 includes a call to routine_name_1? Mutual recursion.

Questions about Subroutines 13 / 1 routine_name_1(args_1) routine_name_2(args_2) // // body_1 body_2 // // return( value2 ) return( value_2 ) Can body_1 include a call to routine_name_1? Yes! Recursion. Recursion Limit? Termination? No Iteration. Fortran 77. What if body_1 includes a call to routine_name_2 and body_2 includes a call to routine_name_1? Mutual recursion. Fortran 77: No.

Questions about Subroutines 13 / 1 routine_name_1(args_1) routine_name_2(args_2) // // body_1 body_2 // // return( value2 ) return( value_2 ) Can body_1 include a call to routine_name_1? Yes! Recursion. Recursion Limit? Termination? No Iteration. Fortran 77. What if body_1 includes a call to routine_name_2 and body_2 includes a call to routine_name_1? Mutual recursion. Fortran 77: No. Are recursive languages more expressive than iterative ones? Can they compute more or fewer functions?

Questions about Subroutines 13 / 1 routine_name_1(args_1) routine_name_2(args_2) // // body_1 body_2 // // return( value2 ) return( value_2 ) Can body_1 include a call to routine_name_1? Yes! Recursion. Recursion Limit? Termination? No Iteration. Fortran 77. What if body_1 includes a call to routine_name_2 and body_2 includes a call to routine_name_1? Mutual recursion. Fortran 77: No. Are recursive languages more expressive than iterative ones? Can they compute more or fewer functions? Recursion iteration!

From Subroutines to Libraries 14 / 1 A subroutine solves a specific problem / it computes a specific operation. It is reusable, i.e., it provides a certain functionality.

From Subroutines to Libraries 14 / 1 A subroutine solves a specific problem / it computes a specific operation. It is reusable, i.e., it provides a certain functionality. A collection of germane subroutines yields a library.

From Subroutines to Libraries 14 / 1 A subroutine solves a specific problem / it computes a specific operation. It is reusable, i.e., it provides a certain functionality. A collection of germane subroutines yields a library. A library is not a program per se. It provides building blocks to be used when writing a program.

From Subroutines to Libraries 14 / 1 A subroutine solves a specific problem / it computes a specific operation. It is reusable, i.e., it provides a certain functionality. A collection of germane subroutines yields a library. A library is not a program per se. It provides building blocks to be used when writing a program. BLAS

From Subroutines to Libraries 14 / 1 A subroutine solves a specific problem / it computes a specific operation. It is reusable, i.e., it provides a certain functionality. A collection of germane subroutines yields a library. A library is not a program per se. It provides building blocks to be used when writing a program. BLAS LAPACK

From Subroutines to Libraries 14 / 1 A subroutine solves a specific problem / it computes a specific operation. It is reusable, i.e., it provides a certain functionality. A collection of germane subroutines yields a library. A library is not a program per se. It provides building blocks to be used when writing a program. BLAS LAPACK LINPACK

From Subroutines to Libraries 14 / 1 A subroutine solves a specific problem / it computes a specific operation. It is reusable, i.e., it provides a certain functionality. A collection of germane subroutines yields a library. A library is not a program per se. It provides building blocks to be used when writing a program. BLAS LAPACK LINPACK EISPACK

From Subroutines to Libraries 14 / 1 A subroutine solves a specific problem / it computes a specific operation. It is reusable, i.e., it provides a certain functionality. A collection of germane subroutines yields a library. A library is not a program per se. It provides building blocks to be used when writing a program. BLAS LAPACK LINPACK EISPACK PETSc

From Subroutines to Libraries 14 / 1 A subroutine solves a specific problem / it computes a specific operation. It is reusable, i.e., it provides a certain functionality. A collection of germane subroutines yields a library. A library is not a program per se. It provides building blocks to be used when writing a program. BLAS LAPACK LINPACK EISPACK PETSc MPI

From Subroutines to Libraries 14 / 1 A subroutine solves a specific problem / it computes a specific operation. It is reusable, i.e., it provides a certain functionality. A collection of germane subroutines yields a library. A library is not a program per se. It provides building blocks to be used when writing a program. BLAS LAPACK LINPACK EISPACK PETSc MPI Pthreads... Libraries can be written in one or more languages. Can they be accessed from a program written in a different language?

Imperative vs. Functional Languages 15 / 1 Imperative Languages Concept of Variables and State. Program is an ordered sequence of commands and assignments. Commands modify state. Side-effects. C, C++, Fortran, Java, Python, Matlab,...

Imperative vs. Functional Languages 15 / 1 Imperative Languages Concept of Variables and State. Program is an ordered sequence of commands and assignments. Commands modify state. Side-effects. C, C++, Fortran, Java, Python, Matlab,... Functional Languages No variables or assignments. Program consists of Functions and Recursion. No side-effects! Subset of Declarative Languages. Lisp, APL, ADA, Haskell, Mathematica, Clojure, F#...

Scope 16 / 1 Program A; Var I:Integer; K:Char; R:Real; Procedure B; Var K:Real; L:Integer; Procedure C; Var M:Real; Begin // Body #1 End; Begin // Body #2 End; Begin // Body #3 End;

Scope 16 / 1 Program A; Var I:Integer; K:Char; R:Real; Procedure B; Var K:Real; L:Integer; Which variables (of which type) are defined in Body #1? Procedure C; Var M:Real; Begin // Body #1 End; Begin // Body #2 End; Begin // Body #3 End;

Scope 16 / 1 Program A; Var I:Integer; K:Char; R:Real; Procedure B; Var K:Real; L:Integer; Which variables (of which type) are defined in Body #1? I:Integer, R:Real, K:Real, L:Integer, M:Real Procedure C; Var M:Real; Begin // Body #1 End; Begin // Body #2 End; Begin // Body #3 End;

Scope 16 / 1 Program A; Var I:Integer; K:Char; R:Real; Procedure B; Var K:Real; L:Integer; Procedure C; Var M:Real; Begin // Body #1 End; Begin // Body #2 End; Begin // Body #3 End; Which variables (of which type) are defined in Body #1? I:Integer, R:Real, K:Real, L:Integer, M:Real Where is K used as Real?

Scope 16 / 1 Program A; Var I:Integer; K:Char; R:Real; Procedure B; Var K:Real; L:Integer; Procedure C; Var M:Real; Begin // Body #1 End; Begin // Body #2 End; Begin // Body #3 End; Which variables (of which type) are defined in Body #1? I:Integer, R:Real, K:Real, L:Integer, M:Real Where is K used as Real? Body #1 and Body #2

Scope 16 / 1 Program A; Var I:Integer; K:Char; R:Real; Procedure B; Var K:Real; L:Integer; Procedure C; Var M:Real; Begin // Body #1 End; Begin // Body #2 End; Begin // Body #3 End; Which variables (of which type) are defined in Body #1? I:Integer, R:Real, K:Real, L:Integer, M:Real Where is K used as Real? Body #1 and Body #2 Can L be referenced in Body #2? Body #3?

Scope 16 / 1 Program A; Var I:Integer; K:Char; R:Real; Procedure B; Var K:Real; L:Integer; Procedure C; Var M:Real; Begin // Body #1 End; Begin // Body #2 End; Begin // Body #3 End; Which variables (of which type) are defined in Body #1? I:Integer, R:Real, K:Real, L:Integer, M:Real Where is K used as Real? Body #1 and Body #2 Can L be referenced in Body #2? Body #3? Body #2: yes; Body #3: no

Scope (2) program main var y: Real; procedure compute() var x : Integer; procedure initialize() var y: Integer; var z: Real; begin {initialize} // Body #1 end {initialize} procedure transform() var x: Real; begin {transform} // Body #2 end {transform} begin {compute} // Body #3 end {compute} begin {main} // Main body end {main} 17 / 1

Scope (2) program main var y: Real; procedure compute() var x : Integer; procedure initialize() var y: Integer; var z: Real; begin {initialize} // Body #1 end {initialize} What is the scope of the variable x declared in the procedure compute? procedure transform() var x: Real; begin {transform} // Body #2 end {transform} begin {compute} // Body #3 end {compute} begin {main} // Main body end {main} 17 / 1

Scope (2) program main var y: Real; procedure compute() var x : Integer; procedure initialize() var y: Integer; var z: Real; begin {initialize} // Body #1 end {initialize} procedure transform() var x: Real; begin {transform} // Body #2 end {transform} begin {compute} // Body #3 end {compute} begin {main} // Main body end {main} What is the scope of the variable x declared in the procedure compute? Body #1 and Body #3 17 / 1

Scope (2) program main var y: Real; procedure compute() var x : Integer; procedure initialize() var y: Integer; var z: Real; begin {initialize} // Body #1 end {initialize} procedure transform() var x: Real; begin {transform} // Body #2 end {transform} begin {compute} // Body #3 end {compute} begin {main} // Main body end {main} What is the scope of the variable x declared in the procedure compute? Body #1 and Body #3 What is the environment for the procedure transform? 17 / 1

Scope (2) program main var y: Real; procedure compute() var x : Integer; procedure initialize() var y: Integer; var z: Real; begin {initialize} // Body #1 end {initialize} procedure transform() var x: Real; begin {transform} // Body #2 end {transform} begin {compute} // Body #3 end {compute} begin {main} // Main body end {main} What is the scope of the variable x declared in the procedure compute? Body #1 and Body #3 What is the environment for the procedure transform? y:real and x:real 17 / 1