Chapter 3:: Names, Scopes, and Bindings

Similar documents
One Ring to rule them all, One Ring to bring them all,

Programming Languages

Names, Scopes, and Bindings. CSE 307 Principles of Programming Languages Stony Brook University

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

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

Names, Scopes, and Bindings. CSE 307 Principles of Programming Languages Stony Brook University

Chapter 8 :: Subroutines and Control Abstraction. Final Test. Final Test Review Tomorrow

Chapter 9 :: Subroutines and Control Abstraction

Chap. 8 :: Subroutines and Control Abstraction

Imperative Programming

Programming Languages

Name, Scope, and Binding. Outline [1]

Control Abstraction. Hwansoo Han

Concepts Introduced in Chapter 7

Run Time Environment. Procedure Abstraction. The Procedure as a Control Abstraction. The Procedure as a Control Abstraction

Programming Languages. Session 2 Main Theme Imperative Languages: Names, Scoping, and Bindings. Dr. Jean-Claude Franchitti

Programming Languages. Session 2 Main Theme Imperative Languages: Names, Scoping, and Bindings. Dr. Jean-Claude Franchitti

Chapter 8 :: Composite Types

COP4020 Programming Languages. Names, Scopes, and Bindings Prof. Robert van Engelen

G Programming Languages - Fall 2012

Binding and Storage. COMP 524: Programming Language Concepts Björn B. Brandenburg. The University of North Carolina at Chapel Hill

6. Names, Scopes, and Bindings

Run Time Environment. Activation Records Procedure Linkage Name Translation and Variable Access

Scope. CSC 4181 Compiler Construction. Static Scope. Static Scope Rules. Closest Nested Scope Rule

Names and Abstractions: What s in a Name?

Heap, Variables, References, and Garbage. CS152. Chris Pollett. Oct. 13, 2008.

Principles of Programming Languages Topic: Scope and Memory Professor Louis Steinberg Fall 2004

CPSC 3740 Programming Languages University of Lethbridge. Data Types

G Programming Languages - Fall 2012

Separate compilation. Topic 6: Runtime Environments p.1/21. CS 526 Topic 6: Runtime Environments The linkage convention

Programming Language Concepts Scoping. Janyl Jumadinova January 31, 2017

Run-time Environments

Types II. Hwansoo Han

Run-time Environments

Every language has its own scoping rules. For example, what is the scope of variable j in this Java program?

Example. program sort; var a : array[0..10] of integer; procedure readarray; : function partition (y, z :integer) :integer; var i, j,x, v :integer; :

Special Topics: Programming Languages

CS 230 Programming Languages

Programming Languages Third Edition. Chapter 10 Control II Procedures and Environments

CS 415 Midterm Exam Spring 2002

Chapter 5. Names, Bindings, and Scopes

Chapter 5 Names, Binding, Type Checking and Scopes

Principles of Programming Languages

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

Programming Languages Third Edition. Chapter 7 Basic Semantics

Chapter 9 :: Data Abstraction and Object Orientation

CSC 533: Organization of Programming Languages. Spring 2005

Procedure and Function Calls, Part II. Comp 412 COMP 412 FALL Chapter 6 in EaC2e. target code. source code Front End Optimizer Back End


! Those values must be stored somewhere! Therefore, variables must somehow be bound. ! How?

Advanced Programming & C++ Language

Implementing Subprograms

CSE 504: Compiler Design. Runtime Environments

Subroutines and Control Abstraction. CSE 307 Principles of Programming Languages Stony Brook University

Run Time Environments

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

Chapter 10 :: Data Abstraction and Object Orientation

NOTE: Answer ANY FOUR of the following 6 sections:

StackVsHeap SPL/2010 SPL/20

CSCI Compiler Design

Programming Languages, Summary CSC419; Odelia Schwartz

Programming Languages

Names, Scopes, and Bindings II. Hwansoo Han

CST-402(T): Language Processors

CS 536 Introduction to Programming Languages and Compilers Charles N. Fischer Lecture 11

St. MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

Java Internals. Frank Yellin Tim Lindholm JavaSoft

Lecture 7: Binding Time and Storage

CS558 Programming Languages

Briefly describe the purpose of the lexical and syntax analysis phases in a compiler.

The Procedure Abstraction

names names identifiers variables subroutines constants

Chapter 9 Subprograms

Subprograms. Copyright 2015 Pearson. All rights reserved. 1-1

C Programming. Course Outline. C Programming. Code: MBD101. Duration: 10 Hours. Prerequisites:

CS558 Programming Languages Winter 2018 Lecture 4a. Andrew Tolmach Portland State University

Runtime Support for Algol-Like Languages Comp 412

INSTITUTE OF AERONAUTICAL ENGINEERING

MIDTERM REVIEW. Lectures 1-15

Run-time Environment

CS 330 Lecture 18. Symbol table. C scope rules. Declarations. Chapter 5 Louden Outline

11. a b c d e. 12. a b c d e. 13. a b c d e. 14. a b c d e. 15. a b c d e

Declaring Pointers. Declaration of pointers <type> *variable <type> *variable = initial-value Examples:

Subroutines. Subroutine. Subroutine design. Control abstraction. If a subroutine does not fit on the screen, it is too long

Programming Language Pragmatics

Memory Management and Run-Time Systems

CS 415 Midterm Exam Spring SOLUTION

Variables and Java vs C++

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

Working of the Compilers

Chapter 11 :: Functional Languages

Index. object lifetimes, and ownership, use after change by an alias errors, use after drop errors, BTreeMap, 309

Memory Allocation. Static Allocation. Dynamic Allocation. Dynamic Storage Allocation. CS 414: Operating Systems Spring 2008

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

Names, Bindings, Scopes

Run-Time Environments

MIDTERM EXAM (Solutions)

Chapter 5 Names, Bindings, Type Checking, and Scopes

Course Overview. Arrays. Static Arrays. Static Arrays. Static Arrays with different lower bound. Static Arrays. PART I: overview material

LECTURE 14. Names, Scopes, and Bindings: Scopes

Transcription:

Chapter 3:: Names, Scopes, and Bindings Programming Language Pragmatics Michael L. Scott

Some more things about NFAs/DFAs We said that a regular expression can be: A character (base case) A concatenation of two regular expressions An alternation (one or the other) A Kleene start Here is a regular language: d * (.d d.) d * It represents decimal numbers The goal is to make a DFA that recognizes it.

Basic NFAs FIGURE 1.6, Inc. All rights reserved. 3

How to use them FIGURE 1.7, Inc. All rights reserved. 4

Making a DFA from an NFA: Subsets of states FIGURE 1.8, Inc. All rights reserved. 5

One last thing from Chapter 2 What is a pragma?

Abstraction Abstraction can mean a lot of things Abstraction from machine language Abstraction in names Abstraction in control (subroutines) Abstraction from machine language The main driving force in early languages Pretty well defined More modern languages are design often in terms of aesthetics, trying to find elegance

Name, Scope, and Binding A name is exactly what you think it is Most names are identifiers symbols (like '+') can also be names A binding is an association between two things, such as a name and the thing it names The scope of a binding is the part of the program (textually)in which the binding is active

Binding Binding Time is the point at which a binding is created or, more generally, the point at which any implementation decision is made language design time program structure, possible types language implementation time I/O, arithmetic overflow, type equality (if unspecified in manual)

Binding Implementation decisions (continued ): program writing time algorithms, names compile time plan for data layout link time layout of whole program in memory load time choice of physical addresses

Binding Implementation decisions (continued): run time value/variable bindings, sizes of strings subsumes program start-up time module entry time elaboration time (point a which a declaration is first "seen") procedure entry time block entry time statement execution time

Binding The terms STATIC and DYNAMIC are generally used to refer to things bound before run time and at run time, respectively static is a coarse term; so is "dynamic" IT IS DIFFICULT TO OVERSTATE THE IMPORTANCE OF BINDING TIMES IN PROGRAMMING LANGUAGES

Binding In general, early binding times are associated with greater efficiency Later binding times are associated with greater flexibility Compiled languages tend to have early binding times Interpreted languages tend to have later binding times Today we talk about the binding of identifiers to the variables they name

Binding Scope Rules - control bindings Fundamental to all programming languages is the ability to name data, i.e., to refer to data using symbolic identifiers rather than addresses Not all data is named! For example, dynamic storage in C or Pascal is referenced by pointers, not names

Lifetime and Storage Management Key events 1. creation of objects 2. creation of bindings 3. references to variables (which use bindings) 4. (temporary) deactivation of bindings 5. reactivation of bindings 6. destruction of bindings 7. destruction of objects

Lifetime and Storage Management The period of time from creation to destruction is called the LIFETIME of a binding If object outlives binding it's garbage If binding outlives object it's a dangling reference The textual region of the program in which the binding is active is its scope In addition to talking about the scope of a binding, we sometimes use the word scope as a noun all by itself, without an indirect object

Lifetime and Storage Management Storage Allocation mechanisms Static Stack Heap Static allocation for code global variables Stored in read-only static or own variables (inside routines) explicit constants (including strings, sets, etc) information about tables

Lifetime and Storage Management Central stack for parameters local variables temporaries Why a stack? allocate space for recursive routines (not necessary in FORTRAN no recursion) reuse space (in all programming languages)

Lifetime and Storage Management Contents of a stack frame (cf., Figure 3.1) arguments and returns local variables temporaries bookkeeping (saved registers, line number static link, etc.) Local variables and arguments are assigned fixed OFFSETS from the stack pointer or frame pointer at compile time

Lifetime and Storage Management

Lifetime and Storage Management Maintenance of stack is responsibility of calling sequence and subroutine prolog and epilog space is saved by putting as much in the prolog and epilog as possible time may be saved by putting stuff in the caller instead or combining what's known in both places (interprocedural optimization)

Lifetime and Storage Management Heap for dynamic allocation