1 / 29

Fall 2011 Marco Valtorta and Jingsong Wang mgv@cse.sc

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).

ghowie
Download Presentation

Fall 2011 Marco Valtorta and Jingsong Wang mgv@cse.sc

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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)

  2. 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

  3. 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

  4. 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

  5. Variable name and scope The scope of a variable is the range of program instructions over which the variable is known and manipulable

  6. Static vs. Dynamic Scoping

  7. User-defined Data Types Warning: this program uses pointer arithmetic!

  8. Pointers to Unnamed Variables

  9. Routines: Procedures and Functions

  10. Declaration, Definition, and Mutual Recursion

  11. Generic Routines

  12. 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;

  13. The SIMPLESEM Machine

  14. A Static Language (C1) Program

  15. Initial State

  16. Adding Simple Routines

  17. A Snapshot

  18. Separate Compilation

  19. A Language with Recursion: C3

  20. Data Memory as a Stack of ARs

  21. SIMPLESEM Code for C3 Example

  22. Snapshots of Data Memory

  23. Block Structure I: Nested Blocks

  24. Block Structure II: Locally Declared Routines

  25. Call and Return for C4’’

  26. Dynamic Scope: C5

  27. Parameter Passing

  28. Routine Parameters

More Related