Download presentation

Presentation is loading. Please wait.

Published byIssac Gardner Modified over 2 years ago

1
1 Introducing ASML ASML version 2, “Steps and Updates ” Lecture 9 Software Engineering COMP201

2
2 The Executable Specification Language - ASML 2 Compiler asmlc [name of the program] Example D:\>asmlc test.asml D:\> test.exe

3
3 I. Steps The general syntax for steps is Step [label] [stopping-condition] statement block a statement block consists of indented statement that follow a label is an optional string, number of identifier followed by a colon (“:”) stopping condition is any these forms: until fixpoint until expression while expression A step can be introduced independently or as part of sequence of steps in the form: step …

4
4 Stopping for fixed point “until fixed point” enum EnumMode Initial Started Finished var mode = Initial var count = 0 Main() step until fixpoint if mode = Initial then mode :=Started count:=1 if mode = Started and count < 10 then count:= count+1 if mode = Started and count >=10 then mode:= Finished Initial Started Finished if count < 10 then count:= count+1 count 10 count:= 1

5
5 Stopping for conditions “while” & “until” while expression until expression var x as Integer = 1 Main() step while x < 10 WriteLine(x) x:= x + 1 var x as Integer = 1 Main() step until x > 9 WriteLine(x) x:= x + 1 Running each of these examples produces nine steps. It will print numbers: 1,2,3,4,5,6,7,8 and 9 as output Either while or until may be used to give an explicit stopping condition for iterated sequential steps of the machine.

6
6 Conditions eq= ne lt < gt > in notin subset superset subseteq superseteq

7
7 Sequences of steps var F as File? = undef var Fcontents as String = “” Main () step 1: F :=open(“mfile.txt”) step 2: FContents :=fread (F,1) step 3: FContents := FContents + fread (F,1) step 4: writeln (FContents) The syntax step … step … indicates a sequence of steps that will be performed in order Labels after the “step” keyword are optional but helpful as documentation.

8
8 Be wary ! Be wary of introducing unnecessary steps This can occur if two operations are really not order-dependent but are given as two sequential steps, regardless It is very easy to fall into this trap, since most people are used to the sequential structures used by other programming languages

9
9 Iteration over collections Another common idiom for iteration is to do one step per element in some finite collection such as a set or sequence step foreach ident 1 in expr 1, ident 2 in expr 2 … statement-block myList = [1,2,3] Main() step foreach i in myList WriteLine (i) Sequential, step-based iteration is available for sets as well as sequences, but in the case of sets, the order is not specified

10
10 Guidelines for using steps SituationYou choose … operations occur in a fixed order sequence of steps each operation must be done in order iterated steps with stopping condition “while”,“until” operations must be done in sequence, one after another iteration over collection “foreach” operations can be done without order iteration over collection “forall” Repeat an operation until no more changes occur fixed-point stopping condition “until fixed point”

11
11 II. Updates “How are variables updated?” A program defines state variables and operations The most important concept is that state is a dictionary of (name,value) pairs Each name identifies an occurrence for state variables Operations may propose new values for state variables But effect of these changes is only visible in subsequent step

12
12 The update statement Update symbol “: =” (reads as “gets”) var x = 0 var y = 1 Main() step WriteLine(“In the first step, x =” + x) // x is 0 WriteLine (“In the first step, y =” + y) // y is 1 x:=2 step // updates occur here WriteLine(“In the second step, x =” + x)//x is 2 WriteLine(“In the second step, y =” + y)//y is 1

13
13 Delayed effect of updates Updates don’t actually occur until the step following the one in which they are written var x = 0 var y = 1 Main() step WriteLine(“In the first step, x =” + x) // x is 0 WriteLine(“In the first step, y =” + y) // y is 1 step x:=2 WriteLine (“In the second step, x =” + x) // x is 0 step WriteLine (“In the third step, x =” + x) // x is 2

14
14 When updates occur in C, Javain ASML temp = x x = y y = temp step x:= y y:=x Swapping values All updates given within a single step occur simultaneously at the end of the step. Conceptually, the updates are applied “in between” the steps.

15
15 Consistency of updates a)The order within a step does not matter, but all of updates in the step must be consistent b)None of the updates given within a step may contradict each other c)If updates do contradict, then they are called “inconsistent updates” and an error occur Inconsistent update Error: CLASH in the update set step x:=1 x:=2 we don’t know which of the two should take effect

16
16 Total and partial updates An update of the variable can either be total or partial Total update is a simple replacement of variable’s value with a new value Partial updates apply to variables that have structure The left hand side of the update operation “ X : = val ” indicates whether the update is total or partial

17
17 Total update of a set-valued variable 1.The variable Students was, initially, an empty set 2.It was then updated to contain the names of the four students 3.Update became visible in the second step as the finial roster var Students as Set of String = {} Main() step WriteLine (“The initial roster is = ” + Students) Students := {“Bill”, “Carol”, “Ted”, “Alice”} step WriteLine (“The final roster is = ” + Students)

18
18 Partial update of a set-valued variable “ X : = val ” is update operation If X ends with an index form, then the update is partial If X ends with a variable name, then the update is total var Students as Set of String = {} Main() step WriteLine (“The initial roster is = ” + Students) Students(“Bill”) := true Students(“Carol”) := true Students(“Ted”) := true Students(“Alice”) := true step WriteLine (“The final roster is = ” + Students)

19
19 Updating a set-valued variable Updating the set Students with updating statement (*) removes “Bill ” from the set The update is partial in the sense that other students may be added to the set Students in the same step without contradiction var Students as Set of String = {} Main() step WriteLine (“The initial roster is = ” + Students) Students := {“Bill”, “Carol”, “Ted”, “Alice”} step WriteLine (“The current roster is = ” + Students) Students ( “Bill”) := false // ( * ) step WriteLine (“The final roster is = ” + Students)

Similar presentations

OK

Introduction to ASMs Dumitru Roman Digital Enterprise Research Institute

Introduction to ASMs Dumitru Roman Digital Enterprise Research Institute

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google