





































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An overview of language semantics, focusing on operational semantics, axiomatic semantics, and denotational semantics. The lecture covers the concepts of machine configurations, semantic rules, and examples using a simple imperative language (imp).
Typology: Study notes
1 / 45
This page cannot be seen from the preview
Don't miss anything!






































Outline Transition SemanticsLanguage Semantics
Mark Hills [email protected]
University of Illinois at Urbana-Champaign
July 14, 2008
(^1) Based on slides by Mattox Beckman, as updated by Vikram Adve, Gul Agha, and Elsa Gunter
Outline Transition Semantics^ Language Semantics
Language Semantics
Transition Semantics
Outline Transition Semantics^ Language Semantics^ An Overview of Semantics^ Varieties of Language Semantics
Time flies like an arrow. Fruit flies like a banana.
So far, we have syntax, but we don’t know what any of it means! Language semantics provide a way for us to assign meaning to constructs in a programming language.
Outline Transition Semantics^ Language Semantics^ An Overview of Semantics^ Varieties of Language Semantics
Semantics can be grouped into two general categories: static semantics and dynamic semantics. ◮ (^) Static semantics provide meaning based solely on the form of a language construct, or the syntax – not based on execution. These are usually restricted to type checking and inference. ◮ (^) Dynamic semantics provide meaning based on models of evaluation for the language. These tell us what it means to execute a program, for instance.
Outline Transition Semantics^ Language Semantics^ An Overview of Semantics^ Varieties of Language Semantics
◮ (^) First, start with a definition of our “machine” which we run programs on ◮ (^) The machine state, including the program, is often called the configuration ◮ (^) Next, describe how to execute programs in a given language by describing how to execute individual statements and parts of statements – rules follow the structure of the program ◮ (^) A program’s “meaning” is defined by how it changes the configuration ◮ (^) Useful as a basis for implementations
Outline Transition Semantics^ Language Semantics^ An Overview of Semantics^ Varieties of Language Semantics
Axiomatic semantics are also called Floyd-Hoare logic ◮ (^) based on logic – first-order predicate calculus ◮ (^) semantics represented as a logical system build from axioms and inference rules ◮ (^) mainly suited to simple imperative languages ◮ (^) used to prove a post-condition from a pre-condition: given something holds in the starting state, we can show something else holds in the end state
{Precondition} Program {Postcondition}
Outline Transition Semantics^ Language Semantics^ An Overview of Semantics^ Varieties of Language Semantics
There are many other methods which have been devised to give semantics to languages. ◮ (^) “Compiler-based” semantics – the meaning is whatever the compiler says it is ◮ (^) Abstract Machines – similar to operational, an abstract machine with instructions, etc is devised and used to give semantics ◮ (^) Term Rewriting – semantics are formulated as term rewriting systems, with evaluation given by the rewriting relation ◮ (^) Rewriting Logic – an extension of equational logic that provides for concurrency
Outline Transition SemanticsLanguage Semantics
Introduction to Transition Semantics A Sample LanguageConfigurations Semantic Rules ExampleExtending the Language
Transition semantics is a form of operational semantics. ◮ (^) Configurations include the code and machine state: (C , m) ◮ (^) Semantics specified as transitions between configurations, altering the machine state ◮ (^) Rules of the form: 〈C , m〉 → 〈C ′, m′〉 ◮ (^) C , C ′^ represents the code yet to be executed ◮ (^) m, m′^ represents the state (store, memory, etc), often a finite map from names to values ◮ (^) May not need m – simple calculator languages with only numbers and operations don’t, for instance Key point: each transition indicates exactly one step of computation
Outline Transition SemanticsLanguage Semantics
Introduction to Transition Semantics A Sample Language Configurations Semantic Rules ExampleExtending the Language
Using a variant of BNF, we can specify the syntax for IMP as:
Aexp a ::= n | X | a 0 + a 1 | a 0 − a 1 | a 0 × a 1 Bexp b ::= true | false | a 0 = a 1 | a 0 ≤ a 1 | ¬b | b 0 ∧ b 1 | b 0 ∨ b 1 Com c ::= skip | X := a | c 0 ; c 1 | if b then c 0 else c 1 | while b do c
Important Point: We assume reasonable input programs that parse and we don’t care about precedence, associativity, etc – we assume all that has been figured out for us
Outline Transition SemanticsLanguage Semantics
Introduction to Transition Semantics A Sample Language Configurations Semantic Rules ExampleExtending the Language
Our configurations will contain two elements: ◮ (^) The code (a, b, or c) ◮ (^) The state We can define the set of states Σ as functions σ : Loc → N, or functions from locations to integer values.
Outline Transition SemanticsLanguage Semantics
Introduction to Transition Semantics A Sample LanguageConfigurations Semantic Rules ExampleExtending the Language
〈a 0 , σ〉 → 〈a′ 0 , σ〉 〈a 0 + a 1 , σ〉 → 〈a′ 0 + a 1 , σ〉
〈a 1 , σ〉 → 〈a′ 1 , σ〉 〈n 0 + a 1 , σ〉 → 〈n 0 + a′ 1 , σ〉
〈n 0 + n 1 , σ〉 → n, where n = n 0 +int n 1
Outline Transition SemanticsLanguage Semantics
Introduction to Transition Semantics A Sample LanguageConfigurations Semantic Rules ExampleExtending the Language
〈a 0 , σ〉 → 〈a′ 0 , σ〉 〈a 0 − a 1 , σ〉 → 〈a′ 0 − a 1 , σ〉
〈a 1 , σ〉 → 〈a′ 1 , σ〉 〈n 0 − a 1 , σ〉 → 〈n 0 − a′ 1 , σ〉
〈n 0 − n 1 , σ〉 → n, where n = n 0 −int n 1
Outline Transition SemanticsLanguage Semantics
Introduction to Transition Semantics A Sample LanguageConfigurations Semantic Rules ExampleExtending the Language
Our semantic relation for boolean expressions will be of the form:
〈b, σ〉 → t
We assume boolean expressions have no side-effects. ◮ (^) We have simple axioms for boolean constants, including true: 〈true, σ〉 → true ◮ (^) and false: 〈false, σ〉 → false
Outline Transition SemanticsLanguage Semantics
Introduction to Transition Semantics A Sample LanguageConfigurations Semantic Rules ExampleExtending the Language
〈a 0 , σ〉 → 〈a′ 0 , σ〉 〈a 0 = a 1 , σ〉 → 〈a′ 0 = a 1 , σ〉
〈a 1 , σ〉 → 〈a′ 1 , σ〉 〈n 0 = a 1 , σ〉 → 〈n 0 = a′ 1 , σ〉
〈n 0 = n 1 , σ〉 → b, where b = (n 0 =int n 1 )
The rules for ≤ are similar.