UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Operational Semantics (Slides mainly.

Slides:



Advertisements
Similar presentations
Semantic Analysis Chapter 6. Two Flavors  Static (done during compile time) –C –Ada  Dynamic (done during run time) –LISP –Smalltalk  Optimization.
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.
Chapter 5 Names, Bindings, and Scopes
Chapter 5: Elementary Data Types Properties of types and objects –Data objects, variables and constants –Data types –Declarations –Type checking –Assignment.
(1) ICS 313: Programming Language Theory Chapter 10: Implementing Subprograms.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Ch.2: Syntax and Semantics Fall 2005.
Chapter 5 Basic Semantics
CS 330 Programming Languages 10 / 16 / 2008 Instructor: Michael Eckmann.
ISBN Chapter 5 Names, Bindings, Type Checking, and Scopes Names Variables The Concept of Binding Type Checking Strong Typing Type Compatibility.
Semantics of Calls and Returns
Chapter 9: Subprogram Control
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Chapter 6: Type Systems Fall 2009.
ISBN Chapter 10 Implementing Subprograms –Semantics of Calls and Returns –Implementing “Simple” Subprograms –Implementing Subprograms with.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 531 Compiler Construction Ch.1 Spring 2010 Marco Valtorta
Names and Bindings Introduction Names Variables The concept of binding Chapter 5-a.
1 Contents. 2 Run-Time Storage Organization 3 Static Allocation In many early languages, notably assembly and FORTRAN, all storage allocation is static.
Software II: Principles of Programming Languages Lecture 5 – Names, Bindings, and Scopes.
1 Chapter 5: Names, Bindings and Scopes Lionel Williams Jr. and Victoria Yan CSci 210, Advanced Software Paradigms September 26, 2010.
Imperative Programming
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
Names Variables Type Checking Strong Typing Type Compatibility 1.
5-1 Chapter 5: Names, Bindings, Type Checking, and Scopes Variables The Concept of Binding Type Checking Strong Typing Type Compatibility Scope and Lifetime.
CS 2104 Prog. Lang. Concepts Subprograms
Programming Languages and Design Lecture 7 Subroutines and Control Abstraction Instructor: Li Ma Department of Computer Science Texas Southern University,
Bindings and scope  Bindings and environments  Scope and block structure  Declarations Programming Languages 3 © 2012 David A Watt, University.
March 12, ICE 1341 – Programming Languages (Lecture #6) In-Young Ko Programming Languages (ICE 1341) Lecture #6 Programming Languages (ICE 1341)
Compiler Construction
Chapter 10 Implementing Subprograms. Copyright © 2012 Addison-Wesley. All rights reserved.1-2 Chapter 10 Topics The General Semantics of Calls and Returns.
Chapter 7 Runtime Environments. Relationships between names and data objects As execution proceeds, the same name can denote different data objects Procedures,
Chapter 5 Names, Bindings, and Scopes. Copyright © 2012 Addison-Wesley. All rights reserved.1-2 Chapter 5 Topics Introduction Names Variables The Concept.
ISBN Chapter 5 Names, Bindings, and Scopes.
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.
ISBN Chapter 5 Names, Bindings, and Scopes.
CSC3315 (Spring 2008)1 CSC 3315 Subprograms Hamid Harroud School of Science and Engineering, Akhawayn University
Programming Languages and Paradigms Imperative Programming.
Run-Time Storage Organization Compiler Design Lecture (03/23/98) Computer Science Rensselaer Polytechnic.
Names, Bindings, and Scope Session 3 Course : T Programming Language Concept Year : February 2011.
Structure of Programming Languages Names, Bindings, Type Checking, and Scopes.
Subprograms - implementation
Concepts of programming languages Chapter 5 Names, Bindings, and Scopes Lec. 12 Lecturer: Dr. Emad Nabil 1-1.
Variables reference, coding, visibility. Rules for making names  permitted character set  maximum length, significant length  case sensitivity  special.
Chapter 10 Implementing Subprograms. Copyright © 2012 Addison-Wesley. All rights reserved.1-2 Chapter 10 Topics The General Semantics of Calls and Returns.
ISBN Chapter 10 Implementing Subprograms.
1 Activation records Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Subprograms - implementation. Calling a subprogram  transferring control to a subprogram: save conditions in calling program pass parameters allocate.
Names, Scope, and Bindings Programming Languages and Paradigms.
Procedure Definitions and Semantics Procedures support control abstraction in programming languages. In most programming languages, a procedure is defined.
ISBN Chapter 10 Implementing Subprograms.
CHAPTER 4 VARIABLES & BINDING SUNG-DONG KIM DEPT. OF COMPUTER ENGINEERING, HANSUNG UNIVERSITY.
Run-Time Environments Presented By: Seema Gupta 09MCA102.
Chapter 10 : Implementing Subprograms
Run-Time Environments Chapter 7
Implementing Subprograms
Implementing Subprograms
Names and Attributes Names are a key programming language feature
Type Checking, and Scopes
CS 326 Programming Languages, Concepts and Implementation
Implementing Subprograms
Names, Bindings, and Scopes
Chapter 10: Implementing Subprograms Sangho Ha
Implementing Subprograms
CSCE 330 Programming Language Structures Ch.2: Syntax and Semantics
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
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:

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Operational Semantics (Slides mainly based on Chapter 2 of Ghezzi and Jazayeri) Fall 2011 Marco Valtorta and Jingsong Wang Sentences are not a mixture of words. Sentences are articulated. (Wittgenstein)

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Declarations, Expressions, Commands A command is executed to update variables and perform I/O An expression is evaluated to yield a value A declaration is elaborated (at compile time) to produce bindings. It may also have the side effect of allocating and initializing variables

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Binding Binding is the specification of the attribute for a programming language entity –Entities: variables, statements, subprograms, declarations, etc. –Attributes for a variable: name, type, storage area, etc. Binding times: –Language definition time –Language implementation time –Compile time –Run time Example: the Fortran type INTEGER is bound partly at language definition time and partly at language implementation time Static binding is established before run time, cannot be changed during program execution Dynamic binding can be changed during program execution

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Variables We consider variables for imperative languages Abstraction of memory cells; each cell has an address Most variables have six attributes: name, scope, lifetime, type, l-value, r-value –Some variables have no name The lifetime of a variable is the length of time during which a storage area is bound to a variable The type of a variable is the range of values the variable can take, together with operations to create, access, and modify values

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Variable name and scope The scope of a variable is the range of program instructions over which the variable is known and manipulable

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Static vs. Dynamic Scoping

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering User-defined Data Types Warning: this program uses pointer arithmetic!

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Pointers to Unnamed Variables

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Routines: Procedures and Functions

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Declaration, Definition, and Mutual Recursion

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Generic Routines

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Overloading and Aliasing Operators are overloaded in almost all programming languages –E.g., + is bound to integer or float addition depending on the arguments it is applied to Two names are aliases if they denote the same entity at the same program point. E.g., i and j are aliases in the C program fragment below: –int x = 0; –int *i = &x; –int *j = &x;

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering The SIMPLESEM Machine

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering A Static Language (C1) Program

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Initial State

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Adding Simple Routines

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering A Snapshot

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Separate Compilation

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering A Language with Recursion: C3

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Data Memory as a Stack of ARs

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering SIMPLESEM Code for C3 Example

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Snapshots of Data Memory

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Block Structure I: Nested Blocks

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Block Structure II: Locally Declared Routines

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Call and Return for C4’’

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Dynamic Scope: C5

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Parameter Passing

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Routine Parameters