Express BASIC - an interpreter in C
Posted: Tue Oct 17, 2023 5:56 am
Different computer, same program
Express BASIC is a minimal BASIC dialect that is suitable for performing complex calculations. The language is inspired by Dartmouth, Palo Alto, Altair, GW BASIC, and the many dialects of Tiny BASIC.
It is written in C and is open source. I have been working nonstop on this and am finally at a point I am comfortable sharing it. The syntax is very close to Net Basic. Most programs written in Express BASIC will run in QBasic or GWBasic with little modification.
Programs may be typed directly, loaded with LOAD "filename.bas", saved with SAVE "filename.bas", cleared with NEW, listed with LIST, etc. You may pass source files through the command line, drag and drop, or association.
The interpreter features a classic style line mode editor and will run on all versions of Windows 95 and up. There's just enough commands and functions to be useful. My goal is for this language to be standard and minimal. I don't want to get crazy with the syntax like with Craft Basic and Commando Basic. This will be my "normal" BASIC along side Net Basic.
So, with Net Basic being written in PHP and Express BASIC in C, I think this will be the last language I will make for a long time hopefully.
Get it here: https://lucidapogee.com/index.php?page=expressbasic
Here's a few examples...
Express BASIC is a minimal BASIC dialect that is suitable for performing complex calculations. The language is inspired by Dartmouth, Palo Alto, Altair, GW BASIC, and the many dialects of Tiny BASIC.
It is written in C and is open source. I have been working nonstop on this and am finally at a point I am comfortable sharing it. The syntax is very close to Net Basic. Most programs written in Express BASIC will run in QBasic or GWBasic with little modification.
Programs may be typed directly, loaded with LOAD "filename.bas", saved with SAVE "filename.bas", cleared with NEW, listed with LIST, etc. You may pass source files through the command line, drag and drop, or association.
The interpreter features a classic style line mode editor and will run on all versions of Windows 95 and up. There's just enough commands and functions to be useful. My goal is for this language to be standard and minimal. I don't want to get crazy with the syntax like with Craft Basic and Commando Basic. This will be my "normal" BASIC along side Net Basic.
So, with Net Basic being written in PHP and Express BASIC in C, I think this will be the last language I will make for a long time hopefully.
Get it here: https://lucidapogee.com/index.php?page=expressbasic
Here's a few examples...
Code: Select all
10 REM ROCKET.BAS by Brian Tung
20 REM Modified to work with Express Basic
30 LET a = 1.032
40 LET d = 1
50 PRINT "Earth gravity in light-years per year squared: "; a
55 PRINT "Distance in light-years (0-100 million): "; d
60 IF d >= 0 AND d <= 100000000 THEN 80
70 PRINT "Distance must be between 0 and 100 million l-y"
75 END
80 LET d1 = d / 2
90 LET t = SQR(d1 * d1 + (2 * d1 / a))
100 LET x = a * t
110 LET m = 1
120 IF x >= 0 THEN 130
125 LET m = -1
130 LET s = LOG(ABS(x) + 1)
140 LET s1 = s + 1
150 LET x1 = (EXP(s) - EXP(s * -1)) / 2 - ABS(x)
160 LET s1 = x1 / (EXP(s) + EXP(s * -1)) / 2
170 LET s = s - s1
180 IF ABS(s1) > .0000001 THEN 150
190 LET t1 = 1 / a * s * m
200 LET v = a * t / SQR(1 + (a * t) * (a * t))
210 PRINT "Time on Earth: "; 2 * t; " years"
220 PRINT "Time on board: "; 2 * t1; " years"
230 SHELL "pause"
Code: Select all
1 REM MODIFIED TO WORK WITH EXPRESS BASIC
10 PRINT "HURKLE"
20 PRINT "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"
30 PRINT
110 LET N=5
120 LET G=10
210 PRINT
220 PRINT "A HURKLE IS HIDING ON A ";G;" BY ";G;" GRID. HOMEBASE"
230 PRINT "ON THE GRID IS POINT 0,0 IN THE SOUTHWEST CORNER,"
235 PRINT "AND ANY POINT ON THE GRID IS DESIGNATED BY A"
240 PRINT "PAIR OF WHOLE NUMBERS. THE FIRST NUMBER IS"
245 PRINT "THE HORIZONTAL POSITION AND THE SECOND NUMBER"
246 PRINT "IS THE VERTICAL POSITION. YOU MUST TRY TO"
250 PRINT "GUESS THE HURKLE'S GRIDPOINT. YOU GET ";N;" TRIES."
260 PRINT "AFTER EACH TRY, I WILL TELL YOU THE APPROXIMATE"
270 PRINT "DIRECTION TO GO TO LOOK FOR THE HURKLE."
280 PRINT
285 LET A=INT(G*RND)
286 LET B=INT(G*RND)
290 LET K = 0
310 LET K = K + 1
320 PRINT "GUESS #";K
330 INPUT "X: ", X
335 INPUT "Y: ", Y
340 IF ABS(X-A)+ABS(Y-B)=0 THEN 500
350 REM PRINT INFO
360 GOSUB 610
370 PRINT
380 IF K <= N THEN 310
410 PRINT
420 PRINT "SORRY, THAT'S ";N;" GUESSES."
430 PRINT "THE HURKLE IS AT ";A;",";B
440 PRINT
450 PRINT "LET'S PLAY AGAIN, HURKLE IS HIDING."
460 PRINT
470 GOTO 285
500 REM
510 PRINT
520 PRINT "YOU FOUND HIM IN ";K;" GUESSES!"
540 GOTO 440
610 PRINT "GO ";
620 IF Y=B THEN 670
630 IF Y<B THEN 660
640 PRINT "SOUTH";
650 GOTO 670
660 PRINT "NORTH";
670 IF X=A THEN 720
680 IF X<A THEN 710
690 PRINT "WEST";
700 GOTO 720
710 PRINT "EAST";
720 PRINT
730 RETURN
999 END
Code: Select all
1 REM https://rosettacode.org/wiki/Attractive_numbers
10 FOR x = 1 TO 120
20 LET n = x
30 LET c = 0
40 IF n MOD 2 <> 0 THEN 70
50 LET n = INT(n / 2)
60 LET c = c + 1
70 IF n MOD 2 = 0 THEN 40
80 FOR i = 3 TO SQR(n) STEP 2
90 IF n MOD i <> 0 THEN 120
100 LET n = INT(n / i)
110 LET c = c + 1
120 IF n MOD i = 0 THEN 90
130 NEXT i
140 IF n <= 2 THEN 160
150 LET c = c + 1
160 IF NOT(PRIME(c)) THEN 180
170 PRINT x,
180 NEXT x
190 PRINT
200 SHELL "pause"
Code: Select all
1 REM https://rosettacode.org/wiki/Golden_ratio/Convergence
5 PRECISION 6
10 LET phi0 = 1
20 LET phi1 = 1 / phi0 + 1
30 LET d = ABS(phi1 - phi0)
40 LET phi0 = phi1
50 LET i = i + 1
60 IF d >= .00001 THEN 20
70 PRINT "result: "; phi1; " after "; i; " iterations"
80 PRINT "the error is approximately "; phi1 - (.5 * (1 + SQR(5)))
90 SHELL "pause"
Code: Select all
1 REM https://rosettacode.org/wiki/Nth_root
5 PRECISION 6
10 LET a = INT(RND * 5999) + 2
20 PRINT "nth root of "; a; "..."
30 FOR n = 1 TO 10
40 LET p = .00001
50 LET x = a
60 LET y = a / n
70 IF ABS(x - y) <= p THEN 110
80 LET x = y
90 LET y = ((n - 1) * y + a / y ^ (n - 1)) / n
100 IF ABS(x - y) > p THEN 80
110 PRINT n; " : "; y
120 NEXT n
130 SHELL "pause"