Documentation

read: This instruction enables the user to supply an integer for the program to process. The value user supplies is placed in a variable.

read x;

The instruction above read a integer user types on a console and places it into variable x.

This instruction has to be followed by a semicolon.

write: This instruction enables you to write out a variable, integer or a string to the console.

write x;

The instruction above writes a value of the variable to the console.

write 5;

The instruction above writes a value 5 to the console.

write "message";

The instruction above writes a value message to the console.

This instruction has to be followed by a semicolon.

if then else end: This instruction enables the user to provide a condition. Depending if the condition is met or not one of other block of instructions is executed.

read x;
if x = 0 then
    write "Number you entered is zero.";
else
    write "Number you entered is not zero.";
end

The code above in first instruction read a integer user types on a console and places it into variable x. In next line it checks if value x is equals to zero. If x is equals to zero message "Number you entered is zero." is printed. If x is not equals to zero message "Number you entered is not zero." is printed.

Instructions then, else and end should not be followed by a semicolon.

Instruction if accepts two conditions. Equals "=" which checks if values compared are equal and less than "<" which checks if first value in comparation is less then the second value in comparation.

If you wish to check if the given variable is negative you would use the following code:

if x < 0 then

If you wish to check if the given variable is positive you would use the following code:

if 0 < x then

repeat until: This instruction enables the user repeatly execute part of the code until the condition is met.

x := 5;
repeat
    write "In the loop.";
    x := x - 1;
until x = 0
write "Exited the loop.";

The code above in first instruction places value 5 into variable x. In next line it starts the repeat block. Then message "In the loop." is printed. Variable x is decremented by 1. Then the condition is checked in the until instruction. If value x is not zero the loop is repeated. If value in x is 0 the message "Exited the loop." is printed.

Instructions repeat and until should not be followed by a semicolon.

Instruction until accepts two conditions. Equals "=" which checks if values compared are equal and less than "<" which checks if first value in comparation is less then the second value in comparation.

If you wish to repeat the block until the given variable becomes negative you would use the following code:

until x < 0

If you wish to repeat the block until the given variable becomes positive you would use the following code:

until 0 < x

comments: The sign # is used for comments in the code. Anything between # signs is ignored by mlpl interpreter.

#This is a comment.#
read x;
#This is another
comment spanning
multiple lines.#
write x

arithmetic operations: Basic arithmetic operations are supported. Arithmetic operations are supported only on integeres.

Assigment

x := 2;

Code above assign number 2 to variable x.

Addition

y := x + 1;

Previous instruction takes value from x adds 1 to it and store results in y.

Substration

y := y - 1;

Previous instruction takes value from y substract 1 from it and store results in y.

Multiplication

x := 2 * 3;

Previous instruction takes multiply 2 with 3 and stores result in x.

Division

z := x / y;

Previous instruction takes value from x divide it by value taken from y and store results in z.