290 likes | 303 Views
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).
E N D
CSCE 330Programming Language StructuresOperational 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)
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
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
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
Variable name and scope The scope of a variable is the range of program instructions over which the variable is known and manipulable
User-defined Data Types Warning: this program uses pointer arithmetic!
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;