A program in Elevator can control many elevators. To do this its nesesary to specify a elevator block. In the program each elevator has its own name which is used to comunicate elevators. Each elevator has a group of actions it can do. Them main action is executed when the progrem starts. All other actions are called as they were commands.
There are to types of syntax: commands and blocks. They syntax is the following:
name params some code end name
|up||up N||Go up N floors.|
|down||down N||Go down N floors.|
|floor||floor N||Go to the Nth floor.|
|getFloor||getFloor||The user selects a floor from the elevator keyboard and it goes to that floor.|
|outFloor||outFloor||Shows the floor number.|
elevator name Some code end elevator
|Creates a controller for a elevator.|
action name params... Some code end action
|Creates a action for a elevator to do. It can only be used in a elevator block.|
with elevator Some code end with
|Lets control an elevator from other one.|
above floor Some code end aboveFloor
|Execs it's code if the current elevator is above the specified floor.|
below floor Some code end below
|Execs it's code if the current elevator is below the specified floor.|
in floor Some code end in
|Execs it's code if the current elevator is in the specified floor.|
until floor Some code end until
|Execs it's code until the elevator is in the specified floor.|
|Comment||;||Ignores the rest of the line.|
|Actual floor||!||Returns the floor of the elevator of the actual action. That means that if it's value is 42 and you use a with block, it will be still 42.|
At the start of the program the interpreter runs each main action in order. Any action can run any other action. If both of them belong to the same elevator, then they can executed as they were any other command. Else a with block is required.
The commands in the actions are executed in order and instantly (unless the elevator needs to change floor, then the program will wait until it has stopped).
If Elevator is being interpreted in an emulator, then there are infinite floors and the floor changes instantly. Also in this case, outFloor prints the floor number and getFloor, instead of reading input from the elevator keyboard, reads a user input as an integer.
Cat and normal elevator
elevator Normal action main getFloor outFloor end action end elevator
; There are three elevators: one for the first number and the result, one for the operation and one for the second number elevator A action main getFloor ; Get the first number end action end elevator elevator Op action main getFloor ; Get the operation end action end elevator elevator B action main getFloor ; Get the second number ; Check the operation with Op in 1 ; add with A up ! outFloor end with end in in 2 ; Substract with A down ! outFloor end with end in end with end action end elevator
; In this version there is instead a controller, a math, and a storage elevator elevator Controller ; When the program starts: action main ; Get the first number getFloor ; Store it into the storage with Storage store ! end with ; Get the operation getFloor ; If its one, then get the second number an add it to the storage in 1 with Math getFloor addToStorage end with end in ; If its 2 substract it to the storage in 2 with Math getFloor substractToStorage end with end in ; Print the result with Storage outFloor end with end action end elevator elevator Storage action store val floor val end action end elevator elevator Math action addToStorage with Storage up ! end with end action action substractToStorage with Storage down ! end with end action end elevator
elevator TruthElevator action main getFloor ; If the input is 0, then the floor is also 0 so the program just outputs the floor in 0 outFloor end in ; If the input is 1 the floor is 1 so the program just outputs it infinitely in 1 until 2 ; Because the floor never changes, it will never be 2 and the loop wont end outFloor end until end in end action end elevator
; This program goes to the floors corresponding to the values of the ascii characters that conform the word "Elevator" elevator Elevator action main show 69 show 108 show 101 show 108 show 118 show 97 show 116 show 111 show 114 end action ; Action for showing numbers action show num floor num outFloor end action end elevator