Question

In: Computer Science

1) Write a denotational semantics for do-while loop

1) Write a denotational semantics for do-while loop

Solutions

Expert Solution

1A)

Denotational semantics for do - while loop ::-

We can define the semantics for loops using either a direct or a continuation semantics. Recall that for the direct semantics, we have:

C: Command → Store⊥ → Store⊥

and we define the valuation function for a loop as follows:
C [[while B do C]] = λs. if B [[B]] then C [[while B do C]] (C [[C]] s) else s

Note that the "then" part of the if says "execute the next iteration, using the store produced by this iteration". But this is a recursive definition; what does it really mean? The answer is to use our usual trick with fixed points:
C [[while B do C]] = Y (λf.λs. if B [[B]] then f (C [[C]] s) else s)
For the continuation semantics, we have:

C: Command → Cc → Store → Store⊥

and we define the valuation function as follows:
C [[while B do C]] = λc.λs. if B [[B]] then (C [[C]] (C [[while B do C]] c) s) else (c s)

Again, we can eliminate the recursion by using Y as we did above for the direct semantics.
Of course, we need to know that the fixed points exist and are what we want.


Related Solutions

Write a denotational semantics for do-while loop
Write a denotational semantics for do-while loop
Do the following lab by while or Do-while loop. question: Write a c++ program that asks...
Do the following lab by while or Do-while loop. question: Write a c++ program that asks students to enter 3 valid grades and then calculate the average and print it. if the user enters the invalid grade you should print the error message and get the new grade. Hint1: each time your program ask the following question: "Do you want to calculate another average?" and if the answer to this question is "Y" or "y" then you should continue. Hint2:...
Re-write following while loop into Java statements that use a Do-while loop. Your final code should...
Re-write following while loop into Java statements that use a Do-while loop. Your final code should result in the same output as the original code below. int total = 0; while(total<100) { System.out.println("you can still buy for"+(100-total)+"Dollars"); total=total+5; }
C++ please 1. Write a do while loop that continually loops until the user enters a...
C++ please 1. Write a do while loop that continually loops until the user enters a single digit between 0 and 9. There should only be one prompt for the user to enter a number inside the loop. 2. Write a simple 4 function calculator using a switch statement. The program should switch on the operator: +, -, *, /. The user should enter two numbers (any type is fine) and then enter an operator and the program should perform...
write a program bus management system? using: if else, for loop, do while loop, function, arrays,...
write a program bus management system? using: if else, for loop, do while loop, function, arrays, string, structure
Modify the previous program to use the Do-While Loop instead of the While Loop. This version...
Modify the previous program to use the Do-While Loop instead of the While Loop. This version of the program will ask the user if they wish to enter another name and accept a Y or N answer. Remove the "exit" requirement from before. Output: Enter the full name of a person that can serve as a reference: [user types: Bob Smith] Bob Smith is reference #1 Would you like to enter another name (Y or N)? [user types: y] Enter...
Python Exercises = Sentinel Values and While Loops #Exercise 1 #Write a while loop with a...
Python Exercises = Sentinel Values and While Loops #Exercise 1 #Write a while loop with a sentinel value #This while loop ends when the user enters a 1, the sentinel value #Assign the number 8 to a variable which will serve as the sentinel value #Condition: while variable is not equal to 1 #Action: display the number assigned to the variable #Use an input statement (no prompt) to ask the user for a number and assign this number to the...
Write a program in C++ coding that utilizes a DO-WHILE loop to redisplay a menu to...
Write a program in C++ coding that utilizes a DO-WHILE loop to redisplay a menu to the user. Ask the user to input their favorite SuperHero and display a positive or funny comment about the chosen SuperHero. If RBG is chosen, display "You can't spell TRUTH without RUTH." Utilize a Do-While Loop to redisplay the menu to the user after item 1, 2 or 3 is executed. If item 4 is chosen, end the program. If the user chooses 4,...
Write a Java program that uses a while loop to do the following: Repeatedly asks the...
Write a Java program that uses a while loop to do the following: Repeatedly asks the user to enter a number or -1 to exit the program. Keeps track of the smallest and largest numbers entered so far: You will need a variable for the smallest number and another variable for the largest number. Read the first number the user enters, and if it is not -1 set the smallest and largest variables to that number. Use a loop to...
write an operational semantic for a while loop in c++
write an operational semantic for a while loop in c++
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT