Download presentation
Presentation is loading. Please wait.
Published byBarnard Pearson Modified over 8 years ago
1
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 mgv@cse.sc.edu Sentences are not a mixture of words. Sentences are articulated. (Wittgenstein)
2
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering
3
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
4
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
5
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
6
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
7
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Static vs. Dynamic Scoping
8
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering User-defined Data Types Warning: this program uses pointer arithmetic!
9
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Pointers to Unnamed Variables
10
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Routines: Procedures and Functions
11
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Declaration, Definition, and Mutual Recursion
12
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Generic Routines
13
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;
14
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering The SIMPLESEM Machine
15
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering A Static Language (C1) Program
16
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Initial State
17
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Adding Simple Routines
18
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering A Snapshot
19
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Separate Compilation
20
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering A Language with Recursion: C3
21
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Data Memory as a Stack of ARs
22
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering SIMPLESEM Code for C3 Example
23
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Snapshots of Data Memory
24
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Block Structure I: Nested Blocks
25
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Block Structure II: Locally Declared Routines
26
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Call and Return for C4’’
27
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Dynamic Scope: C5
28
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Parameter Passing
29
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Routine Parameters
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.