Imperator

Imperator is an 80s-like programming language created in 2023. It was influenced by programming languages like BASIC.
==Syntax==
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".
===Print===
Values can be printed by typing P at the end of the line.
===Calculations===
Calculations can be called with M. The value of the calculation can be printed with P
Example: M 1+2 P
The number "3" will be output
Imperator also supports calculations with variables: M a+b P
===Strings===
Strings are written with a < at the beginning and a > at the end.
Example: <Hello, World!> P
Variables can also be added to strings.
Example: <Number: > + a P
===Variables===
Imperator supports string and number variables.
====Declare variables====
The letter to declare a variable is V
Declare a variable: V + name + = + statement
Example: V test = 1
Example 2: V math = M 1+1
Example 3: V string = <Test>
====Change variables====
Changing variables works in the same as declaring variables, but the keyword is NEW
Example: NEW test = 2
===Loops===
The keyword for loops in Imperator is REPEAT
Example:
REPEAT 5 [
M 1+1 P
]
This will output "2" for five times.
Example 2:
V i = 0
REPEAT 5 [
NEW i = i + 1
i P
]
This will output:
1
2
3
4
5
===If statement===
If statements can be called in Imperator as follows: IF + expression + -> + statement
====Operator: = ====
With = it can be checked if two values are the same.
Example: IF a = 10 -> <Same value!> P
====Operator: > ====
With > it can be checked if a values is greater than a other one. < doesn't exist
Example: IF a > 10 -> <a is greater than 10!> P
====Operator: ! ====
With ! it can be checked if two values are not the same.
Example: IF a ! 10 -> <a is not 10!> P
===Input===
The user can be asked for a input with the keyword I
====String inputs====
Example: V string = I
====Int inputs====
Example: V int = I : INT
====Float inputs====
Example: V float = I : FLOAT
===Round function===
Numbers can be rounded with $ROUND
Example: V roundedNumber = $ROUND : 1.5
===Random function===
Random numbers can be generated with $RANDOM
====Random ints====
Example: V randInt = $RANDOM : INT ; (1, 5)
This will generate a random int between 1 and 5
====Random floats====
Example: 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 %
====Line numbers====
To jump to a line by their line number, write: % = + line number
Example: % = 5
The program will jump to line 5
====Ranges====
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.
Example: % = (5, 7)
This will interpret the line 5 to 7 and will then jump back and continue
====Marks====
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.
Example:
% = @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
===Comments===
Use !!! to create a comment
Example: !!! 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 .impr
Example: SOURCE TEST
This will access and run the file TEST.impr
==Examples==
A few example programs written in Imperator
===Hello, World!===
A Hello, World! program in Imperator
<Hello, World!> P
===Calculator===
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
===Cat program===
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
===Truth-machine===
A Truth-machine in Imperator
V INPUT = I : INT
IF INPUT = 0 -> INPUT P
IF INPUT = 1 -> % = 6
#STOP
INPUT P
% = 6
==Links==
*Source code
Category:Turing complete Category:Implemented Category:2023