Names and Attributes Names are a key programming language feature

Slides:



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

Programming Languages and Paradigms
Names and Bindings.
CSE 425: Semantic Analysis Semantic Analysis Allows rigorous specification of a program’s meaning –Lets (parts of) programming languages be proven correct.
CSE 425: Semantics II Implementing Scopes A symbol table is in essence a dictionary –I.e., every name appears in it, with the info known about it –Usually.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Ch.2: Syntax and Semantics Fall 2005.
Chapter 9 Subprogram Control Consider program as a tree- –Each parent calls (transfers control to) child –Parent resumes when child completes –Copy rule.
Chapter 5 Basic Semantics
CS 330 Programming Languages 10 / 16 / 2008 Instructor: Michael Eckmann.
Names and Scopes CS 351. Program Binding We should be familiar with this notion. A variable is bound to a method or current block e.g in C++: namespace.
1 Pertemuan 20 Run-Time Environment Matakuliah: T0174 / Teknik Kompilasi Tahun: 2005 Versi: 1/6.
Run time vs. Compile time
The Concept of Variables
Chapter 9: Subprogram Control
1 Run time vs. Compile time The compiler must generate code to handle issues that arise at run time Representation of various data types Procedure linkage.
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
CSE 425: Data Types II Survey of Common Types I Records –E.g., structs in C++ –If elements are named, a record is projected into its fields (e.g., via.
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 5: Programming Languages and Constructs by Ravi Sethi Activation Records Dolores Zage.
Chapter 7 Runtime Environments. Relationships between names and data objects As execution proceeds, the same name can denote different data objects Procedures,
CSE 425: Object-Oriented Programming I Object-Oriented Programming A design method as well as a programming paradigm –For example, CRC cards, noun-verb.
The Procedure Abstraction, Part V: Support for OOLs Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in.
1 Scope Rules (Section 3.3) CSCI 431 Programming Languages Fall 2003 A compilation of material developed by Felix Hernandez-Campos and Michael Scott.
Introduction A variable can be characterized by a collection of properties, or attributes, the most important of which is type, a fundamental concept in.
Basic Semantics Associating meaning with language entities.
CSE 425: Data Types I Data and Data Types Data may be more abstract than their representation –E.g., integer (unbounded) vs. 64-bit int (bounded) A language.
Programming Languages and Paradigms Imperative Programming.
Run-Time Storage Organization Compiler Design Lecture (03/23/98) Computer Science Rensselaer Polytechnic.
COMP3190: Principle of Programming Languages
CSE 425: Control Abstraction I Functions vs. Procedures It is useful to differentiate functions vs. procedures –Procedures have side effects but usually.
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.
Programming Languages and Design Lecture 6 Names, Scopes and Binding Instructor: Li Ma Department of Computer Science Texas Southern University, Houston.
7. Runtime Environments Zhang Zhizheng
CSE 425: Control Abstraction II Exception Handling Previous discussion focuses on normal control flow –Sometimes program reaches a point where it cannot.
1 Structure of Compilers Lexical Analyzer (scanner) Modified Source Program Parser Tokens Semantic Analysis Syntactic Structure Optimizer Code Generator.
RUNTIME ENVIRONMENT AND VARIABLE BINDINGS How to manage local variables.
CS 330 Programming Languages 10 / 23 / 2007 Instructor: Michael Eckmann.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Operational Semantics (Slides mainly.
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?
Chapter 5 Names, Bindings, Type Checking CSCE 343.
Advanced Programming in C
Chapter 10 : Implementing Subprograms
Run-Time Environments Chapter 7
CS 326 Programming Languages, Concepts and Implementation
CS 326 Programming Languages, Concepts and Implementation
Type Checking, and Scopes
CS 326 Programming Languages, Concepts and Implementation
Semantics CSE 340 – Principles of Programming Languages Spring 2016
Chapter 10: Implementing Subprograms Sangho Ha
Names, Binding, and Scope
CSE 3302 Programming Languages
Chap. 8 :: Subroutines and Control Abstraction
Chap. 8 :: Subroutines and Control Abstraction
CSCE 330 Programming Language Structures Ch.2: Syntax and Semantics
Iteration Implemented through loop constructs (e.g., in C++)
Parallelism and Concurrency
Binding Times Binding is an association between two things Examples:
Delayed Evaluation Special forms in Scheme (e.g., if and cond) do not use applicative order evaluation Only one of two or more expressions is actually.
Activation records Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
UNIT V Run Time Environments.
Programming Languages
CSE 3302 Programming Languages
RUN-TIME STORAGE Chuen-Liang Chen Department of Computer Science
Activation records Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Presentation transcript:

Names and Attributes Names are a key programming language feature Also known as labels or identifiers Allow a program to declare and refer to an abstraction Names almost always have additional attributes E.g., a type, which may depend on other names Names with data types also have a value attribute Variables also will have a location, but constants might not A function’s signature includes its name and its type I.e., its name and the ordered list of types the function takes Attributes may be bound to labels at different times Lexically scoped languages often bind statically (prior to execution) though some features may be bound dynamically

Bindings A binding associates a set of attributes with a name E.g., int &i = j; // i is a reference to int j Bindings can occur at many different times Language design time: control flow constructs, constructors Language implementation time: 32 vs 64 bit int, etc. Programming time: names given to algorithms, objects, etc. Compile time: templates are instantiated (types are bound), machine code produced for functions and methods Link time: calls between compilation units are linked up Load time: virtual addresses mapped to physical ones Run time: scopes are entered and left, dynamic allocation of objects, updates to variables, pointers, and references, etc.

Static, Stack, and Dynamic Allocation In static allocation, unchanging names are introduced E.g., program code, global or static objects, etc. Manifest constants can be defined at compile time as well In stack based allocation, scoped names are added Recursion requires a stack to maintain frames for calls Elaboration time constants, local variables, parameters, etc. In heap based allocation, names appear any time I.e., whenever the program calls a dynamic allocation operator, constructor, etc. Deallocation may be either explicit or implicit If implicit, garbage collection is often needed

Declarations, Blocks, and Scope A declaration explicitly binds some information to an identifier, and may bind other information implicitly E.g, the statement int x; explicitly binds integer type attribute int with identifier x, implicitly binds a location for x, and may or may not implicitly bind a value (i.e., 0) for x Declarations that bind all attributes are called definitions Declarations that leave some attributes unbound are called simply declarations, or sometimes prototypes A block is a sequence of declarations and definitions Declarations that are specific to a block are locally scoped Program-wide declarations are globally scoped Block-structured languages allow both nesting of blocks and scoped re-declaration of identifiers (via lexical addressing) Classes, structs, namespaces, packages also create scopes

Scope Rules A scope identifies where a binding is active E.g., from the point where it is declared until its block ends In modern languages, often determined statically at compile time (lexically scoped through the process of compilation) Static scoping vs. nested subroutines Scoping layout can be established at compile time but the details must be managed at run-time in many languages I.e., inter-frame pointers, instruction counter, etc. on stack Declaration order may require additional semantics E.g., in C++ can declare and define bindings separately Modules and classes have possibly different uses For functional subdivision vs. encapsulation respectively E.g., namespaces vs. structs and classes in C++

Today’s Studio Exercises We’ll code up ideas from Scott Chapter 3.1-3.3 Looking at the semantics of different C++ constructs Building and managing a simple symbol table Next time we’ll look at additional topics and extend our symbol table implementation (save your code!) Today’s exercises are again in C++ Please take advantage of the on-line reference manual pages that are linked on the course web site As always, please ask us for help as needed When done, email your answers to the course e-mail account with “Semantics Studio I” in the subject