objectives
play

Objectives You should be able to... In order to express the meaning - PowerPoint PPT Presentation

Introduction Formal Systems A Simple Imperative Programming Language Church Rosser Introduction Formal Systems A Simple Imperative Programming Language Church Rosser Objectives You should be able to... In order to express the meaning of a


  1. Introduction Formal Systems A Simple Imperative Programming Language Church Rosser Introduction Formal Systems A Simple Imperative Programming Language Church Rosser Objectives You should be able to... In order to express the meaning of a program, we need a formal language Small Step Semantics to capture these meanings. Today’s semantics will use transitions to specify the value of an expression. By the end of lecture, you should know how to use transitional semantics. Dr. Mattox Beckman ◮ what the word “semantics” means. University of Illinois at Urbana-Champaign ◮ determine the value of an expression (i.e., be able to read) Department of Computer Science ◮ specify the meaning of a language (i.e., be able to write). You should also know the Church-Rosser property and be able to give examples of languages that have it and languages that don’t have it. Introduction Formal Systems A Simple Imperative Programming Language Church Rosser Introduction Formal Systems A Simple Imperative Programming Language Church Rosser Parts of a Formal System Example Symbols S , ( , ) , Z , P , x , y . To create a formal system, you must specify the following: Defjnition of a furbitz ◮ A set of symbols or an alphabet . ◮ Z is a furbitz. x and y are variables of type furbitz. ◮ A defjnition of a valid sentence . ◮ if x is a furbitz, then S ( x ) is a furbitz. ◮ A set of transformation rules to make new valid sentences out of old ◮ if x and y are furbitzi, then P ( x , y ) is a furbitz. ones. Defjnition of the gloppit relation ◮ A set of initial valid sentences . ◮ Z has the gloppit relation with Z . ◮ If x and y have the gloppit relation, then S ( x ) and You do NOT need: S ( y ) have the gloppit relation. ◮ An interpretation of those symbols. ◮ If α and β , then we can write α g β . They are highly recommended, but the formal system can exist and do its work without one. True Sentences If α g β , then also ◮ P ( S ( α ) , β ) gS ( P ( α, β )) , and P ( Z , β ) g β

  2. skip Introduction Formal Systems A Simple Imperative Programming Language Church Rosser Introduction Formal Systems A Simple Imperative Programming Language Church Rosser Example Grammar for Simple Imperative Programming Language Symbols S , ( , ) , Z , P , x , y . The Language Defjnition of an integer ◮ 1 is an integer. x and y are variables of type integer. S ::= ◮ if x is an integer, then S ( x ) is an integer. u := t | ◮ if x and y are integers, then P ( x , y ) is an integer. S 1 ; S 2 | if B then S 1 else S 2 fi Defjnition of the equality relation | while B do S 1 od | ◮ 1 has the equality relation with 1 . ◮ If x and y have the equality relation, then S ( x ) and S ( y ) have the equality relation. ◮ Let u be a possibly subscripted variable. ◮ If α and β , then we can write α = β . ◮ Let t be an expression of some sort. True Sentences If α = β , then also ◮ Let B be a boolean expression. ◮ P ( S ( α ) , β ) = S ( P ( α, β )) , and P (1 , β ) = β Introduction Formal Systems A Simple Imperative Programming Language Church Rosser Introduction Formal Systems A Simple Imperative Programming Language Church Rosser Transistions Defjnition of → Skip and Assignment ◮ There are many ways we can specify the meaning of an expression. One way is to specify the steps that the computer will take during < skip , σ > → < E , σ > an evaluation. < u := t , σ > → < E , σ [ u := σ ( t )] > ◮ A transition has the following form: ◮ σ will have the form { u 1 := t 1 , u 2 := t 2 , . . . , u n := t n } < S 1 , σ > → < S 2 , τ > ◮ If σ = { x := 5 } , then we can say σ ( x ) = 5 where S 1 and S 2 are statements, and σ and τ represent ◮ We can update σ . environments. The statement could change the environment. ◮ Note well: → indicates exactly one step of evaluation. (Hence σ [ x := 20] = { x := 20 } “small step semantics”) σ [ y := 20] = { x := 5 , y := 20 }

  3. Introduction Formal Systems A Simple Imperative Programming Language Church Rosser Introduction Formal Systems A Simple Imperative Programming Language Church Rosser Defjnition of → Defjnition of → If Sequencing < S 1 , σ > → < S 2 , τ > < if B then S 1 else S 2 fi , σ > → < S 1 , σ > where σ | = B < S 1 ; S , σ > → < S 2 ; S , τ > < if B then S 1 else S 2 fi , σ > → < S 2 , σ > where σ | = ¬ B E ; S ≡ S ◮ The notation σ | = B means “ B is true given variable assignments in ◮ Notice how we don’t talk about the second statement at all! σ .” ◮ { x := 20 , y := 30 } | = x < y Introduction Formal Systems A Simple Imperative Programming Language Church Rosser Introduction Formal Systems A Simple Imperative Programming Language Church Rosser Defjnition of → Example Evaluation While Evaluate: x:=1; n:=3; while n>1 do x:=x*n; n:=n-1 od < while B do S 1 od , σ > → < S 1 ; while B do S 1 od , σ > where σ | = B < while B do S 1 od , σ > → < E , σ > where σ | = ¬ B < x:=1; n:=3; while n>1 do x:=x*n; n:=n-1 od , {} > ◮ Notice how the body of the while loop is copied in front of the loop!

  4. Introduction Formal Systems A Simple Imperative Programming Language Church Rosser Introduction Formal Systems A Simple Imperative Programming Language Church Rosser Example Evaluation Example Evaluation Evaluate: x:=1; n:=3; while n>1 do x:=x*n; n:=n-1 od Evaluate: x:=1; n:=3; while n>1 do x:=x*n; n:=n-1 od < x:=1; n:=3; while n>1 do x:=x*n; n:=n-1 od , {} > < x:=1; n:=3; while n>1 do x:=x*n; n:=n-1 od , {} > → < n:=3; while n>1 do x:=x*n; n:=n-1 od , { x := 1 } > → < n:=3; while n>1 do x:=x*n; n:=n-1 od , { x := 1 } > → < while n>1 do x:=x*n; n:=n-1 od , { x := 1 , n := 3 } > Introduction Formal Systems A Simple Imperative Programming Language Church Rosser Introduction Formal Systems A Simple Imperative Programming Language Church Rosser Example Evaluation Example Evaluation Evaluate: x:=1; n:=3; while n>1 do x:=x*n; n:=n-1 od Evaluate: x:=1; n:=3; while n>1 do x:=x*n; n:=n-1 od < x:=1; n:=3; while n>1 do x:=x*n; n:=n-1 od , {} > < x:=1; n:=3; while n>1 do x:=x*n; n:=n-1 od , {} > → < n:=3; while n>1 do x:=x*n; n:=n-1 od , { x := 1 } > → < n:=3; while n>1 do x:=x*n; n:=n-1 od , { x := 1 } > → < while n>1 do x:=x*n; n:=n-1 od , { x := 1 , n := 3 } > → < while n>1 do x:=x*n; n:=n-1 od , { x := 1 , n := 3 } > → < x:=x*n;n:=n-1;while n>1 do x:=x*n; n:=n-1 od , → < x:=x*n;n:=n-1;while n>1 do x:=x*n; n:=n-1 od , { x := 1 , n := 3 } > { x := 1 , n := 3 } > → < n:=n-1;while n>1 do x:=x*n; n:=n-1 od , { x := 3 , n := 3 } >

  5. Introduction Formal Systems A Simple Imperative Programming Language Church Rosser Introduction Formal Systems A Simple Imperative Programming Language Church Rosser Example Evaluation Example Evaluation Evaluate: x:=1; n:=3; while n>1 do x:=x*n; n:=n-1 od Evaluate: x:=1; n:=3; while n>1 do x:=x*n; n:=n-1 od < x:=1; n:=3; while n>1 do x:=x*n; n:=n-1 od , {} > < x:=1; n:=3; while n>1 do x:=x*n; n:=n-1 od , {} > → < n:=3; while n>1 do x:=x*n; n:=n-1 od , { x := 1 } > → < n:=3; while n>1 do x:=x*n; n:=n-1 od , { x := 1 } > → < while n>1 do x:=x*n; n:=n-1 od , { x := 1 , n := 3 } > → < while n>1 do x:=x*n; n:=n-1 od , { x := 1 , n := 3 } > → < x:=x*n;n:=n-1;while n>1 do x:=x*n; n:=n-1 od , → < x:=x*n;n:=n-1;while n>1 do x:=x*n; n:=n-1 od , { x := 1 , n := 3 } > { x := 1 , n := 3 } > → < n:=n-1;while n>1 do x:=x*n; n:=n-1 od , { x := 3 , n := 3 } > → < n:=n-1;while n>1 do x:=x*n; n:=n-1 od , { x := 3 , n := 3 } > → < while n>1 do x:=x*n; n:=n-1 od , { x := 3 , n := 2 } > → < while n>1 do x:=x*n; n:=n-1 od , { x := 3 , n := 2 } > → < x:=x*n;n:=n-1;while n>1 do x:=x*n; n:=n-1 od , { x := 3 , n := 2 } > Introduction Formal Systems A Simple Imperative Programming Language Church Rosser Introduction Formal Systems A Simple Imperative Programming Language Church Rosser Example Evaluation Example Evaluation Evaluate: x:=1; n:=3; while n>1 do x:=x*n; n:=n-1 od Evaluate: x:=1; n:=3; while n>1 do x:=x*n; n:=n-1 od < x:=1; n:=3; while n>1 do x:=x*n; n:=n-1 od , {} > < x:=1; n:=3; while n>1 do x:=x*n; n:=n-1 od , {} > → < n:=3; while n>1 do x:=x*n; n:=n-1 od , { x := 1 } > → < n:=3; while n>1 do x:=x*n; n:=n-1 od , { x := 1 } > → < while n>1 do x:=x*n; n:=n-1 od , { x := 1 , n := 3 } > → < while n>1 do x:=x*n; n:=n-1 od , { x := 1 , n := 3 } > → < x:=x*n;n:=n-1;while n>1 do x:=x*n; n:=n-1 od , → < x:=x*n;n:=n-1;while n>1 do x:=x*n; n:=n-1 od , { x := 1 , n := 3 } > { x := 1 , n := 3 } > → < n:=n-1;while n>1 do x:=x*n; n:=n-1 od , { x := 3 , n := 3 } > → < n:=n-1;while n>1 do x:=x*n; n:=n-1 od , { x := 3 , n := 3 } > → < while n>1 do x:=x*n; n:=n-1 od , { x := 3 , n := 2 } > → < while n>1 do x:=x*n; n:=n-1 od , { x := 3 , n := 2 } > → < x:=x*n;n:=n-1;while n>1 do x:=x*n; n:=n-1 od , → < x:=x*n;n:=n-1;while n>1 do x:=x*n; n:=n-1 od , { x := 3 , n := 2 } > { x := 3 , n := 2 } > → < n:=n-1;while n>1 do x:=x*n; n:=n-1 od , { x := 6 , n := 2 } > → < n:=n-1;while n>1 do x:=x*n; n:=n-1 od , { x := 6 , n := 2 } > → < while n>1 do x:=x*n; n:=n-1 od , { x := 6 , n := 1 } >

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend