I started this project a few days ago. This has been on my mind for months.
My goal is to create a minimal BASIC in PHP.
This will bring BASIC to places where Javascript isn't present.
The language is called Net Basic. It's essentially just a programmable calculator with BASIC keywords.
https://lucidapogee.com/netbasic/
Net Basic - a BASIC in PHP
Re: Net Basic - a BASIC in PHP
We're working on adding more examples.
Also trying to add for loops.
For now, prime() and facorial() have been added.
Also trying to add for loops.
For now, prime() and facorial() have been added.
Re: Net Basic - a BASIC in PHP
I have updated Net Basic.
The three examples by MikeHawk (http://petesqbsite.com/phpBB3/viewtopic.php?p=39352) have been added.
Based on the issue I described in the post above, I decided to change how the NOT() works for now. Let me know if this is bad.
Returns
Now identical to QBasic.. except for when floating point values are used. I don't know what to do with that. I know the newer languages have a more optimal version of NOT, but I wanted this to be a classic BASIC like language.
This is what I am doing in PHP:
The commented out line is what I started with.
The three examples by MikeHawk (http://petesqbsite.com/phpBB3/viewtopic.php?p=39352) have been added.
Based on the issue I described in the post above, I decided to change how the NOT() works for now. Let me know if this is bad.
Code: Select all
10 LET i = -10
20 PRINT i, NOT(i)
30 LET i = i + 1
40 IF i < 10 THEN 20
Code: Select all
-10 9
-9 8
-8 7
-7 6
-6 5
-5 4
-4 3
-3 2
-2 1
-1 0
0 -1
1 -2
2 -3
3 -4
4 -5
5 -6
6 -7
7 -8
8 -9
9 -10
This is what I am doing in PHP:
Code: Select all
case "!":
$pointer--;
//$evalstack[$pointer] = !intval($evalstack[$pointer]);
if ($evalstack[$pointer] == ""){
$evalstack[$pointer] = "-1";
}else{
$evalstack[$pointer] = strval(floatval($evalstack[$pointer]) * -1 - 1);
}
$pointer++;
break;
Re: Net Basic - a BASIC in PHP
I tried all sorts of stuff to try making it work like QBasic, but ultimately I decided it was out of the scope of what I am trying to do. I reverted everything to work like YaBasic, Just Basic, and PHP.
1 is true and 0 is false
this applies to all operator and functions
1 and 1 equals 1
not(0) equals 1
not(1) equals 0
etc..
I just added a neat new feature to allow for "compiling" of programs. Basically, a URL is generated containing the encoding of your program. This way it may be shared, linked, bookmarked, iframed, or popped up. The URL appears whenever you RUN a program. Simply copy/paste it wherever.
And now...
The GET command is an advanced feature intended to be used with URL encoded programs. The command returns the contents of a variable with the same name from the URL. Variable names must be upper case in the URL.
Take this simple program and encode it to a url using the IDE on the Net Basic page.
Once you get the url, add the variables to the url in upper case. Notice the U=25.99&E=.925881&G=.7924&I=82.628&J=145.96 part.
Here's the URL ready to go.
https://www.lucidapogee.com/netbasic/?U ... Y%22%0D%0A
When you click the link, you will get exchange rates. Simply modify the GET variables to change the program output.
1 is true and 0 is false
this applies to all operator and functions
1 and 1 equals 1
not(0) equals 1
not(1) equals 0
etc..
I just added a neat new feature to allow for "compiling" of programs. Basically, a URL is generated containing the encoding of your program. This way it may be shared, linked, bookmarked, iframed, or popped up. The URL appears whenever you RUN a program. Simply copy/paste it wherever.
And now...
The GET command is an advanced feature intended to be used with URL encoded programs. The command returns the contents of a variable with the same name from the URL. Variable names must be upper case in the URL.
Take this simple program and encode it to a url using the IDE on the Net Basic page.
Code: Select all
1 REM USD currency conversion
10 GET u
20 PRINT "$"; u; " USD ="
30 GET e
40 GET g
50 GET i
60 GET j
70 PRINT u * e; " EUR"
80 PRINT u * g; " GBP"
90 PRINT u * i; " INR"
100 PRINT u * j; " JPY"
Here's the URL ready to go.
https://www.lucidapogee.com/netbasic/?U ... Y%22%0D%0A
When you click the link, you will get exchange rates. Simply modify the GET variables to change the program output.