Download presentation
Presentation is loading. Please wait.
1
Prénom Nom Formal Semantics Introduction Rolf Ingold Département d'Informatique Université de Fribourg http://moodle.unifr.ch > Formal Semantics [SP 08]
2
© Prof. Rolf Ingold Chapter content Role of formal semantics Difference between syntax and semantics Difference between mathematics and programming Referential Transparency Difference between language and metalanguage
3
© Prof. Rolf Ingold Formal Semantics Formal semantics serves several purposes: Help in understanding programming languages Support for language design and specification Useful for standardization Support for compiler development and testing Support for software specification Support for program verification and validation Limitations of formal semantics High complexity, hard to learn and to master Inappropriate for most existing languages
4
© Prof. Rolf Ingold Syntax and semantics What is the difference between syntax and semantics ? Syntax describes the structure of programs. It defines well-formed programs. Semantics characterizes the behavior of programs. Semantics relies on syntax. In this course, we distinguish Static semantics, describing static constraints that are not taken into account by syntax, Dynamic semantics describing the effect of programs at runtime.
5
© Prof. Rolf Ingold Mathematics vs. programming The problem with imperative features Most programming languages are imperative and rely on instructions with side effects. Side effects are hard to describe. In mathematics, the notation is asserting the equality between two objects. In programming languages, is a command that assigns the value of e to a variable x. No propriety can be directly inferred. Pure functional languages avoid this difficulty but their practical interest is limited.
6
© Prof. Rolf Ingold Referential Transparency The following propriety is referred to as referential transparency. if and are true, then is true Standard mathematical notations are referentially transparent.
7
© Prof. Rolf Ingold Referential Transparency But programming languages are generally not referentially transparent. Considering the program (Pascal style) the following properties are obtained var y : Integer; function f(var x: Integer): Integer begin y:=y+1; f:=y+x end; y:=0; f(1) + f(1) = 3 but y:=0; 2 * f(1) = 2 y:=0; z:=0; f(y) = 2 but y:=0; z:=0; f(z) = 1
8
© Prof. Rolf Ingold Referential Transparency The objective of the course is to describe constructs of programming languages, which are referentially opaque, by a formalism being referentially transparent.
9
© Prof. Rolf Ingold Language and Metalanguage The programming languages to be studied will be referred to as the languages. The formalism used to describe properties of languages will be called metalanguage. Such a distinction avoids circularity of descriptions.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.