Docsity

Semantic Interpretation - Lecture Slides | 22C 111, Study notes of Programming Languages

Toggle sidebar
bg1
22c:111 Programming Language Concepts - Fall 2008
22c:111 Programming Language Concepts
Fall 2008
Copyright 2007-08, The McGraw-Hill Company and Cesare Tinelli.
These notes were originally developed by Allen Tucker, Robert Noonan and modified by Cesare Tinelli. They are
copyrighted materials and may not be used in other course settings outside of the University of Iowa in their current form
or modified form without the express written permission of one of the copyright holders. During this course, students are
prohibited from selling notes to or being paid for taking notes by any person or commercial firm without the express
written permission of one of the copyright holders.
Semantic Interpretation
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19

Partial preview of the text

Download Semantic Interpretation - Lecture Slides | 22C 111 and more Study notes Programming Languages in PDF only on Docsity!

22c:111 Programming Language Concepts Fall 2008 Copyright 2007-08, The McGraw-Hill Company and Cesare Tinelli. These notes were originally developed by Allen Tucker, Robert Noonan and modified by Cesare Tinelli. They are copyrighted materials and may not be used in other course settings outside of the University of Iowa in their current form or modified form without the express written permission of one of the copyright holders. During this course, students are prohibited from selling notes to or being paid for taking notes by any person or commercial firm without the express written permission of one of the copyright holders.

Semantic Interpretation

Contents

8.1 State Transformations and Partial

Functions

8.2 Semantics of Clite

8.3 Semantics with Dynamic Typing

8.4 A Formal Treatment of Semantics

Historical Problem

Valid program had different meanings on different

machines

  • More than (e.g.) size of an int or float

Problem was lack of precision in defining meaning

Methods

Compiler C on Machine M

  • Ex: Fortran on IBM 709/
  • Ex: PL/1 (F) on IBM 360 series

Operational Semantics โ€“ Ch. 7

Axiomatic Semantics โ€“ Ch. 18

Denotational Semantics โ€“ Ch. 8.

Simple State

Ignore environment

Set of identifier โ€“ value pairs

Ex: { <i, 13>, <j, -1>}

Special value undefined for each type

8.1 State Transformations

Defn : The denotational semantics of a language

defines the meanings of abstract language elements

as a collection of state-transforming functions.

Defn : A semantic domain is a set of values whose

properties and operations are independently well-

understood and upon which the rules that define

the semantics of a language can be based.

Meaningless Expression

Are all expressions meaningful?

C++Lite Semantics

State โ€“ a mapping from program variables to values

A meaning function M is a mapping:

M: Program โ†’ State M: Statement x State โ†’ State M: Expression x State โ†’ Value

Meaning Rule 8.

The meaning of a Program is defined to be the

meaning of the body when given

an initial state consisting of the variables of the

decpart initialized to the undef value corresponding

to the variable's type.

let p_meaning (decl_list, stat_list) =

s_meaning (Block stat_list) State.empty

Statements

s_meaning: statement โ†’ state โ†’ state type statement = Skip (* ; ) | Block of statement list ( {โ€ฆ} ) | Assign of string * expr ( x = a ) | Cond of expr * statement * statement ( if b s1 else s2 ) | Loop of expr * statement ( while (b) s *)

Meaning Rule 8.3 - Assignment

The output state is computed from the input state by

replacing the value of the target variable by the

computed value of the source expression.

let rec s_meaning (s:statement) (q:state) = match s with โ€ฆ | Assign (x, e) -> let v = e_meaning e q in State.update q x v | โ€ฆ

Meaning Rule 8.4 - Conditional

The meaning of a conditional is:

  • If the meaning of the test is true, the meaning of the then- branch;
  • Otherwise, the meaning of the else-branch

Meaning Rule - Loop

let rec s_meaning (s:statement) (q:state) = match s with โ€ฆ | Loop (e, sโ€™) -> (match (e_meaning e q) with B false -> q | B true -> s_meaning (Block [sโ€™; s]) q | _ -> failwith "Impossible caseโ€ ) | โ€ฆ

Meaning Rule - Block

let rec s_meaning (s:statement) (q:state) = match s with โ€ฆ | Block [] -> q | Block sโ€™::t -> let qโ€™ = s_meaning sโ€™ q in s_meaning (Block t) qโ€™