Giter Club home page Giter Club logo

m's Introduction

M - A BASIC inspired interpreted scripting language

Commands:

- 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

Syntax:

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

Running an M script

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

Example Programs:

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!

Output

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!

Note

  • This is not a serious scripting langauge, just something for a bit of code practice.
  • Practical applications could include basic data manipulation

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.