- STORE [register] [value*] - Stores the value of [value] in [register]
- GOTO [label*] - Moves execution to the line starting with [label]
- PRINT [message*] - Outputs [message]
- INPUT [register] [message*] - Asks for user input with [message] and stores the value in [register]
- COMPARE [label*] [register1] [mode*] [register2] - Compares [register1] to [register2] depending on the mode (EQ, GT, LT, NE)
- CALCULATE [register] [expression*] - Calculates [expression] and stores the result in [register]
- ASSIGN [register] [file path*] [mode*] - Open a file and store it in [register] with the mode [mode] (READ/WRITE)
- READ [register1] [register2] - Read a line from the file in [register1] and store it in [register2]
- SIZE [register1] [register2] - Get the size of the file in [register1] and store it in [register2]
- WRITE [register1] [register2] - Write the data at [register2] into the file [register1]
- END - Halt execution
- $[register] - Recalls the value in [register]
Values marked with a * can be either a value or a register
All lines must follow the same basic syntax:
[label] [command] [arguments]
- Label can be text, but it is recommended to use a number
- Command MUST be in all capitals
- Using quote marks around text is not necessary
- Comments begin with a #
- Comments must be on their own line
Incorrect commands will halt execution and throw a Syntax Error
The only current interpreter is written in python. As such, you will need python3 installed.
python3 interpreter.py [input file]
It is recommended to save M files as [name].m
10 PRINT Hello
Input | Output |
---|---|
- | Hello |
10 STORE number 10
20 PRINT $number
Input | Output |
---|---|
- | 10 |
10 STORE storedNumber 10
20 INPUT num1 Enter a number:
30 INPUT num2 Enter another number:
40 CALC addedNumbers $num1 + $num2
50 COMPARE 70 $storedNumber EQ $addedNumbers
60 PRINT The sum of your numbers is not 10
END
70 PRINT The sum of your numbers is 10
Input | Output |
---|---|
7, 3 | The sum of your numbers is 10 |
12, 45 | The sum of your numbers is not 10 |
10 PRINT Opening file
20 ASSIGN file .\data.txt READ
30 PRINT File opened
40 READ file line
50 COMPARE 70 $line NE EOF
60 PRINT End of file
END
70 PRINT $line
80 GOTO 40
data.txt
hello world!
Another line!
And one more!
Opening file
File opened
hello world!
Another line!
And one more!
End of file
10 ASSIGN fileIn .\input.txt READ
15 ASSIGN fileOut .\output.txt WRITE
20 READ fileIn line
30 COMPARE 40 $line NE EOF
END
40 WRITE fileOut $line
50 GOTO 20
input.txt
hello world!
Another line!
And one more!
output.txt
hello world!
Another line!
And one more!
- This is not a serious scripting langauge, just something for a bit of code practice.
- Practical applications could include basic data manipulation