Basic Semantics Associating meaning with language entities.

Slides:



Advertisements
Similar presentations
Chapter 3:: Names, Scopes, and Bindings
Advertisements

Symbol Table.
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.
Chapter 5 Names, Bindings, and Scopes
Basic Semantics.
Chapter 9 Subprogram Control Consider program as a tree- –Each parent calls (transfers control to) child –Parent resumes when child completes –Copy rule.
Variables Names Bindings Type Scope. L-Value versus R-Value Not complicated Associated with assignment statements Left hand side represents an address.
Chapter 5 Basic Semantics
Programming Languages Third Edition
CS 330 Programming Languages 10 / 16 / 2008 Instructor: Michael Eckmann.
Chapter 5K. Louden, Programming Languages1 Chapter 5 Basic Semantics.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Chapter 4: Names Fall 2009 Marco Valtorta.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 4 Names The first step toward wisdom is calling.
Run-Time Storage Organization
1 Pertemuan 20 Run-Time Environment Matakuliah: T0174 / Teknik Kompilasi Tahun: 2005 Versi: 1/6.
CS 330 Programming Languages 10 / 24 / 2006 Instructor: Michael Eckmann.
The environment of the computation Declarations introduce names that denote entities. At execution-time, entities are bound to values or to locations:
Chapter 9: Subprogram Control
CSC321: Programming Languages Names Chapter 4: Names 4.1 Syntactic Issues 4.2 Variables 4.3 Scope 4.4 Symbol Table 4.5 Resolving References 4.6 Dynamic.
Names and Bindings Introduction Names Variables The concept of binding Chapter 5-a.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 4 Names The first step toward wisdom is calling.
1 Contents. 2 Run-Time Storage Organization 3 Static Allocation In many early languages, notably assembly and FORTRAN, all storage allocation is static.
Chapter 5 - Basic Semantics
1 Chapter 5: Names, Bindings and Scopes Lionel Williams Jr. and Victoria Yan CSci 210, Advanced Software Paradigms September 26, 2010.
Names and Binding In procedural programming, you write instructions the manipulate the “state” of the process where the “state” is the collection of variables.
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.
Runtime Environments Compiler Construction Chapter 7.
March 12, ICE 1341 – Programming Languages (Lecture #6) In-Young Ko Programming Languages (ICE 1341) Lecture #6 Programming Languages (ICE 1341)
Names and Scope. Scope Suppose that a name is used many times for different entities in text of the program, or in the course of execution. When the name.
Compiler Construction
1 Names, Scopes and Bindings Aaron Bloomfield CS 415 Fall
Chapter 8 - Control II: Procedures and Environments
Chapter 7 Runtime Environments. Relationships between names and data objects As execution proceeds, the same name can denote different data objects Procedures,
Names. 2 Variables  binding is an association between an entity (such as a variable) and a property (such as its value). A binding is static if the association.
Basic Semantics Attributes, Bindings, and Semantic Functions
Introduction A variable can be characterized by a collection of properties, or attributes, the most important of which is type, a fundamental concept in.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Programming Languages and Paradigms Imperative Programming.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. C H A P T E R F I V E Memory Management.
BİL 744 Derleyici Gerçekleştirimi (Compiler Design)1 Run-Time Environments How do we allocate the space for the generated target code and the data object.
Run-Time Storage Organization Compiler Design Lecture (03/23/98) Computer Science Rensselaer Polytechnic.
COMP3190: Principle of Programming Languages
SE424 Languages with Context A Block Structured Language.
Semantics CSE 340 – Principles of Programming Languages Fall 2015 Adam Doupé Arizona State University
Concepts of programming languages Chapter 5 Names, Bindings, and Scopes Lec. 12 Lecturer: Dr. Emad Nabil 1-1.
10-1 Chapter 10: Implementing Subprograms The General Semantics of Calls and Returns Implementing “Simple” Subprograms Implementing Subprograms with Stack-Dynamic.
ISBN Chapter 10 Implementing Subprograms.
Names, Scope, and Bindings Programming Languages and Paradigms.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Operational Semantics (Slides mainly.
1 Compiler Construction Run-time Environments,. 2 Run-Time Environments (Chapter 7) Continued: Access to No-local Names.
CHAPTER 4 VARIABLES & BINDING SUNG-DONG KIM DEPT. OF COMPUTER ENGINEERING, HANSUNG UNIVERSITY.
Run-Time Environments Presented By: Seema Gupta 09MCA102.
Code Generation Instruction Selection Higher level instruction -> Low level instruction Register Allocation Which register to assign to hold which items?
Object Lifetime and Pointers
Data Types In Text: Chapter 6.
Names and Attributes Names are a key programming language feature
CS 326 Programming Languages, Concepts and Implementation
Type Checking, and Scopes
CSE 3302 Programming Languages
Names.
Names, Binding, and Scope
Binding Times Binding is an association between two things Examples:
Programming Languages
CSE 3302 Programming Languages
Lecture 6: Names (Revised based on the Tucker’s slides) 5/27/2019
Types and Related Issues
Run-time environments
Presentation transcript:

Basic Semantics Associating meaning with language entities

Attributes & Binding Attributes associated with variables and other entities –Name –Location –Value

Binding Times Language definition time Language implementation time Translation time (compile time) Link time (linking external entities) Load time (loading the program in memory) Execution time (run time)

Symbol Table The symbol table associates names with attributes –In a compiler the Symbol Table associates names with the static attributes The attributes known only at compile time

Environment & Memory The Environment is a binding of names to storage locations The Memory binds values to locations –Sometimes the memory is referred to as the store or state

Blocks A Block consists of a sequence of declarations and statements surrounded by syntactic markers such as braces or begin-end pairs In many languages blocks are called compound statements

Local & Non-local Declarations Declarations associated with a specific block are called local declarations Declarations in surrounding blocks and global declarations are called non-local declarations

Scope The scope of a binding is the region of the program over which the binding is maintained Lexical scope –Binding limited to the block in which the declaration appears (and any blocks contained within this block)

Declare-Before-Use Rule The scope of a declaration begins at the point of the declaration itself C and Pascal observe this rule

Scope-holes & Visibility A scope-hole occurs when a local declaration takes precedence over a non-local declaration. The non-local variable then has a hole in its scope Visibility of a declaration includes only those areas of the program where the bindings of the declaration apply A declaration may be in scope, but not visible (hence a scope-hole) Some languages provide a scope resolution operator

The Symbol Table A symbol table is like a variable dictionary Operations supported –Insertion –Look-up –Deletion Names and associated attributes are stored, representing bindings

Static Scoping The symbol table is maintained by the compiler The bindings of all declarations are static

Dynamic Scoping The Symbol Table is maintained dynamically, during execution Declarations are processed as they are encountered along the execution path through the program

Name Resolution & Overloading To what extent can the same name be used to refer to different things in a program? The + operator is overloaded –Used to add integers –Used to add floating point numbers –Used to concatenate Strings How does the translator disambiguate these different uses?

Overload Resolution The lookup feature of the Symbol Table is expanded to perform lookups of functions based not only on the name, but also on the number of parameters and their associated data types Ada allows the return type of functions, and even the names of the parameters in the definition also to be used in overload resolution

Other overloading Some languages allow the same name to be used for different kinds of program entities Generally separate name spaces are kept for the different sorts of entities class A { A A(A A) { A: for(;;) { if (A.A(A) == A) break A; } return A; } }

Environment The binding of names to memory locations FORTRAN has a complete static environment Lisp has a complete dynamic environment Block-structured languages usually use a mix of static & dynamic allocation –Globals are allocated statically –Locals are allocated dynamically

Dynamic Environment of Local Variables When a block is entered during execution, variables declared in that block are allocated Upon exit from a block, the bindings of that block are deallocated, leaving the environment as it was before the block was entered

Activation Records Each time a procedure or function is called, its local variables will be allocated The region of memory allocated for the local variables is called an activation record A recursive function or procedure may have several activation records associated with it – one for each recursive call

Lifetime The lifetime of an entity is the duration of its allocation in the environment

Pointers A pointer is an variable whose stored value is a reference to another entity –The value stored is actually the address of the referenced entity A language which allows pointers provides a dereferencing operator to allow access to the object to which the pointer points

The Heap The heap is the area of the environment that is used for arbitrary allocation and deallocation using facilities like new and delete Allocating on the heap is often referred to as dynamic allocation The heap is not to be confused with the data structure called a heap

Allocation Automatic allocation –The allocation of local variables on the stack, accomplished automatically under control of the run-time system Dynamic Allocation –Allocation under user control

Variables A variable is an entity whose value can be changed during execution An assignment statement is the primary way to change the value of a variable –l-values –r-values –Assignment by sharing –Assignment by cloning

Constants A constant is an entity that has a fixed value for the duration of its existence in a program A constant is like a variable except that it has no location attribute, but a value only –Compile-time constants –Load-time constants (static constants) –Manifest constants – those which are names for literal constants

Functions Compile-time functions Function variables, as in C int (*f) (int, int) = gcd; Anonymous functions (function literals) as in ML fn(x:int) => x * x

Aliases An alias occurs when two different names are bound to the same location at the same time –Occurs with the use of pointers –Occurs when a global variable is passed as a parameter to a procedure or function

Dangling References A dangling reference is a location that has been deallocated from the environment, but which can still be accessed by a program

Memory Leaks (Garbage) A memory leak occurs when a reference to a location has been removed from the environment, but the memory on the heap has not been deallocated This can occur when memory has been allocated in a block, and the block has been exited without deallocating the memory

Garbage Collection Garbage collection is a means by which garbage is automatically deallocated by the language system Java provides automatic garbage collection