Bindings. Typical stages of program execution First, the program is compiled Then everything is loaded into memory Then it is linked to any library routines.

Slides:



Advertisements
Similar presentations
OO Programming in Java Objectives for today: Overriding the toString() method Polymorphism & Dynamic Binding Interfaces Packages and Class Path.
Advertisements

Programming Languages and Paradigms
Names and Bindings.
Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
The Functions and Purposes of Translators Code Generation (Intermediate Code, Optimisation, Final Code), Linkers & Loaders.
Chapter 5: Elementary Data Types Properties of types and objects –Data objects, variables and constants –Data types –Declarations –Type checking –Assignment.
Variables Names Bindings Type Scope. L-Value versus R-Value Not complicated Associated with assignment statements Left hand side represents an address.
Chapter 9 Subprograms Sections 1-5 and 9. Copyright © 2007 Addison-Wesley. All rights reserved. 1–2 Introduction Two fundamental abstraction facilities.
Chapter 5 Basic Semantics
CS 330 Programming Languages 10 / 16 / 2008 Instructor: Michael Eckmann.
CS 330 Programming Languages 10 / 18 / 2007 Instructor: Michael Eckmann.
ISBN Chapter 9 Subprograms. Copyright © 2006 Addison-Wesley. All rights reserved.1-2 Introduction Two fundamental abstraction facilities.
CS 330 Programming Languages 10 / 24 / 2006 Instructor: Michael Eckmann.
Names and Bindings Introduction Names Variables The concept of binding Chapter 5-a.
1 Introduction to Semantics The meaning of a language.
Programming Languages and Paradigms Object-Oriented Programming.
Chapter TwelveModern Programming Languages1 Memory Locations For Variables.
CS 330 Programming Languages 10 / 21 / 2008 Instructor: Michael Eckmann.
COP4020 Programming Languages
Static and Dynamic Behavior CMPS Power of OOP Derives from the ability of objects to change their behavior dynamically at run time. Static – refers.
CSC3315 (Spring 2009)1 CSC 3315 Programming Languages Hamid Harroud School of Science and Engineering, Akhawayn University
5-1 Chapter 5: Names, Bindings, Type Checking, and Scopes Variables The Concept of Binding Type Checking Strong Typing Type Compatibility Scope and Lifetime.
Subprograms Support process abstraction and modularity –characteristics of subprograms are that they have a single entry point the calling entity is suspended.
1 Names, Scopes and Bindings Aaron Bloomfield CS 415 Fall
Chapter 5: Programming Languages and Constructs by Ravi Sethi Activation Records Dolores Zage.
Copyright © 2002, Systems and Computer Engineering, Carleton University a-JavaReview.ppt * Object-Oriented Software Development Unit.
What is an Array? An array is a collection of variables. Arrays have three important properties: –group of related items(for example, temperature for.
Introduction A variable can be characterized by a collection of properties, or attributes, the most important of which is type, a fundamental concept in.
CSSE501 Object-Oriented Development. Chapter 11: Static and Dynamic Behavior  In this chapter we will examine the differences between static and dynamic.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Basic Semantics Associating meaning with language entities.
CSC3315 (Spring 2008)1 CSC 3315 Subprograms Hamid Harroud School of Science and Engineering, Akhawayn University
Programming Languages and Paradigms Imperative Programming.
ECE122 Feb. 22, Any question on Vehicle sample code?
COP4020 Programming Languages Names, Scopes, and Bindings Prof. Xin Yuan.
Implementing Subprograms What actions must take place when subprograms are called and when they terminate? –calling a subprogram has several associated.
COMP3190: Principle of Programming Languages
RUN-Time Organization Compiler phase— Before writing a code generator, we must decide how to marshal the resources of the target machine (instructions,
ISBN Chapter 9 Subprograms Sections
Names, Bindings, and Scope Session 3 Course : T Programming Language Concept Year : February 2011.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
Concepts of programming languages Chapter 5 Names, Bindings, and Scopes Lec. 12 Lecturer: Dr. Emad Nabil 1-1.
ISBN Object-Oriented Programming Chapter Chapter
Programming Languages and Design Lecture 6 Names, Scopes and Binding Instructor: Li Ma Department of Computer Science Texas Southern University, Houston.
How to execute Program structure Variables name, keywords, binding, scope, lifetime Data types – type system – primitives, strings, arrays, hashes – pointers/references.
Variables reference, coding, visibility. Rules for making names  permitted character set  maximum length, significant length  case sensitivity  special.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
1 Structure of Compilers Lexical Analyzer (scanner) Modified Source Program Parser Tokens Semantic Analysis Syntactic Structure Optimizer Code Generator.
CS 330 Programming Languages 10 / 23 / 2007 Instructor: Michael Eckmann.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
1 Asstt. Prof Navjot Kaur Computer Dept PRESENTED BY.
Names, Scope, and Bindings Programming Languages and Paradigms.
Binding & Dynamic Linking Presented by: Raunak Sulekh(1013) Pooja Kapoor(1008)
Code Generation Instruction Selection Higher level instruction -> Low level instruction Register Allocation Which register to assign to hold which items?
Chapter 9 Subprograms.
Data Types In Text: Chapter 6.
Type Checking Generalizes the concept of operands and operators to include subprograms and assignments Type checking is the activity of ensuring that the.
Type Checking, and Scopes
Chapter 5 Names, Bindings, Type Checking, and Scopes.
CSCI 3370: Principles of Programming Languages Chapter 9 Subprograms
CSC 533: Programming Languages Spring 2015
Memory Management Tasks
Binding Times Binding is an association between two things Examples:
Activation records Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Names and Binding In Text: Chapter 5.
CSC 533: Programming Languages Spring 2018
CSC 533: Programming Languages Spring 2019
Types and Related Issues
Activation records Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Presentation transcript:

Bindings

Typical stages of program execution First, the program is compiled Then everything is loaded into memory Then it is linked to any library routines it uses –Linking and loading are often combined into a single step Finally, the program executes

Binding times A binding is an association of two things Typically, a name is bound to something Bindings can occur at different types. Examples: –Language design--keywords to language constructs –Compilation--Variable names to types –Linking--Names to library units –Loading--Code and data to storage locations –Execution--Variable names to values These are language-dependent examples!

FORTRAN bindings FORTRAN distinguishes declarations from statements Declarations are “non-executable” Declarations bind names to types (at “compile time”) and to storage locations (at “load time”) Declarations may bind initial values to variables Statements are executable (done at “run time”) Statements may also bind values to variables

Why binding time matters This function works correctly only the first time Some variables in C are initialized the same way FUNCTION SUM (A, N) DIMENSION A(N) -- specify A as an array of size N INTEGER TOTAL/0/ -- set TOTAL = 0 (at compile time) DO 50 I=1, N -- do statement 50 N times 50 TOTAL=TOTAL+A(I) -- add A[i] to TOTAL RETURN TOTAL -- return TOTAL as the result END

Storage allocation in FORTRAN The FORTRAN compiler binds all variables to storage locations relative to the start of the program unit The FORTRAN loader binds the relative locations to absolute locations This technique cannot support dynamic storage allocation Without dynamic allocation, recursion is impossible FORTRAN versions that support recursion don't use this storage model

A FORTRAN binding problem FORTRAN binds floating-point literals to storage locations The compiler puts the value into the storage location The language does not adequately protect the storage location It’s possible to bind a new value to the storage location Therefore, constants aren’t necessarily constant!

Storage allocation in Algol 60 An area of storage is set aside for “the stack” The Algol compiler binds variables to locations relative to “the top of the stack” The “top of the stack” is bound during execution This technique is ideally suited for supporting recursion Storage allocated on the stack must be discarded in reverse order of acquisition

Bindings in Java Method variables are bound much like in Algol 60 Java does not initialize method variables, but checks to make sure that you do –It is impossible to make this check perfectly Class and instance variables are initialized during object construction –Default is to initialize to zero (null) Messages are dynamically bound to methods

Overloading O-O languages permit method overloading –Methods with the same name but different signatures Ada and Prolog also permit operator overloading In most languages, operators (+, -, *, /, &, etc.) are bound at language design time Ada permits operator overloading during compilation Prolog permits operator overloading during execution Overloaded operators are hard to compile, easy to misuse

Summary Bindings can happen at various times Earlier bindings are more efficient; later bindings are more flexible Sometimes the same kind of binding can occur at different times Mysterious errors can result if bindings don’t occur when you expect them to

The End