1.84k likes | 1.85k Views
Define an abstract machine to control cars entering/leaving a 640-space car park, tracking current cars and enabling operations.
E N D
“B is a method for specifying, designing, and coding software systems.” J.R. Abrial, The B-Book, Cambridge University Press
Exercise 1.7 A car park has 640 parking spaces. Give an abstract machine which specifies a system to control cars entering the car park. It should keep track of the cars currently in the car park, and should provide 3 operations: • Enter, which recorders the entry of a new car. This should occur only when the car park is not full; • Leave, which records the exit of a car from the car park; • Query, which outputs the number of cars currently in the car park.
MACHINE CarPark VARIABLES contents INVARIANT contents : NAT & contents <= 640 INITIALIZATION contents := 0 OPERATIONS enter = PRE contents < 640 THEN contents := contents + 1 END; leave = PRE contents > 0 THEN contents := contents – 1 END; nn <-- query = PRE true THEN nn := contents END END