About M2000
This text was from M2000paper.pdf (included in setup file) plus some additions. I have to update this but can be used. For Greek people there are pages: here and some greek books here. The Greek Manual also included in setup file (newer version).
The M2000 Interpreter is a programming language and has a programming environment with many capabilities like window managing (GUI) and console managing together (REPL). Programming paradigms such as event driven and functional can be apply. Current version of interpreter is 12.
The idea of M2000 based on a language for pupils to experiment, to make some programs for fun and study. Also there are two vocabularies, one with Greek identifiers, and one with English identifiers. We can say: M2000 have Greek and English "reserved" words.
The language first written in 1999 as a simple interpreter like a BASIC clone, using suffixes $ and %, but with curly brackets as block of code and a user dictionary like in FORTH of module names and functions, with embedding modules and functions, utilizing stacks of values to pass and get data during calls and everywhere in code. The upgrade of language was parallel to the upgrade of interpreter and environment. Latest upgrade has BigInteger the arbitrary-precision integers.
form 80, 32
biginteger a=848093284092840932840386876876876876892
biginteger b=3432402938402820840923809880009089
biginteger c=1000000000000
Print "a="+a
Print "b="+b
Print "c="+c
Print "a power b modules c (modpow(a,b,c)) = "; modpow(a,b,c)
Print "a*b = "; a*b
' mix BigInterals with double type values
Print "a*100+b*500 = "; a*100+b*500
a=500
Print type$(a)="BigInteger"
' using u at the end of number for BigIntegers Literals
k=848093284092840932840386876876876876892u*3432402938402820840923809880009089u
Print Len(str$(k))=73 ' 73 characters length
' true:
print k/848093284092840932840386876876876876892u=3432402938402820840923809880009089u
The syntax color produced by the M2000 Editor from M2000 Environment. When we copy code we get color information as Html text with tags. Blogger read the clipboard and placed the text with color.
M2000 Environment
The M2000 Environment has the M2000 Interpreter, a free software as GNU GPL3 licensed. The first idea was for an Environment with a console in a full screen display with text scrolling, using a split screen, with a part of screen which non scrolling at the top, and mixing graphics like the way this did in a BBC model B 8bit computer. Additional was two more capabilities, one for databases and one for multimedia (images, sounds, movies). A help system driven by a database (now a simple dat file) exist and is internal for all identifiers (greek/english more than 500 for each). Use Help All to see all Identifiers on a popup window.
Many versions prepared, with compatibility to previous, including layers of display, sprites, threads, music tune programming with threads, speach and finally support for COM objects, events, and private windows manager, windows and controls.
The environment written first in VB5 (Windows 98) and later in VB6 (Windows Xp to Windows 10). Early versions had ANSI support only, and later versions are Unicode for everywhere including files/screen/GUI. Also the early versions had exclude the tab character (which converted to spaces), From version 8, we can use tab combining with spaces for block intendation. From numeric double type (float 64bit) as the starting only numeric type we can use all types included in VB6, and the variant type. Right to left text (RTL) can be used almost everywhere except some points where it can't fit without more programming effort. The M2000 editor can handle RTL text, although it is a left justified editor. The RTL in the programming editor are prepared per colored chunk, so the LTR M2000 code stay as LTR.
Install Environment
You have to install M2000 environment, to practice on it. Visual Basic 6 run time is part of all Windows Os, so the installation can be done from Xp to Windows 10. You can found the setup file from M2000 blog, here in Github:
https://github.com/M2000Interpreter/Environment/releases
Also there are the binaries:
https://github.com/M2000Interpreter/Environment/releases
After installation and the opening of M2000 console (running M2000.exe) we can give these statements:
Dir AppDir$ : Load
Info <press enter>
When you see the introduction message press the function key F1 to save info.gsb to user directory. So after the End statement in console which exit the M2000 environment, you can open it next time just using Load info and press enter. Also you can open the user directory using Win Dir$ from console, and place gsb files there.
The Language
The M2000 language use internal Identifiers and user defined as variables, modules names, and functions. Except identifiers used for flow control all internal identifiers can be used from user for own use (eg the Print statement can be a Module name, but the actual Print can be called using @ character before name). M2000 has a lot of internal names, more than 500, for each of the two different sets of identifiers or vocabularies, the English and the Greek (you can code with greek statements/identifiers too, or you can use libraries from any vocabulary). Both of these sets can be used on same program. Because M2000 is an open source project you have the permition to exclude one set (the Greek one), and install another for some other language eg Turkish maybe, but this is a hard job, because of the recursive descent parser of M2000 interpreter.
Names are non case sensitive except for labels (for goto and simple subroutines, like in BASIC). To execute code we can use M2000 console as a REPL (Read-Eval-Print Loop) for executing statements except loops, and we can make modules and functions at global level and use them as new identifiers. There is no RUN statement, we just call the module name we want to run (like in FORTH).
This example can be written in a module A, just write Edit A then press key <Enter> and that is: you open the editor. Then you write or paste this code and then you press key <Esc> to exit editor, then write A and press key <Enter> to run it. The Inner modules can’t be called from outside module, nor from inner modules. All modules at the zero level (where we edit modules from REPL) are global, so they can called from other modules (except form the same code, if we use simple call, only by name).
Here we redefine Print, and Long. Interpreter when see operators right after a name think it is a variable. Without operator think is a command or a module name. If the name has parenthesis and there is no operator after it, then this means a call to a subroutine (a kind of module without an namespace – exist only on modules/functions).
Module Print {
Print "Hi"
While not empty
If isNum then @Print Number,
If isLet Then @Print Quote$(Letter$),
end while
Print
}
// lets define some variables
Long k = 100
Long = 100
Long J = 500
Long++
// this call module Print
Print Long=101, Long-k=1, J+Long=601
// same as this// call can't be used for internal commands
Call Print Long=101, Long-k=1, J+Long=601
// this call internal Print
@Print Long=101, Long-k=1, J+Long=601
M2000 is like a stack oriented language when we pass parameters. Although expresions written using infix notation, and executed by a functional way, where each function hold one accumulator and when we open parentesis a new function called with a new accumulator, and so on until we return to first call.
Passing agruments to Modules/Functions done from a stack of values. M2000 is a stack-based language from a view of passing and handling arguments.
Functions have own stack of values, modules get the one from the caller (so modules can return arbitrary number of values through stack of values).
The use of a space for multiple modules, on M2000 Environemnt, means that we may have different versions for same program, and we can try each one, using some modules as libraries or common sub programs. We can make functions using Edit from REPL: Edit X2() <Enter> open X@() and we place these two lines (no need spaces or tabs for indentation, here are for this text only):
read x
=x*2
So now we do this from immediate mode (REPL), see we can use lower case for x, and ? for print statement:
? x2(10)=20
True
We pass a double type 10 numeric literal, to a new stack of values, and pass it to function X2 which a READ statement get the value and assign it to variable x. Then we pass the value from x*2 expression to the return value of function. Functions return to caller at the end of code not at the passing of value at the = as statement (we have to use statement Exit to exit early). Functions have no types (excluding those with names with suffix $). If we do this ? x2(10, 30, "hello") we get 20 and the rest of arguments, on the list of arguments passed to stack of values but not used. This isn’t a fault or error, unless we take control over stack, inspect it and we wish to inform for something which we define as fault. Internal functions not work with stack of values.
Δεν υπάρχουν σχόλια:
Δημοσίευση σχολίου
You can feel free to write any suggestion, or idea on the subject.