Question

In: Advanced Math

Suppose an elevator is controlled by two commands: ↑ to move the elevator up one floor...

Suppose an elevator is controlled by two commands: ↑ to move the elevator up one floor and ↓ to move the elevator down one floor. Assume that the building is arbitrarily tall and that the elevator starts at floor x.

A)Write an LL(1) grammar that generates arbitrary command sequences that (1) never cause the elevator to go below floor x and (2) always return the elevator to floor x at the end of the sequence. For example, ↑↑↓↓ and ↑↓↑↓ are valid command sequences, but ↑↓↓↑ and ↑↓↓ are not. For convenience, you may consider a null sequence as valid.

B)Prove that your grammar is LL(1) (you need to provide the first, follow, and predict sets, as well as the complete parse table).

Solutions

Expert Solution

he question is quite interesting, we will use reduction method to solve the problem:-

Generally when we come across problems like these we have to reduce the problem accoring to logic, like, from this question, we can understand the hidden logics, which will make the question more easy:-

1) We observer that the machine should start and end at a fixed state.

2) If we assume that ↑ = a & ↓ = b , then we can reduce this problem by saying, that this problem talks about a language wich has equal number of a's and b's.

Now lets solve for it:-

Here, we need not to maintain any order of a’s and b’s. Thus our state diagram will contain only an initial state and a final state. The count of a’s and b’s is maintained by stack. We will take 3 stack alphabets:

  = {a, b, z}
  1. If ‘a’ comes first then push it in stack
  2. if again ‘a’ comes then also push it
  3. Similarly, if ‘b’ comes first (‘a’ did not comes yet) then push it into the stack
  4. if again ‘b’ comes then also push it.
  5. if ‘a’ is present in the top of the stack and ‘b’ comes then pop the ‘a’ from the stack.
  6. if ‘b’ present in the top of the stack and ‘a’ comes then pop the ‘b’ from the stack.
  7. And at the end if the stack becomes empty then we can say that the string is accepted.

 

where a = ↑ & b =  ↓ and x = Initial state , xf = Final state and similarly = indicates pop operation


Related Solutions

A monkey sits on a bathroom scale which is on the floor of an elevator for...
  A monkey sits on a bathroom scale which is on the floor of an elevator for a very tall building. The monkey has a mass of 42.0 kg. What is the reading on the scale if there is not motion and no acceleration? When the elevator starts moving the scale reads 480 N. Describe the acceleration for this case. At another time the scale reads 360 N. Describe the acceleration for this second case. Calculate the acceleration in each...
1) a. There is an elevator on the 102th floor of the Empire State Building with...
1) a. There is an elevator on the 102th floor of the Empire State Building with a sign: MAXIMUM WEIGHT 2900 LBS. During refurbishment, the cable was being replaced. A section of the new cable is cut up and tested for its breaking strength. The cable was tested 20 times and the average breaking point of the sample was found to be 3100 LBS with a standard deviation of 280 LBS. Construct an appropriate hypothesis test that determines whether the...
An object is placed on the floor of an elevator. Which of the following statements is...
An object is placed on the floor of an elevator. Which of the following statements is correct regarding the magnitude of the normal force that the elevator floor exerts on the object? A) It is always the same as the weight of the object regardless the state of motion of the elevator B) It is less than the weight of the object if the elevator moves downward with a constant velocity C) It is largest if the elevator undergoes free...
A box of mass sits on the floor of an elevator. The area of the bottom...
A box of mass sits on the floor of an elevator. The area of the bottom surface of the box is 0.250 m2. When the elevator is moving upward at a constant speed of 2.00 m/s the pressure the box exerts on the floor is 981 pascal. (Note: One Pascal equals one Newton per square meter; 1 Pa = 1 N/m2). Calculate the pressure the box exerts on the floor while the elevator a. slows uniformly from an upward speed...
A car is to be hoisted by elevator to the fourth floor of a parking garage,...
A car is to be hoisted by elevator to the fourth floor of a parking garage, which is 48 ft above the ground. Part A If the elevator can accelerate at 0.8 ft/s2, decelerate at 0.3 ft/s2, and reach a maximum speed of 8 ft/s, determine the shortest time to make the lift, starting from rest and ending at rest.
draw a PLC ladder diagram for 5 floor elevator
draw a PLC ladder diagram for 5 floor elevator
The elevator starts from rest at the first floor of the building and comes to a...
The elevator starts from rest at the first floor of the building and comes to a complete stop at the 6th floor. It can accelerate at 6 ft/s2 and then decelerate at 2 ft/s2 Determine the shortest time is takes to reach the 6th floor, which is 60 ft above the ground. Draw the v?t and s?t graphs for the motion of the elevator.
A group of n people get on an elevator at Floor 0. There are m floors...
A group of n people get on an elevator at Floor 0. There are m floors besides Floor 0. Each person uniformly randomly chooses one of those m floors to stop at. (All choices are independent, and no one gets on the elevator after Floor 0.) The elevator stops at a floor if at least one person has chosen to stop there. Let X be the number of stops that the elevator makes after Floor 0. (a) What is E[X]?...
A box of mass M sits on the floor of an elevator at rest. Gravity (which...
A box of mass M sits on the floor of an elevator at rest. Gravity (which has a strength set by the local acceleration due to gravity g) pulls the box and the floor pushes the box. The net or total force on the box is zero. What is the force on the box from the floor? Give both the magnitude and the direction. Now imagine that the elevator is accelerating upwards at acceleration a. Now the two forces on...
Objective: Write a program that simulates a robot running a queue of commands to move around...
Objective: Write a program that simulates a robot running a queue of commands to move around a board with obstacles. Requirements: The board is composed of spaces that are either empty (“_”) or have an obstacle (“X”). Also the board is assumed to be 10x10 spaces. The robot (“O”) has an x and y position corresponding to its location on the board, and four commands: move up, move down, move left, and move right. Both the board and the robot’s...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT