Author Topic: Express BASIC - an interpreter in C  (Read 1353 times)

Offline Gemino Smothers

  • BASIC Developer
  • Posts: 24
    • Lucid Apogee
Express BASIC - an interpreter in C
« on: November 25, 2023, 09:12:59 PM »
My attempt at a BASIC interpreter in C: https://lucidapogee.com/index.php?page=expressbasic

It's syntax is similar to Net BASIC.

DOS and 9x Edition is compiled with DJGPP
Minimal Edition (for XP and up to 11) compiled with Dev C++
Extended Edition (for XP only) compiled with Dev C++

Code: [Select]
1 REM https://rosettacode.org/wiki/Circular_primes
10 LET p = 2
20 LET s = 1
30 LET n = INT(LOG(p) / LOG(10))
40 LET m = 10 ^ n
50 LET q = p
60 LET r = 1
70 FOR i = 0 TO n
80 IF NOT(q < p OR PRIME(q) = 0) THEN 110
90 LET r = 0
100 BREAK i
110 LET q = (q MOD m) * 10 + INT(q / m)
120 NEXT i
130 IF NOT(r) THEN 160
140 PRINT p,
150 LET l = l + 1
160 LET p = p + s
170 LET s = 2
180 IF l < 19 THEN 30

Code: [Select]
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]
1 REM https://rosettacode.org/wiki/Factors_of_an_integer
10 INPUT "enter a number: ", n
15 PRINT "the factors of "; n; " are ";
20 LET a = ABS(n)
30 LET i = i + 1
40 IF a <> INT(a / i) * i THEN 60
50 PRINT i; " ";
60 IF i < INT(a / 2) THEN 30
70 PRINT a; " ";
80 PRINT
90 SHELL "pause"

Code: [Select]
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"