1 Semantic Description of Programming languages. 2 Static versus Dynamic Semantics n Static Semantics represents legal forms of programs that cannot be.

Slides:



Advertisements
Similar presentations
Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Advertisements

Semantics Static semantics Dynamic semantics attribute grammars
PZ03D Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ03D - Program verification Programming Language Design.
ICE1341 Programming Languages Spring 2005 Lecture #6 Lecture #6 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
Hoare’s Correctness Triplets Dijkstra’s Predicate Transformers
David Evans CS655: Programming Languages University of Virginia Computer Science Lecture 19: Minding Ps & Qs: Axiomatic.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Axiomatic Semantics.
ISBN Chapter 3 Describing Syntax and Semantics.
Dynamic semantics Precisely specify the meanings of programs. Why? –programmers need to understand the meanings of programs they read –programmers need.
Copyright © 2006 Addison-Wesley. All rights reserved. 3.5 Dynamic Semantics Meanings of expressions, statements, and program units Static semantics – type.
Program Proving Notes Ellen L. Walker.
CS 330 Programming Languages 09 / 19 / 2006 Instructor: Michael Eckmann.
CS 355 – Programming Languages
Comp 205: Comparative Programming Languages Semantics of Imperative Programming Languages denotational semantics operational semantics logical semantics.
Describing Syntax and Semantics
Concepts of Programming Languages 1 Describing Syntax and Semantics Brahim Hnich Högskola I Gävle
Axiomatic Semantics Dr. M Al-Mulhem ICS
CS 330 Programming Languages 09 / 18 / 2007 Instructor: Michael Eckmann.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Operational Semantics.
Chapter 3 Describing Syntax and Semantics Sections 1-3.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
PSUCS322 HM 1 Languages and Compiler Design II Formal Semantics Material provided by Prof. Jingke Li Stolen with pride and modified by Herb Mayer PSU Spring.
ISBN Chapter 3 Describing Syntax and Semantics.
Dr. Muhammed Al-Mulhem 1ICS ICS 535 Design and Implementation of Programming Languages Part 1 Fundamentals (Chapter 4) Axiomatic Semantics ICS 535.
Chapter 3 Describing Syntax and Semantics Sections 1-3.
CS 330 Programming Languages 09 / 16 / 2008 Instructor: Michael Eckmann.
Describing Syntax and Semantics
ISBN Chapter 3 Describing Syntax and Semantics.
ISBN Chapter 3 Describing Syntax and Semantics.
Describing Syntax and Semantics
1 Program Correctness CIS 375 Bruce R. Maxim UM-Dearborn.
CSI 3125, Axiomatic Semantics, page 1 Axiomatic semantics The assignment statement Statement composition The "if-then-else" statement The "while" statement.
ISBN Chapter 3 Describing Syntax and Semantics.
Chapter 25 Formal Methods Formal methods Specify program using math Develop program using math Prove program matches specification using.
ISBN Chapter 3 Describing Syntax and Semantics.
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
Course: ICS313 Fundamentals of Programming Languages. Instructor: Abdul Wahid Wali Lecturer, College of Computer Science and Engineering.
CS 363 Comparative Programming Languages Semantics.
Muhammad Idrees Lecturer University of Lahore 1. Outline Introduction The General Problem of Describing Syntax Formal Methods of Describing Syntax Attribute.
3.2 Semantics. 2 Semantics Attribute Grammars The Meanings of Programs: Semantics Sebesta Chapter 3.
ISBN Chapter 3 Describing Semantics.
Chapter 3 Part II Describing Syntax and Semantics.
ISBN Chapter 3 Describing Syntax and Semantics.
Chapter 3 Describing Syntax and Semantics. Copyright © 2012 Addison-Wesley. All rights reserved. 1-2 Chapter 3 Topics Introduction The General Problem.
Programming Languages and Design Lecture 3 Semantic Specifications of Programming Languages Instructor: Li Ma Department of Computer Science Texas Southern.
Semantics In Text: Chapter 3.
Languages and Compilers
COP4020 Programming Languages Introduction to Axiomatic Semantics Prof. Robert van Engelen.
ISBN Chapter 3 Describing Syntax and Semantics.
1 / 48 Formal a Language Theory and Describing Semantics Principles of Programming Languages 4.
Chapter 3 © 2002 by Addison Wesley Longman, Inc Introduction - Who must use language definitions? 1. Other language designers 2. Implementors 3.
Describing Syntax and Semantics Session 2 Course : T Programming Language Concept Year : February 2011.
Chapter 3 Describing Syntax and Semantics. Copyright © 2012 Addison-Wesley. All rights reserved.1-2 Chapter 3 Topics Introduction The General Problem.
ISBN Chapter 3 Describing Syntax and Semantics.
Static Techniques for V&V. Hierarchy of V&V techniques Static Analysis V&V Dynamic Techniques Model Checking Simulation Symbolic Execution Testing Informal.
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
C HAPTER 3 Describing Syntax and Semantics. D YNAMIC S EMANTICS Describing syntax is relatively simple There is no single widely acceptable notation or.
Advanced programming language theory. week 2. Attribute grammars and semantics.
Describing Syntax and Semantics
Syntax Questions 6. Define a left recursive grammar rule.
Axiomatic semantics Points to discuss: The assignment statement
Programming Languages and Compilers (CS 421)
Programming Languages 2nd edition Tucker and Noonan
Semantics In Text: Chapter 3.
Chapter 3 Describing Syntax and Semantics.
Describing Syntax and Semantics
Programming Languages and Compilers (CS 421)
Programming Languages 2nd edition Tucker and Noonan
COP4020 Programming Languages
Presentation transcript:

1 Semantic Description of Programming languages

2 Static versus Dynamic Semantics n Static Semantics represents legal forms of programs that cannot be easily described using a BNF grammar. We call this semantics static because it is verified at compile time. n Dynamic Semantics describes the meaning of programs or the effect caused by a program’s execution.

3 Why do we need to describe Dynamic Semantic? n Programmers need to know exactly what each portion of their program does. n People who design compilers must also know what each instruction must do. n Even though they are not very precise, programmers and compiler designers must use descriptions in English given that formal semantic descriptions are very complex. n Nonetheless, the definition of a formal and adequate notation is important since it can help compiler designers have access to more precise definitions, which could perhaps one day be the basis for the automatic generation of compilers.

4 How is (Dynamic) Semantics Described? There exist three methods for describing Semantics: Operational Description: The meaning of a program is determined by the execution of its listing on a virtual machine. Denotational Description: The meaning of a program is described using functions that show the effect of applying a listing on the state of the machine. Axiomatic Description: the meaning of a program is described using assertions which specify the constraints and relations imposed by a listing.

5 Operational Semantics n The idea behind operational semantics is to describe the meaning of a program by executing its instructions on a real or simulated machine. The changes that take place in the status of the machine when it executes these instructions represent the meaning of this instruction. n In order to build an idealised simulated machine, two components are needed: a translator which translates low-level language, L, and a virtual machine whose status changes as the code written in language L is executed. n Operational Semantics is effective. However, it is not formal and may cause circularities.

6 Denotational Semantics n Denotational Semantics is the most rigourous description method for the semantic description of programs. n The idea consists of defining, for each language entity, a mathematical object and function that attaches instances of this entity to instances of the corresponding mathematical object. n Just like for operational semantics, the status of an idealised machine (in fact, the value of the variables) represents the meaning of an instruction. n The difficulty of this method is in the creation of objects and functions for these objects. The notation is also difficult to read, albeit very concise.

7 Axiomatic Semantic I n Axiomatic Semantic is defined along with a method of proof of program correctness. n When the program is correct, there exists a proof of correctness and in this proof, each proposition is preceded and followed by a logical expression (pre-condition and post-condition) which specify the constraints on the program’s variables. It is these constraints that define the meaning of the program.

8 Axiomatic Semantic II n The weakest pre-condition represents the least restrictive pre-condition which guarantees the correctness of the post- condition associated to the instruction of the program. n If the weakest pre-condition can be calculated from the post-condition defined for each language instruction, proofs of correctness can be constructed for the programs of this language. n The proofs are constructed starting from the end of a program and moving toward its begining. n Axiomatic Semantic is not that useful with respect to the description of the meaning of programming languages because of its complexity. However, it is useful for research and for reasoning about programs.

9 Sémantique axiomatique III n More specifically, the verification of a program’s correctness is done in two steps: – The association of a formula with each step of the significant calculation. – The demonstration that the final formula logically follows from the initial formula thanks to the intermediate steps and formulae. n The formulae for the assignment and the conditional statement are the basic formulae. The effect of all the other instructions is logically derived from the basic formulae.

10 Axiomatic Semantic IV: The Assignment Statement n Let’s assume that x = E is an assignment statement and that Q is its post-condition. Then, its pre-condition is defined by the following axiom P = Q x --> E which means that P is computed just like Q with all the instances of x replaced by E. n How can we prove the correctness of our programs (and in particular of an assignment statement) with such tools?

11 Axiomatic Semantic V: Justifying the procedure n An assignment statement accompanied by its pre-condition and its post-condition can be considered to be a theorem. n If the assignment statement’s axiom, when applied to the post-condition and to the assignment statement, produces the given pre-condition, then we can say that the theorem has been proven, and that, therefore, the program is correct.

12 Axiomatic Semantic VI: Consequence Rule (Narrowing and Widening) n Sometimes, the precondition one obtains by the procedure just discussed does not correspond to the expected pre-condition. n In such a case, one can use the consequence rule, which is given below: {P} S {Q}, P’ => P, Q => Q’ {P’} S {Q’}

13 Axiomatic SemanticVII: Sequences of instructions Given two adjacent instructions with the following pre- and post- conditions: {P1} S1 {P2} {P2} S2 {P3} The inference rule for such a sequence is: {P1} S1 {P2}, {P2} S2 {P3} {P1} S1 ; S2 {P3}

14 Axiomatic SemanticsVIII: The Selection Statement n If-then-else: {B and P} S1 {Q}, {(not B) and P} S2 {Q} {P} if B then S1 else S2 {Q} n If-then: {B and P} S1 {Q}, {(not B) and P} => Q {P} if B then S1 {Q}

15 Axiomatic Semantics IX: Loops with pre-test n In a loop with a pre-test (also known as a while loop), there is a repetition of instructions. The problem with these loops, however, is that it is impossible to know, ahead of time, how many repetitions there will be. Therefore, it is quite difficult to determine exactly the correctness of these loops. n The method we use is similar to the mathematical method of induction. n The inductive hypothesis is called the loop invariant.

16 Axiomatic Semantics X: Loops with Pre-test n The inference rule that allows us to find the pre- consition of a while loop is the following: {I and B} S {I} {I} while B do S end {I and (not B)} I represents the loop invariant but it is not provided. We must find it! How? By calculating the pre-condition for a certain number of repetitions and trying to guess a pattern.

17 Axiomatic Semantics XI: Loops with Pre-test n Finding the loop invariant is not all!!!!! n Given instruction {P} while B do S end {Q}, and loop invariant, I, here is a summary of all that needs to be proven in order to prove the correctness of a while loop: P => I {I} B {I} {I and B} S {I} (I and (not B)) => Q The loop terminates