Category:M2000 Interpreter: Difference between revisions

no edit summary
mNo edit summary
No edit summary
Line 9:
|gc=allowed
}}
M2000 is an interpreter running on its own Environment written in Visual Basic 6, as an open source project and can be find in GitHub[https://github.com/M2000Interpreter/Version9]. Current version is 9.3. and revision 3032. See [[M2000 Interpreter Implementation]]
{{language programming paradigm|Imperative}}
{{language programming paradigm|Object-oriented}}
Line 18:
M2000 has two set of vocabularies, one with English identifiers and one with Greek identifiers. We can mix languages, but not if some identifiers are part of a statement in non matching language.
 
 
M2000 start as an experimental interpreted language, using a Module in Module idea (like a Procedure in Procedure) where each inner Module is closed for modification, but open for expansion, by replacing code at run time. Code executed in one pass. There is a pre-pass to determine the major type of an expression, a number or a string. Look this paradigm: We call inner Beta in two stages. InsAt the second stage we change inner Theta with Theta2. This is the decoration of Beta with Theta as Theta2. This is a temporary decoration because Beta after execution erase any new identifier including Theta. So each time we call Beta, statement Module Theta make this module unless a decoration stop it.
==English Vocabulary==
<lang >Module Beta {
Line 149 ⟶ 150:
Def A(x)=x**2
Print A(3), A(@ 4)</lang>
 
 
 
Line 156:
It is easy to make modules, with modules, functions, variables, arrays. We can use subroutines when we want code in a module or a function to used more than once. We can use local variables inside subroutines. In subroutines we can use module's variables, functions, subroutines. Until here we see something like BASIC, except that variables are local to modules and functions, but can be used by subroutines. Also we have see that we can replace a module in a module when we call it. With this replacement we can use a predefined logic with some "terminals", modules that get parameters and do final things. We can make global modules and functions in local modules and functions, but these exist until creator module or function exit.
 
M2000 can be used for more advanced programming. Modules and functions can be members of Groups. Groups are values. So a function can return a Group. Modules and functions get parameters in a stack. Modules get the parent stack with parameters, and functions get a new stack with parameters. Modules return from call and are responsible to clear as needed the stack. Functions drop the stack after the call from an expression. A module can return entities in stack, if we want to do that.
 
===Stack of Values===
Modules and functions get parameters in a stack. Modules get the parent stack with parameters, and functions get a new stack with parameters. Modules return from call and are responsible to clear as needed the stack. Functions drop the stack after the call from an expression. A module can return entities in stack, if we want to do that. We can call a module and pass parameters, and that module can call other module leaving parameters in stack to be read in last module.
We use Read to pop values from stack to feed variables, or Number to pop number, or Letter$ to pop alphanumeric. We can use Empty to check if we have an empty stack. And there are other statement to move or copy items, to drop items.
 
In the example below (y) is a Read y for module definition. Early versions of language use Module alfa {Read y ... }, and last can use Module alfa(y) {...} with or without space before open parenthesis.
 
As we see alfa has no read statement, because before get the first number need to make two modules, and then pop one number and call a module passing current stack, so if choose beta, then the second value feed y from a read y statement.
 
<lang >
module alfa {
module beta (y) {
print y**3
}
module delta (y) {
print y**2
}
if number<2 then {beta} else delta
}
alfa 1, 3 ' 27
alfa 3, 3 ' 9
 
 
\\ number pop a number from stack
function sumall {
sum=0
While not empty {
sum+=number
}
=sum
}
print sumall(1,2,3,4,5,6,7)=28
</lang >
 
 
 
===OOP===
Groups are objects for M2000. We can use them as values, and if we want we can use pointers for groups (but we can make a lot of programs without using pointers to groups). Without using pointer, a Group may be local with a name in a Module or can be in a container like array, inventory (a type of map) and stack objects, without name. Groups may have private and public members, may have properties as read only, may get value and return value, and may have operators. Members of Groups can be anything, including other groups. Groups may have events too. We can make groups by using CLASS statement or by using own function which return a Group or a pointer to Group.
 
Anonymous user