|Computational class||Turing complete|
Imperator is an 80s-like programming language created in 2023. It was influenced by programming languages like BASIC.
A brief overview of the syntax of "Imperator":
"Imperator" is an imperative language. The name comes from the Latin word "imperator", meaning "the one who gives orders".
Values can be printed by typing
P at the end of the line.
Calculations can be called with
M. The value of the calculation can be printed with
M 1+2 P
The number "3" will be output
Imperator also supports calculations with variables:
M a+b P
Strings are written with a < at the beginning and a > at the end.
<Hello, World!> P
Variables can also be added to strings.
<Number: > + a P
Imperator supports string and number variables.
The letter to declare a variable is
Declare a variable:
V + name +
= + statement
V test = 1
V math = M 1+1
V string = <Test>
Changing variables works in the same as declaring variables, but the keyword is
NEW test = 2
The keyword for loops in Imperator is
REPEAT 5 [ M 1+1 P ]
This will output "2" for five times.
V i = 0 REPEAT 5 [ NEW i = i + 1 i P ]
This will output:
1 2 3 4 5
If statements can be called in Imperator as follows:
IF + expression +
-> + statement
= it can be checked if two values are the same.
IF a = 10 -> <Same value!> P
> it can be checked if a values is greater than a other one.
< doesn't exist
IF a > 10 -> <a is greater than 10!> P
! it can be checked if two values are not the same.
IF a ! 10 -> <a is not 10!> P
The user can be asked for a input with the keyword
V string = I
V int = I : INT
V float = I : FLOAT
Numbers can be rounded with
V roundedNumber = $ROUND : 1.5
Random numbers can be generated with
V randInt = $RANDOM : INT ; (1, 5)
This will generate a random int between 1 and 5
V randFloat = $RANDOM : FLOAT ; (1, 5)
This will generate a random float between 1 and 5
Jump to lines
Imperator can jump to a new line with
To jump to a line by their line number, write:
% = + line number
% = 5
The program will jump to line 5
With ranges Imperator can jump to a line and interpret everything up to the other line. Then Imperator will jump back to the line where the range was called.
% = (5, 7)
This will interpret the line 5 to 7 and will then jump back and continue
Imperator also contains a feature called marks. Marks can be added by typing @ + name. Then a mark can be called like this:
% = @ + name. Imperator will jump to the line where the mark was added. This can be helpful if the line numbers are changing often because of edits in the code.
% = @Test <This will not be output> P @Test <This will be output> P
Stop the script
To stop the script, simply write
#STOP. The script will stop immediately if it encounters this keyword
!!! to create a comment
!!! This is a comment
Access and run Imperator files
Imperator files can be accessed and executed with
SOURCE + file name (without file extension). Make sure that the file has the file extension
This will access and run the file
A few example programs written in Imperator
A Hello, World! program in Imperator
<Hello, World!> P
A very simple calculator in Imperator
!!! CALCULATOR <ENTER FIRST NUMBER:> P V FNUMBER = I : FLOAT <ENTER SECOND NUMBER:> P V SNUMBER = I : FLOAT <RESULT:> P V RESULT = M FNUMBER + SNUMBER <> + FNUMBER + < + > + SNUMBER + < = > + RESULT P NEW RESULT = M FNUMBER - SNUMBER <> + FNUMBER + < - > + SNUMBER + < = > + RESULT P NEW RESULT = M FNUMBER * SNUMBER <> + FNUMBER + < * > + SNUMBER + < = > + RESULT P NEW RESULT = M FNUMBER / SNUMBER <> + FNUMBER + < / > + SNUMBER + < = > + RESULT P
Number Guessing Game
A Number guessing game in Imperator
!!! GUESS THE NUMBER V RANDOM = 0 V ATTEMPTS = 3 V AGAIN = <> V GUESS = 0 NEW RANDOM = $RANDOM : INT ; (1, 10) NEW ATTEMPTS = 3 <GUESS A NUMBER BETWEEN 1 AND 10! YOU HAVE 3 ATTEMPTS!> P NEW GUESS = I : INT IF GUESS > 10 -> % = @FALSE IF 1 > GUESS -> % = @FALSE IF GUESS = RANDOM -> % = @WIN IF GUESS > RANDOM -> % = @BIGGER IF RANDOM > GUESS -> % = @SMALLER #STOP @WIN <YOU WON! DO YOU WANT TO PLAY AGAIN? ("Y", "N")> P NEW AGAIN = I IF AGAIN = <Y> -> % = 7 #STOP @BIGGER NEW ATTEMPTS = M ATTEMPTS-1 IF ATTEMPTS > 0 -> % = 34 <GAME OVER! THE NUMBER WAS > + RANDOM P <DO YOU WANT TO PLAY AGAIN? ("Y", "N")> P NEW AGAIN = I IF AGAIN = <Y> -> % = 7 #STOP <THE RANDOM NUMBER IS SMALLER.> P % = 12 @SMALLER NEW ATTEMPTS = M ATTEMPTS-1 IF ATTEMPTS > 0 -> % = 45 <GAME OVER! THE NUMBER WAS > + RANDOM P <DO YOU WANT TO PLAY AGAIN? ("Y", "N")> P NEW AGAIN = I IF AGAIN = <Y> -> % = 7 #STOP <THE RANDOM NUMBER IS BIGGER.> P % = 12 @FALSE <INVALID INPUT! DO YOU WANT TO PLAY AGAIN? ("Y", "N")> P NEW AGAIN = I IF AGAIN = <Y> -> % = 7 #STOP
A Cat program in Imperator
V INPUT = I P
99 bottles of beer
A 99 bottles of beer program in Imperator
V COUNT = 99 REPEAT 98 [ <> + COUNT + < BOTTLES OF BEER ON THE WALL,> P <> + COUNT + < BOTTLES OF BEER.> P <TAKE ONE DOWN, PASS IT AROUND,> P NEW COUNT = M COUNT-1 <> + COUNT + < BOTTLES OF BEER ON THE WALL.> P <> P ] <> + COUNT + < BOTTLES OF BEER ON THE WALL,> P <> + COUNT + < BOTTLES OF BEER.> P <TAKE ONE DOWN, PASS IT AROUND,> P <NO BOTTLES OF BEER ON THE WALL.> P
A Truth-machine in Imperator
V INPUT = I : INT IF INPUT = 0 -> INPUT P IF INPUT = 1 -> % = 6 #STOP INPUT P % = 6