NAMES, SCOPES AND BINDING A REVIEW OF THE CONCEPTS
|
|
- Owen Hicks
- 6 years ago
- Views:
Transcription
1 NAMES, SCOPES AND BINDING A REVIEW OF THE CONCEPTS Name Binding and Binding Time Name binding is the associa1on of objects (data and/or code) with names (iden1fiers) Shape S = new Shape(); The binding of a program element to a par1cular property is the choice of the property from a set of possible proper1es binding and binding 1mes are the proper1es of program elements that are determined by the defini1on of the language or its implementa1on The 1me during program formula1on or processing when this choice is made is the binding +me There are many classes of bindings in programming languages as well as many different binding 1mes
2 Binding Time Binding 1mes: Run 1me (execu1on 1me): On entry to a subprogram or block Binding of formal to actual parameters Binding of formal parameters to storage loca1ons At arbitrary points during execu1on binding of variables to values Dynamic binding Binding Time Compile 1me (Sta1c Time) Declara1ons (programmer ac1on) Variable names variable types program statement structure Compiler ac1on Rela1ve loca1on of data objects Linker ac1ons Rela1ve loca1on of different object modules
3 Binding Time Binding Time
4 Binding Time o The sum operator (+) At compila1on 1me (depending on the type of the operands because of overloading) o If x is declared integer + means one thing o if x is declared real means something else o + can also be overloaded by the programmer. o Example (C++): it is possible to specify that + operates on strings: string operator +(string& a, string& b) { return a.append(b); } Binding Time Shape s= new Shape(); s.getarea(); // The compiler can resolve this method call statically.
5 Binding Time public void MakeSomeFoo(object a) { // Things happen... ((Shape) a).getarea(); // You won't know if this works until runtime!} Binding Time: discussion Many of the most important and subtle differences between programming languages involve differences in binding 1me The trade off is between sta1c analysis, efficient execu1on and flexibility The language comes with a type system. The compiler assigns a type expression to parts of the source program. The compiler checks that the type usage in the program conforms to the type system for the language. When efficiency is a considera1on (Fortran, C) languages are designed so that as many bindings as possible are performed during transla1on Where flexibility is the prime determiner, bindings are delayed un1l execu1on 1me so that they may be made data dependent
6 Dynamic Dispatch " Dynamic dispatch allows the code executed when a message is sent to an object (o.m(x)) to be determined by run- 1me values. " interface Shape {... void draw() {... } } class Circle extends Shape {... void draw() {... } } class Square extends Shape {... void draw() {... } }... Shape s =...; //could be a circle a square, or something else. s.draw(); " Invoking s.draw() could run the code for any of the methods shown in the program (or for any other class that extends Shape). " Java, all methods (except for sta1c methods) are dispatched dynamically. In " C++, only virtual members are dispatched dynamically. " Note that dynamic dispatch is not the same as overloading, which is usually resolved using the sta1c types of the arguments to the func1on being called.
7 Objects life1me Program execution time Creation of an object Object lifetime Creation of a binding Binding lifetime Destruction of a binding Destruction of an object Dangling reference if these two times are interchanged Dangling References Int * p = new int; Int * q = new int; // things happen on p and q delete p; //Other things happens Use(q)
8 Dangling references #include<stdio.h> int *call(); void main(){ int*ptr; ptr=call(); fflush(stdin); printf("%d",*ptr); } int * call(){ int x=25; ++x; return &x; }
9 Storage Management Programming languages provide three storage alloca1on mechanisms o Sta1c Absolute address retained troughout program s execu1on o Stack Dynamic alloca1on with calls&returns o Heap Allocated and de- allocated at arbitrary 1me Sta1c Alloca1on Global variables Constants o manifest, declared (parameter variables in Fortran) or iden1fied by the compiler Variables iden1fied as const in C can be a func1on of non constants and therefore cannot be sta1cally allocated Constant tables generated by the compiler for debugging and other purposes
10 Sta1c Alloca1on In the absence of recursion, all variables can be sta1cally allocated Also, can be sta1cally allocated: o Arguments and return values (or their addresses). Alloca1on can be in processor registers rather than in memory o Temporaries o Bookkeeping informa1on return address saved registers debugging informa1on Sta1c Alloca1on
11 Stack- based Alloca1on Needed when language permits recursion Useful in languages without recursion because it can save space Each subrou1ne invoca1on creates a frame or ac1va1on record o arguments o return address o local variables o temporaries o bookkeeping informa1on Stack maintained by o calling sequence o prologue o epilogue Stack- based Alloca1on (Cont.)
12 Una funzione ricorsiva int Func ( /* in */ int a, /* in */ int b ) { int result; if ( b == 0 ) // base case result = 0; else if ( b > 0 ) // first general case result = a + Func ( a, b - 1 ) ) ; } return result; 23 Run- Time Stack Ac1va1on Records x = Func(5, 2);// original call at instruction 100 FCTVAL? result? b 2 a 5 Return Address 100 original call at instruction 100 pushes on this record for Func(5,2) 24
13 Run- Time Stack Ac1va1on Records x = Func(5, 2);// original call at instruction 100 FCTVAL? result? b 1 a 5 Return Address 50 FCTVAL? result 5+Func(5,1) =? b 2 a 5 Return Address 100 call in Func(5,2) code at instruction 50 pushes on this record for Func(5,1) record for Func(5,2) 25 Run- Time Stack Ac1va1on Records x = Func(5, 2);// original call at instruction 100 FCTVAL? result? b 0 a 5 Return Address 50 FCTVAL? result 5+Func(5,0) =? b 1 a 5 Return Address 50 FCTVAL? result 5+Func(5,1) =? b 2 a 5 Return Address 100 call in Func(5,1) code at instruction 50 pushes on this record for Func(5,0) record for Func(5,1) record for Func(5,2) 26
14 Run- Time Stack Ac1va1on Records x = Func(5, 2);// original call at instruction 100 FCTVAL 0 result 0 b 0 a 5 Return Address 50 FCTVAL? result 5+Func(5,0) =? b 1 a 5 Return Address 50 FCTVAL? result 5+Func(5,1) =? b 2 a 5 Return Address 100 record for Func(5,0) is popped first with its FCTVAL record for Func(5,1) record for Func(5,2) 27 Run- Time Stack Ac1va1on Records x = Func(5, 2);// original call at instruction 100 FCTVAL 5 result 5+Func(5,0) = 5+ 0 b 1 a 5 Return Address 50 FCTVAL? result 5+Func(5,1) =? b 2 a 5 Return Address 100 record for Func(5,1) is popped next with its FCTVAL record for Func(5,2) 28
15 Run- Time Stack Ac1va1on Records x = Func(5, 2);// original call at instruction 100 FCTVAL 10 result 5+Func(5,1) = 5+5 b 2 a 5 Return Address 100 record for Func(5,2) is popped last with its FCTVAL 29 Heap- based Alloca1on Region of storage in which blocks of memory can be allocated and de- allocated at arbitrary 1mes Because they are not allocated in the stack, the life1me of objects allocated in the heap is not confined to the subrou1ne where they are created o They can be assigned to parameters (or to components of objects accessed via pointers by parameters) o They can be returned as value of the subrou1ne/func1on/ method
16 Find the errors in this code Heap- based Alloca1on Several strategies to manage space in the heap Fragmenta1on o Internal fragmenta+on when space allocated is larger than needed o External fragmenta+on when allocated blocks are scahered through the heap. Total space available might be more than requested, but no block has the needed size
17 Heap- based Alloca1on One approach to maintain the free memory space is to use a free list Two strategies to find a block for a give request o First fit: use first block in the list large enough to sa1sfy the request o Best fit: search the list to find the smallest block that sa1sfy the request The free list could be organized as an array of free lists where each list in the array contain blocks of the same size Cells and Liveness " Cell = data item in the heap o Cells are pointed to by pointers held in registers, stack, global/sta1c memory, or in other heap cells " Roots: registers, stack loca1ons, global/sta1c variables " A cell is live if its address is held in a root or held by another live cell in the heap
18 Garbage " Garbage is a block of heap memory that cannot be accessed by the program o An allocated block of heap memory does not have a reference to it (cell is no longer live ) " Garbage collec1on (GC) - automa1c management of dynamically allocated storage o Reclaim unused heap blocks for later use by program slide 35 Example of Garbage class node { int value; node next; } node p, q; p = new node(); q = new node(); q = p; delete p; slide 36
19 The Perfect Garbage Collector " No visible impact on program execu1on " Works with any program and its data structures o For example, handles cyclic data structures " Collects garbage (and only garbage) cells quickly o Incremental; can meet real- 1me constraints " Has excellent spa1al locality of reference o No excessive paging, no nega1ve cache effects " Manages the heap efficiently o Always sa1sfies an alloca1on request and does not fragment slide 37 Reference Coun1ng: Example Heap space root set slide 38
20 Reference Coun1ng: Cycles root set Heap space 1 Memory leak slide 39 Mark- Sweep Example (1) Heap space root set slide 40
21 Mark- Sweep Example (2) Heap space root set slide 41 Mark- Sweep Example (3) Heap space root set slide 42
22 Mark- Sweep Example (4) root set Heap space Free unmarked cells Reset mark bit of marked cells slide 43 Genera1onal Garbage Collec1on " Observa1on: most cells that die, die young o Nested scopes are entered and exited more frequently, so temporary objects in a nested scope are born and die close together in 1me " Divide the heap into genera1ons, and GC the younger cells more frequently o Amor1ze the cost across genera1ons slide 44
23 Example with Immediate Aging (1) root set A C D Young B E F Old G slide 45 Example with Immediate Aging (2) root set C D Young E A F Old G B slide 46
24 Genera1ons with Semi- Spaces root set... From-space To-space Youngest Middle generation(s) Oldest From-space To-space slide 47 SCOPE
25 Variable A variable is a loca+on (AKA reference) that can be associated with a value. Obtaining the value associated with a variable is called dereferencing, and crea1ng or changing the associa1on is called assignment. Seman1cs of Programming Languages
26 Formal Model Graphical Names x y z 3.14 abc s fun x y z x s fun Env Store abc Scope and extent
27 Typed Variables In sta1cally- typed languages, a variable also has a type, meaning that only values of a given type can be stored in it In dynamically- typed languages, values, not variables, have types Scope rules The region of the program in which a binding is ac1ve is its scope Most languages today are lexically scoped Some languages (e.g. Perl) have both lexical and dynamic scoping
28 Sta1c Scope - Nested Subrou1nes In most languages any constant, type, variables or subrou1nes declared within a subrou1ne are not visible outside the subrou1ne Closest nested scope rule: a name is known in the scope in which it is declared unless it is hidden by another declara1on of the same name Sta1c Scope - Nested Subrou1nes (2) procedure P1(A1: T1); var X: real; procedure P2(A2: T2); procedure P3(A3: T3); begin (*body of P3 *) end; begin (* body of P2 *) end; procedure P4(A4: T4); function F1(A5: T5) : T6; var X: integer; begin (* body of F1 *) end; begin (* body of P4 *) end; begin (* body of P1 *) end;
29 Sta1c Scope - Nested Subrou1nes (3) To find the frames of surrounding scopes where the desired data is a sta1c link could be used func1on A() { int I; func1on B() { int J; func1on C() { int K; K=I+J; B(); } C(); } // body of B. B(); } // body of A. A calls B calls C calls B calls C.
30 Sta1c Scope - Nested Subrou1nes (4) Sta1c Scope - Nested Subrou1nes (5) { /* B1 */! { /* B2 */! { /* B3 */! { /* B4 */! AR B4 AR B3 }! }! AR B2 }! }! AR B1
31 class Outer { final int x; class Inner { //int x; void foo() { x; } } } void bar() { Inner i = new Inner(); int x; i.foo(); } GNU MIPS
32 gcc MIPS gcc x386 sp local m local m-1... local 1 old fp return addr arg1 arg2... argn fp
33 Example Example: invoca1on
34 int baz(int x, int y) { char buf[256]; { int z = y + 1; x += z; } return x + y; } Example
35 Modules Modulariza1on depends on informa1on hiding Func1ons and subrou1nes can be used to hide informa1on. However, this is not flexible enough. One reason is that persistent data is usually needed to create abstrac1on. This can be addressed in some cases using sta1cally allocated values Sta1c Scope - Modules (Cont.)
36 Sta1c Scope - Modules (Cont.) But modulariza1on oten requires a variety of opera1ons on persistent data. Sta1c Scope - Modules (Cont.) Objects inside a module are visible to each other Objects inside can be hidden explicitly (using a keyword like private) or implicitly (objects are only visible outside if they are exported) In some language objects outside need to be imported to be visible within the module
37 Sta1c Scope - Modules Modula- 2 examples VAR a,b: CARDINAL;! MODULE M;!!IMPORT a; EXPORT w,x;!!var u,v,w; CARDINAL;!!MODULE N;!!!IMPORT u; EXPORT x,y;!!!var x,y,z: CARDINAL;!!!(* x,u,y,z visible here *)!!END N;!!(* a,u,v,w,x,y visible here *)! END M;! (* a,b,w,x visible here *)!
38 Modules as types Dynamic scope In early Lisp systems variables were bound dynamically rather than sta1cally In a language with dynamic binding, free variables in a procedure get their values from the environment in which the procedure is called rather than the environment in which the procedure is defined
39 Symbol Tables Symbol tables are used to keep track of scope and binding informa1on about names. The symbol table is searched every 1me a name is encountered in the source text Changes occur when a new name or new informa1on about a name is discovered The abstract syntax tree will contain pointers to the symbol table rather than the actual names used for objects in the source text Symbol Tables (Cont.) Each symbol table entry contains o the symbol name o its category (scalar variable, array, constant, type, procedure, field name, parameter, etc.) o scope number o type (a pointer to another symbol table entry) o and addi1onal, category specific fields (e.g. rank and shape for arrays) To keep symbol table records uniform, it may be convenient for some of the informa1on about a name to be kept outside the table entry, with only a pointer to this informa1on stored in the entry
40 Symbol Tables (Cont.) The symbol table may contain the keywords at the beginning if the lexical scanner searches the symbol table for each name Alterna1vely, the lexical scanner can iden1fy keywords using a separate table or by crea1ng a separate final state for each keyword Symbol Tables (Cont.) One of the important issues is handling sta1c scope A simple solu1on is to create a symbol table for each scope and ahach it to the node in the abstract syntax tree corresponding to the scope An alter na1ve is to use a addi+onal data structure to keep track of the scope. This structure would resemble a stack:
41 4 top A C B A additional 2 0 scope_marker 2 LL symbol table Symbol Tables (Cont.) A hash table can be added to the previous data structure to accelerate the search. Elements with the same name are linked from top to bohom. Search start at the entry of the hash table and proceeds through the linked list un1l the end of the list is reached (old_id) or un1l the link list refers to an element below scope_marker(ll - 1) (new_id)
42 Symbol Tables (Cont.) Symbol Tables
43 Symbol Tables (Cont.) Associa1on Lists and Central Reference Tables
44 The binding of referencing environments P1()! { REAL X! { /* B1 */! { /* B2 */! { /* B3 */! P2(P3)! }!! P3()!! {!!x!! }! }! P2(PX)! {! PX()! }! }! }! AR P3 PX AR P2 AR B3 AR B2 AR B1 AR P1
Principles of Programming Languages
Principles of Programming Languages h"p://www.di.unipi.it/~andrea/dida2ca/plp- 14/ Prof. Andrea Corradini Department of Computer Science, Pisa Lesson 18! Bootstrapping Names in programming languages Binding
More informationG Programming Languages - Fall 2012
G22.2110-003 Programming Languages - Fall 2012 Lecture 2 Thomas Wies New York University Review Last week Programming Languages Overview Syntax and Semantics Grammars and Regular Expressions High-level
More informationPrinciples of Programming Languages
Principles of Programming Languages h"p://www.di.unipi.it/~andrea/dida2ca/plp- 15/ Prof. Andrea Corradini Department of Computer Science, Pisa Lesson 13! Scoping rules and their implementa;on 1 Summary
More informationCS 345. Garbage Collection. Vitaly Shmatikov. slide 1
CS 345 Garbage Collection Vitaly Shmatikov slide 1 Major Areas of Memory Static area Fixed size, fixed content, allocated at compile time Run-time stack Variable size, variable content (activation records)
More informationResearch opportuni/es with me
Research opportuni/es with me Independent study for credit - Build PL tools (parsers, editors) e.g., JDial - Build educa/on tools (e.g., Automata Tutor) - Automata theory problems e.g., AutomatArk - Research
More informationNames, Scopes, and Bindings. CSE 307 Principles of Programming Languages Stony Brook University
Names, Scopes, and Bindings CSE 307 Principles of Programming Languages Stony Brook University http://www.cs.stonybrook.edu/~cse307 1 Names, Scopes, and Bindings Names are identifiers (mnemonic character
More informationCompilers. 8. Run-time Support. Laszlo Böszörmenyi Compilers Run-time - 1
Compilers 8. Run-time Support Laszlo Böszörmenyi Compilers Run-time - 1 Run-Time Environment A compiler needs an abstract model of the runtime environment of the compiled code It must generate code for
More informationCSE P 501 Compilers. Memory Management and Garbage Collec<on Hal Perkins Winter UW CSE P 501 Winter 2016 W-1
CSE P 501 Compilers Memory Management and Garbage Collec
More informationNames, Scopes, and Bindings. CSE 307 Principles of Programming Languages Stony Brook University
Names, Scopes, and Bindings CSE 307 Principles of Programming Languages Stony Brook University http://www.cs.stonybrook.edu/~cse307 1 Names, Scopes, and Bindings Names are identifiers (mnemonic character
More informationProgramming Languages
Programming Languages Tevfik Koşar Lecture - VIII February 9 th, 2006 1 Roadmap Allocation techniques Static Allocation Stack-based Allocation Heap-based Allocation Scope Rules Static Scopes Dynamic Scopes
More informationPrinciples of Programming Languages Topic: Scope and Memory Professor Louis Steinberg Fall 2004
Principles of Programming Languages Topic: Scope and Memory Professor Louis Steinberg Fall 2004 CS 314, LS,BR,LTM: Scope and Memory 1 Review Functions as first-class objects What can you do with an integer?
More informationName, Scope, and Binding. Outline [1]
Name, Scope, and Binding In Text: Chapter 3 Outline [1] Variable Binding Storage bindings and lifetime Type bindings Type Checking Scope Lifetime vs. Scope Referencing Environments N. Meng, S. Arthur 2
More informationChapter 4: Memory. Taylor & Francis Adair Dingle All Rights Reserved
Chapter 4: Memory Program Memory Overview Analysis of the impact of design on memory use Memory Abstrac9on Heap Memory Memory Overhead Memory Management Programmer s Perspec9ve Standard Views of Memory
More informationProgramming Languages Third Edition. Chapter 7 Basic Semantics
Programming Languages Third Edition Chapter 7 Basic Semantics Objectives Understand attributes, binding, and semantic functions Understand declarations, blocks, and scope Learn how to construct a symbol
More informationRun-time Environments
Run-time Environments Status We have so far covered the front-end phases Lexical analysis Parsing Semantic analysis Next come the back-end phases Code generation Optimization Register allocation Instruction
More informationRun-time Environments
Run-time Environments Status We have so far covered the front-end phases Lexical analysis Parsing Semantic analysis Next come the back-end phases Code generation Optimization Register allocation Instruction
More information6. Names, Scopes, and Bindings
Copyright (C) R.A. van Engelen, FSU Department of Computer Science, 2000-2004 6. Names, Scopes, and Bindings Overview Names Binding time Object lifetime Object storage management Static allocation Stack
More informationProgramming Languages Third Edition. Chapter 10 Control II Procedures and Environments
Programming Languages Third Edition Chapter 10 Control II Procedures and Environments Objectives Understand the nature of procedure definition and activation Understand procedure semantics Learn parameter-passing
More information! Those values must be stored somewhere! Therefore, variables must somehow be bound. ! How?
A Binding Question! Variables are bound (dynamically) to values Subprogram Activation! Those values must be stored somewhere! Therefore, variables must somehow be bound to memory locations! How? Function
More informationLecture 7: Binding Time and Storage
Lecture 7: Binding Time and Storage COMP 524 Programming Language Concepts Stephen Olivier February 5, 2009 Based on notes by A. Block, N. Fisher, F. Hernandez-Campos, and D. Stotts Goal of Lecture The
More informationProcedure and Object- Oriented Abstraction
Procedure and Object- Oriented Abstraction Scope and storage management cs5363 1 Procedure abstractions Procedures are fundamental programming abstractions They are used to support dynamically nested blocks
More informationMemory Management. CS449 Fall 2017
Memory Management CS449 Fall 2017 Life9mes Life9me: 9me from which a par9cular memory loca9on is allocated un9l it is deallocated Three types of life9mes Automa9c (within a scope) Sta9c (dura9on of program)
More informationToday's Topics. CISC 458 Winter J.R. Cordy
Today's Topics Last Time Semantics - the meaning of program structures Stack model of expression evaluation, the Expression Stack (ES) Stack model of automatic storage, the Run Stack (RS) Today Managing
More informationSE352b: Roadmap. SE352b Software Engineering Design Tools. W3: Programming Paradigms
SE352b Software Engineering Design Tools W3: Programming Paradigms Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa SE352b: Roadmap CASE Tools: Introduction System Programming Tools Programming Paradigms
More informationAnswer: Early binding generally leads to greater efficiency (compilation approach) Late binding general leads to greater flexibility
Quiz Review Q1. What is the advantage of binding things as early as possible? Is there any advantage to delaying binding? Answer: Early binding generally leads to greater efficiency (compilation approach)
More informationLecture 2: Memory in C
CIS 330:! / / / / (_) / / / / _/_/ / / / / / \/ / /_/ / `/ \/ / / / _/_// / / / / /_ / /_/ / / / / /> < / /_/ / / / / /_/ / / / /_/ / / / / / \ /_/ /_/_/_/ _ \,_/_/ /_/\,_/ \ /_/ \ //_/ /_/ Lecture 2:
More informationCS 330 Lecture 18. Symbol table. C scope rules. Declarations. Chapter 5 Louden Outline
CS 0 Lecture 8 Chapter 5 Louden Outline The symbol table Static scoping vs dynamic scoping Symbol table Dictionary associates names to attributes In general: hash tables, tree and lists (assignment ) can
More informationContents. 8-1 Copyright (c) N. Afshartous
Contents 1. Introduction 2. Types and Variables 3. Statements and Control Flow 4. Reading Input 5. Classes and Objects 6. Arrays 7. Methods 8. Scope and Lifetime 9. Utility classes 10 Introduction to Object-Oriented
More informationCSCI312 Principles of Programming Languages!
CSCI312 Principles of Programming Languages! Scope Xu Liu ! 4.1 Syntactic Issues! 4.2 Variables! 4.3 Scope! 4.4 Symbol Table! 4.5 Resolving References! 4.6 Dynamic Scoping! 4.7 Visibility! 4.8 Overloading!
More informationOpera&ng Systems CMPSCI 377 Garbage Collec&on. Emery Berger and Mark Corner University of Massachuse9s Amherst
Opera&ng Systems CMPSCI 377 Garbage Collec&on Emery Berger and Mark Corner University of Massachuse9s Amherst Ques
More informationCSE 504: Compiler Design. Runtime Environments
Runtime Environments Pradipta De pradipta.de@sunykorea.ac.kr Current Topic Procedure Abstractions Mechanisms to manage procedures and procedure calls from compiler s perspective Runtime Environment Choices
More informationNames and Abstractions: What s in a Name?
Copyright R.A. van Engelen, FSU Department of Computer Science, 2000 Names, Scopes, and Bindings Binding time Object lifetime Object storage management Static allocation Stack allocation Heap allocation
More informationBBM 101 Introduc/on to Programming I Fall 2014, Lecture 3. Aykut Erdem, Erkut Erdem, Fuat Akal
BBM 101 Introduc/on to Programming I Fall 2014, Lecture 3 Aykut Erdem, Erkut Erdem, Fuat Akal 1 Today Introduc/on to Programming Basic Concepts Developing Algorithms Crea
More informationCOP4020 Programming Languages. Names, Scopes, and Bindings Prof. Robert van Engelen
COP4020 Programming Languages Names, Scopes, and Bindings Prof. Robert van Engelen Overview Abstractions and names Binding time Object lifetime Object storage management Static allocation Stack allocation
More informationRun-time Environments - 3
Run-time Environments - 3 Y.N. Srikant Computer Science and Automation Indian Institute of Science Bangalore 560 012 NPTEL Course on Principles of Compiler Design Outline of the Lecture n What is run-time
More informationNames, Bindings, Scopes
Names, Bindings, Scopes Variables In imperative l Language: abstractions of von Neumann machine Variables: abstraction of memory cell or cells Sometimes close to machine (e.g., integers), sometimes not
More informationExample. program sort; var a : array[0..10] of integer; procedure readarray; : function partition (y, z :integer) :integer; var i, j,x, v :integer; :
Runtime Environment Relationship between names and data objects (of target machine) Allocation & de-allocation is managed by run time support package Each execution of a procedure is an activation of the
More informationImperative Programming
Naming, scoping, binding, etc. Instructor: Dr. B. Cheng Fall 2004 1 Imperative Programming The central feature of imperative languages are variables Variables are abstractions for memory cells in a Von
More informationG Programming Languages - Fall 2012
G22.2110-003 Programming Languages - Fall 2012 Lecture 4 Thomas Wies New York University Review Last week Control Structures Selection Loops Adding Invariants Outline Subprograms Calling Sequences Parameter
More informationSemantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler Front-End
Outline Semantic Analysis The role of semantic analysis in a compiler A laundry list of tasks Scope Static vs. Dynamic scoping Implementation: symbol tables Types Static analyses that detect type errors
More informationCS558 Programming Languages. Winter 2013 Lecture 3
CS558 Programming Languages Winter 2013 Lecture 3 1 NAMES AND BINDING One essential part of being a high-level language is having convenient names for things: variables constants types functions etc. classes
More informationScope, Functions, and Storage Management
Scope, Functions, and Storage Management Implementing Functions and Blocks cs3723 1 Simplified Machine Model (Compare To List Abstract Machine) Registers Code Data Program Counter (current instruction)
More informationNames, Scope, and Bindings
Names, Scope, and Bindings COMS W4115 Prof. Stephen A. Edwards Fall 2007 Columbia University Department of Computer Science What s In a Name? Name: way to refer to something else variables, functions,
More informationNames, Scope, and Bindings
Names, Scope, and Bindings COMS W4115 Prof. Stephen A. Edwards Fall 2003 Columbia University Department of Computer Science What s In a Name? Name: way to refer to something else variables, functions,
More informationCSC 533: Organization of Programming Languages. Spring 2005
CSC 533: Organization of Programming Languages Spring 2005 Language features and issues variables & bindings data types primitive complex/structured expressions & assignments control structures subprograms
More informationCSE 307: Principles of Programming Languages
1 / 26 CSE 307: Principles of Programming Languages Names, Scopes, and Bindings R. Sekar 2 / 26 Topics Bindings 1. Bindings Bindings: Names and Attributes Names are a fundamental abstraction in languages
More informationAnatomy of a Compiler. Overview of Semantic Analysis. The Compiler So Far. Why a Separate Semantic Analysis?
Anatomy of a Compiler Program (character stream) Lexical Analyzer (Scanner) Syntax Analyzer (Parser) Semantic Analysis Parse Tree Intermediate Code Generator Intermediate Code Optimizer Code Generator
More informationDesign Issues. Subroutines and Control Abstraction. Subroutines and Control Abstraction. CSC 4101: Programming Languages 1. Textbook, Chapter 8
Subroutines and Control Abstraction Textbook, Chapter 8 1 Subroutines and Control Abstraction Mechanisms for process abstraction Single entry (except FORTRAN, PL/I) Caller is suspended Control returns
More informationThe role of semantic analysis in a compiler
Semantic Analysis Outline The role of semantic analysis in a compiler A laundry list of tasks Scope Static vs. Dynamic scoping Implementation: symbol tables Types Static analyses that detect type errors
More informationTypes II. Hwansoo Han
Types II Hwansoo Han Arrays Most common and important composite data types Homogeneous elements, unlike records Fortran77 requires element type be scalar Elements can be any type (Fortran90, etc.) A mapping
More informationNames, Scope, and Bindings
Names, Scope, and Bindings COMS W4115 Prof. Stephen A. Edwards Spring 2007 Columbia University Department of Computer Science What s In a Name? Name: way to refer to something else variables, functions,
More informationRuntime. The optimized program is ready to run What sorts of facilities are available at runtime
Runtime The optimized program is ready to run What sorts of facilities are available at runtime Compiler Passes Analysis of input program (front-end) character stream Lexical Analysis token stream Syntactic
More informationCSE 413 Midterm, May 6, 2011 Sample Solution Page 1 of 8
Question 1. (12 points) For each of the following, what value is printed? (Assume that each group of statements is executed independently in a newly reset Scheme environment.) (a) (define x 1) (define
More informationCIT Week13 Lecture
CIT 3136 - Week13 Lecture Runtime Environments During execution, allocation must be maintained by the generated code that is compatible with the scope and lifetime rules of the language. Typically there
More informationCSE Lecture 10: Modules and separate compila5on 18 Feb Nate Nystrom University of Texas at Arlington
CSE 5317 Lecture 10: Modules and separate compila5on 18 Feb 2010 Nate Nystrom University of Texas at Arlington Modules Key to building large sodware systems is ability to organize the program into modules
More informationJava's Memory Management
Java's Memory Management Oliver W. Layton CS231: Data Structures and Algorithms Lecture 04, Fall 2018 Wednesday September 12 Java %p of the day: Common compila%on errors Class name must MATCH the filename
More informationInformatica 3 Syntax and Semantics
Informatica 3 Syntax and Semantics Marcello Restelli 9/15/07 Laurea in Ingegneria Informatica Politecnico di Milano Introduction Introduction to the concepts of syntax and semantics Binding Variables Routines
More informationRun Time Environments
Run Time Environments ALSU Textbook Chapter 7.1 7.3 Tsan-sheng Hsu tshsu@iis.sinica.edu.tw http://www.iis.sinica.edu.tw/~tshsu 1 Preliminaries During the execution of a program, the same name in the source
More informationCompiler Construction
Compiler Construction Thomas Noll Software Modeling and Verification Group RWTH Aachen University https://moves.rwth-aachen.de/teaching/ss-16/cc/ Recap: Static Data Structures Outline of Lecture 18 Recap:
More informationScope. Chapter Ten Modern Programming Languages 1
Scope Chapter Ten Modern Programming Languages 1 Reusing Names Scope is trivial if you have a unique name for everything: fun square a = a * a; fun double b = b + b; But in modern languages, we often use
More informationGarbage collec,on Parameter passing in Java. Sept 21, 2016 Sprenkle - CSCI Assignment 2 Review. public Assign2(int par) { onevar = par; }
Objec,ves Inheritance Ø Overriding methods Garbage collec,on Parameter passing in Java Sept 21, 2016 Sprenkle - CSCI209 1 Assignment 2 Review private int onevar; public Assign2(int par) { onevar = par;
More informationShort Notes of CS201
#includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system
More informationWhy Pointers. Pointers. Pointer Declaration. Two Pointer Operators. What Are Pointers? Memory address POINTERVariable Contents ...
Why Pointers Pointers They provide the means by which functions can modify arguments in the calling function. They support dynamic memory allocation. They provide support for dynamic data structures, such
More informationProgramming Language Concepts Scoping. Janyl Jumadinova January 31, 2017
Programming Language Concepts Scoping Janyl Jumadinova January 31, 2017 Scope Rules A scope is a program section of maximal size in which no bindings change, or at least in which no re-declarations are
More informationProgramming Language Implementation
A Practical Introduction to Programming Language Implementation 2014: Week 10 Garbage Collection College of Information Science and Engineering Ritsumeikan University 1 review of last week s topics dynamic
More informationCSc 520 Principles of Programming Languages. Questions. rocedures as Control Abstractions... 30: Procedures Introduction
Procedures as Control Abstractions CSc 520 Principles of Programming Languages 30: Procedures Introduction Christian Collberg collberg@cs.arizona.edu Department of Computer Science University of Arizona
More informationCS201 - Introduction to Programming Glossary By
CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with
More informationCS558 Programming Languages
CS558 Programming Languages Winter 2017 Lecture 4a Andrew Tolmach Portland State University 1994-2017 Semantics and Erroneous Programs Important part of language specification is distinguishing valid from
More informationCS558 Programming Languages
CS558 Programming Languages Fall 2016 Lecture 3a Andrew Tolmach Portland State University 1994-2016 Formal Semantics Goal: rigorous and unambiguous definition in terms of a wellunderstood formalism (e.g.
More informationChapter 5 Names, Bindings, Type Checking, and Scopes
Chapter 5 Names, Bindings, Type Checking, and Scopes Names Variables The Concept of Binding Scope and Lifetime Type Checking Referencing Environments Named Constants Names Used for variables, subprograms
More informationEvery language has its own scoping rules. For example, what is the scope of variable j in this Java program?
Lexical Binding There are two ways a variable can be used in a program: As a declaration As a "reference" or use of the variable Scheme has two kinds of variable "declarations" -- the bindings of a let-expression
More informationSemantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler so far
Outline Semantic Analysis The role of semantic analysis in a compiler A laundry list of tasks Scope Static vs. Dynamic scoping Implementation: symbol tables Types Statically vs. Dynamically typed languages
More informationConcepts Introduced in Chapter 7
Concepts Introduced in Chapter 7 Storage Allocation Strategies Static Stack Heap Activation Records Access to Nonlocal Names Access links followed by Fig. 7.1 EECS 665 Compiler Construction 1 Activation
More informationCSE Compilers. Reminders/ Announcements. Lecture 15: Seman9c Analysis, Part III Michael Ringenburg Winter 2013
CSE 401 - Compilers Lecture 15: Seman9c Analysis, Part III Michael Ringenburg Winter 2013 Winter 2013 UW CSE 401 (Michael Ringenburg) Reminders/ Announcements Project Part 2 due Wednesday Midterm Friday
More informationWays to implement a language
Interpreters Implemen+ng PLs Most of the course is learning fundamental concepts for using PLs Syntax vs. seman+cs vs. idioms Powerful constructs like closures, first- class objects, iterators (streams),
More informationOutline. Pointers arithme.c and others Func.ons & pointers
Pointers II 1 Outline Pointers arithme.c and others Func.ons & pointers 2 Pointer Arithme/c When you add to or subtract from a pointer, the amount by which you do that is mul/plied by the size of the type
More informationBBM 101 Introduc/on to Programming I Fall 2013, Lecture 6-7
BBM 101 Introduc/on to Programming I Fall 2013, Lecture 6-7 Instructors: Aykut Erdem, Erkut Erdem, Fuat Akal TAs: Yasin Sahin, Ahmet Selman Bozkir, Gultekin Isik, Oguzhan Guclu 1 Today Func/ons Defini@ons
More informationAgenda. Address vs. Value Consider memory to be a single huge array. Review. Pointer Syntax. Pointers 9/9/12
Agenda CS 61C: Great Ideas in Computer Architecture Introduc;on to C, Part II Instructors: Krste Asanovic Randy H. Katz hep://inst.eecs.berkeley.edu/~cs61c/f12 Review Pointers Administrivia Arrays Technology
More informationAcknowledgements These slides are based on Kathryn McKinley s slides on garbage collection as well as E Christopher Lewis s slides
Garbage Collection Last time Compiling Object-Oriented Languages Today Motivation behind garbage collection Garbage collection basics Garbage collection performance Specific example of using GC in C++
More informationCS 101: Computer Programming and Utilization
CS 101: Computer Programming and Utilization Jul-Nov 2017 Umesh Bellur (cs101@cse.iitb.ac.in) Lecture 16: Representing variable length entities (introducing new and delete) A programming problem Design
More informationBinding and Storage. COMP 524: Programming Language Concepts Björn B. Brandenburg. The University of North Carolina at Chapel Hill
Binding and Storage Björn B. Brandenburg The University of North Carolina at Chapel Hill Based in part on slides and notes by S. Olivier, A. Block, N. Fisher, F. Hernandez-Campos, and D. Stotts. What s
More informationSystem Software Assignment 1 Runtime Support for Procedures
System Software Assignment 1 Runtime Support for Procedures Exercise 1: Nested procedures Some programming languages like Oberon and Pascal support nested procedures. 1. Find a run-time structure for such
More informationThe basic operations defined on a symbol table include: free to remove all entries and free the storage of a symbol table
SYMBOL TABLE: A symbol table is a data structure used by a language translator such as a compiler or interpreter, where each identifier in a program's source code is associated with information relating
More informationWeeks 6&7: Procedures and Parameter Passing
CS320 Principles of Programming Languages Weeks 6&7: Procedures and Parameter Passing Jingke Li Portland State University Fall 2017 PSU CS320 Fall 17 Weeks 6&7: Procedures and Parameter Passing 1 / 45
More informationChapter 5. Names, Bindings, and Scopes
Chapter 5 Names, Bindings, and Scopes Chapter 5 Topics Introduction Names Variables The Concept of Binding Scope Scope and Lifetime Referencing Environments Named Constants 1-2 Introduction Imperative
More informationWhat about Object-Oriented Languages?
What about Object-Oriented Languages? What is an OOL? A language that supports object-oriented programming How does an OOL differ from an ALL? (ALGOL-Like Language) Data-centric name scopes for values
More informationProject. there are a couple of 3 person teams. a new drop with new type checking is coming. regroup or see me or forever hold your peace
Project there are a couple of 3 person teams regroup or see me or forever hold your peace a new drop with new type checking is coming using it is optional 1 Compiler Architecture source code Now we jump
More informationCS101: Fundamentals of Computer Programming. Dr. Tejada www-bcf.usc.edu/~stejada Week 1 Basic Elements of C++
CS101: Fundamentals of Computer Programming Dr. Tejada stejada@usc.edu www-bcf.usc.edu/~stejada Week 1 Basic Elements of C++ 10 Stacks of Coins You have 10 stacks with 10 coins each that look and feel
More informationCA Compiler Construction
CA4003 - Compiler Construction David Sinclair When procedure A calls procedure B, we name procedure A the caller and procedure B the callee. A Runtime Environment, also called an Activation Record, is
More informationEDAN65: Compilers, Lecture 13 Run;me systems for object- oriented languages. Görel Hedin Revised:
EDAN65: Compilers, Lecture 13 Run;me systems for object- oriented languages Görel Hedin Revised: 2014-10- 13 This lecture Regular expressions Context- free grammar ATribute grammar Lexical analyzer (scanner)
More informationSpecial Topics: Programming Languages
Lecture #17 0 V22.0490.001 Special Topics: Programming Languages B. Mishra New York University. Lecture # 17 Lecture #17 1 Slide 1 Runtime Representations Variable Names Environment L-values Scope, Extent
More informationCompiler Construction
Compiler Construction Lecture 18: Code Generation V (Implementation of Dynamic Data Structures) Thomas Noll Lehrstuhl für Informatik 2 (Software Modeling and Verification) noll@cs.rwth-aachen.de http://moves.rwth-aachen.de/teaching/ss-14/cc14/
More informationCS 536 Introduction to Programming Languages and Compilers Charles N. Fischer Lecture 11
CS 536 Introduction to Programming Languages and Compilers Charles N. Fischer Lecture 11 CS 536 Spring 2015 1 Handling Overloaded Declarations Two approaches are popular: 1. Create a single symbol table
More informationImplementing Subprograms
1 Implementing Subprograms CS 315 Programming Languages Pinar Duygulu Bilkent University CS315 Programming Languages Pinar Duygulu The General Semantics of Calls and Returns 2 The subprogram call and return
More informationStructure of Programming Languages Lecture 10
Structure of Programming Languages Lecture 10 CS 6636 4536 Spring 2017 CS 6636 4536 Lecture 10: Classes... 1/23 Spring 2017 1 / 23 Outline 1 1. Types Type Coercion and Conversion Type Classes, Generics,
More informationG Programming Languages Spring 2010 Lecture 4. Robert Grimm, New York University
G22.2110-001 Programming Languages Spring 2010 Lecture 4 Robert Grimm, New York University 1 Review Last week Control Structures Selection Loops 2 Outline Subprograms Calling Sequences Parameter Passing
More informationOperating Systems CMPSCI 377, Lec 2 Intro to C/C++ Prashant Shenoy University of Massachusetts Amherst
Operating Systems CMPSCI 377, Lec 2 Intro to C/C++ Prashant Shenoy University of Massachusetts Amherst Department of Computer Science Why C? Low-level Direct access to memory WYSIWYG (more or less) Effectively
More informationLanguage of the Machine Recursive functions
EECS 322 Computer Architecture Language of the Machine Recursive functions Instructor: Francis G. Wolff wolff@eecs.cwru.edu Case Western Reserve University This presentation uses powerpoint animation:
More informationNOTE: Answer ANY FOUR of the following 6 sections:
A-PDF MERGER DEMO Philadelphia University Lecturer: Dr. Nadia Y. Yousif Coordinator: Dr. Nadia Y. Yousif Internal Examiner: Dr. Raad Fadhel Examination Paper... Programming Languages Paradigms (750321)
More informationCMSC 330: Organization of Programming Languages
CMSC 330: Organization of Programming Languages Memory Management and Garbage Collection CMSC 330 - Spring 2013 1 Memory Attributes! Memory to store data in programming languages has the following lifecycle
More information