Category:M2000 Interpreter: Difference between revisions

Content added Content deleted
No edit summary
No edit summary
Line 1: Line 1:
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. Ins 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.
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. Ins 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.


Module Beta {
<lang >Module Beta {
Module Theta (x){
Module Theta (x){
Print "This is Theta, we get x=";x
Print "This is Theta, we get x=";x
Line 7: Line 7:
For i=1 to 3 : Theta i : Next i
For i=1 to 3 : Theta i : Next i
}
}

Beta
Beta

Module Theta2 (x) {
Module Theta2 (x) {
Print "This is Theta2, we get x=";x
Print "This is Theta2, we get x=";x
}
}
Beta ; Theta as Theta2</lang>

Beta ; Theta as Theta2




Line 20: Line 17:
As we can see from code, some statements are like BASIC, except the use of curly brackets {}. Check the code below. We have a Module (as a Procedure), where we define some functions and some variables, as entities. These entities defined in every call to CheckIt, and erased when execution return from CheckIt. By default every parameter in M2000 pass by value. We define two functions, Alfa() where we set type for parameter x and ExpType$() where we not set type for x, and we wish to return the name of type when we make a call. Using DEF we can define variables and functions (in one line).
As we can see from code, some statements are like BASIC, except the use of curly brackets {}. Check the code below. We have a Module (as a Procedure), where we define some functions and some variables, as entities. These entities defined in every call to CheckIt, and erased when execution return from CheckIt. By default every parameter in M2000 pass by value. We define two functions, Alfa() where we set type for parameter x and ExpType$() where we not set type for x, and we wish to return the name of type when we make a call. Using DEF we can define variables and functions (in one line).


Module CheckIt {
<lang >Module CheckIt {
\\ We can't call something out of this module
\\ We can't call something out of this module
Function Alfa(X as double) {
Function Alfa(X as double) {
Line 46: Line 43:
Print ExpType$(10)
Print ExpType$(10)
}
}

\\ We call it
\\ We call it

CheckIt
CheckIt

\\ Now Funtion Alfa and all variables erased.
\\ Now Funtion Alfa and all variables erased.

\\ We can call it again
\\ We can call it again
CheckIt</lang>

CheckIt




Line 61: Line 53:




Module CheckInt {
<lang >Module CheckInt {
A%=1212212.12@
A%=1212212.12@
Print A% ' 1212212
Print A% ' 1212212
Line 77: Line 69:
Print B% ' 122121213
Print B% ' 122121213
}
}
CheckInt</lang>

CheckInt


So we say about Integer Variables, and no Integer Numeric Type. Like in Basic, M2000 is not case sensitive (except for labels), so A% and a% is the same. We may have A, A$ and A% as three variables, or A(), A%(), A$() as arrays or and functions. We can use name(@ ) to call function and not array if we have each with same name.
So we say about Integer Variables, and no Integer Numeric Type. Like in Basic, M2000 is not case sensitive (except for labels), so A% and a% is the same. We may have A, A$ and A% as three variables, or A(), A%(), A$() as arrays or and functions. We can use name(@ ) to call function and not array if we have each with same name.


Dim A(10)=1
<lang >Dim A(10)=1

Def A(x)=x**2
Def A(x)=x**2
Print A(3), A(@ 4)</lang>

Print A(3), A(@ 4)




Line 101: Line 90:




Module Delta {
<lang >Module Delta {
\\ Make a group like a lambda
\\ Make a group like a lambda
\\ A Class make a Global Function
\\ A Class make a Global Function
Line 135: Line 124:
Print Type$(P) ="Group"
Print Type$(P) ="Group"
}
}
Delta</lang>

Delta




Line 143: Line 131:
Until now we see modules/functions/subs for procedural programming, Groups for OOP, Groups as lambda functions and lambda functions for functional programming. We can use events for groups and for COM objects, including GUI objects.
Until now we see modules/functions/subs for procedural programming, Groups for OOP, Groups as lambda functions and lambda functions for functional programming. We can use events for groups and for COM objects, including GUI objects.


<lang >Module Beta {

Module Beta {
Group WithEvents Alpha {
Group WithEvents Alpha {
Event "One"
Event "One"
Line 174: Line 161:
Print M=111
Print M=111
}
}
Beta</lang>

Beta




Line 183: Line 169:
Modules may have Threads, part of modules that can be executed in intervals, can be halted, or can be released, and can be erased. Each thread has own stack and may have own static variables (Modules and Functions also may have static variables), but can use modules variables and functions/modules/subs. Threads can run concurrent (thread return to task manager after execution of a statement or a block of statements) or sequential (a thread has to exit from interval to start other thread)
Modules may have Threads, part of modules that can be executed in intervals, can be halted, or can be released, and can be erased. Each thread has own stack and may have own static variables (Modules and Functions also may have static variables), but can use modules variables and functions/modules/subs. Threads can run concurrent (thread return to task manager after execution of a statement or a block of statements) or sequential (a thread has to exit from interval to start other thread)


Module Zeta {
<lang >Module Zeta {
k=10
k=10
Thread {
Thread {
Line 194: Line 180:
}
}
}
}
Zeta</lang>

Zeta




Line 202: Line 187:




Module Kappa {
<lang >Module Kappa {
Function Theta(x) {
Function Theta(x) {
Structure Points_single {
Structure Points_single {
Line 218: Line 203:
Print Eval(P, 0!x)=1212.12~, Eval(P, 0!y)=21.1212~
Print Eval(P, 0!x)=1212.12~, Eval(P, 0!y)=21.1212~
}
}
Kappa</lang>

Kappa