Author Topic: The 65 BASIC Interpreter  (Read 864 times)

Offline luke

  • QB64 Developer
  • Forum Regular
  • Posts: 164
The 65 BASIC Interpreter
« on: July 04, 2020, 11:09:05 AM »
I've been fiddling away on a BASIC interpreter (because it's basically a rite of passage to write one yourself, right?) for a little while and thought I'd at least start a forum thread for it. It's primarily interactive, so you can just hit F5 in the IDE to launch it and start typing commands. You can also drag-and-drop source code files onto it (or give a command line argument) to run a file.

It's early days so there's still lots that's unsupported, but I can run all the programs up to the start of Task 5 in Terry Ritchie's QB64 tutorial, so that's something!

Latest source attached to this post. Project also at https://github.com/flukiluke/65/ for the interested. There will be bugs, feel free to yell at me if you get an error with something that's on the "working" list.

What's different:
  • Variables with the same name but different types are an error, not different variables
  • No _ for INTEGER64
  • It's called QUAD instead of _FLOAT

What's working:
  • Apostrophe comments and REM
  • Line joining with :
  • Variable assignment
  • Data types INTEGER %, LONG &, INTEGER64 &&, SINGLE !, DOUBLE #, QUAD ## and STRING $
  • Addition, subtraction, multiplication, division, integer division, exponentiation, negation, MOD, AND, OR, NOT, XOR, IMP, EQV, =, <>, <, >, <=, >=
  • PRINT and ?, handles ; and , as variable separators
  • DO, WHILE and FOR loops
  • IF THEN ELSEIF ELSE END IF (single and multi-line versions)
  • ABS, ASC (function), ATN
  • BEEP
  • C* rounding functions, CHDIR, CHR$, CIRCLE, CLS, COLOR, COMMAND$, CONST, COS, CSRLIN, CV* functions
  • DIM for scalar variables,
  • FIX
  • INT, INPUT command
  • GOTO (line numbers only, no line labels)
  • LEFT$
  • MID$ (function)
  • PLAY
  • RIGHT$
  • SCREEN (statement), SOUND, SYSTEM

What's not working:
  • Arrays
  • UDTs
  • SUBs/FUNCTIONs
  • NEXT with multiple variables on the same line 'NEXT i, j'
  • SELECT CASE
  • Line labels
  • GOSUB
  • Error handling
  • Events
  • Line continuation with _
  • Everything else
« Last Edit: July 11, 2020, 11:09:18 PM by luke »

Offline bplus

  • Forum Resident
  • Posts: 4614
  • B+ nots
Re: The 65 BASIC Interpreter
« Reply #1 on: July 04, 2020, 11:46:15 AM »
Ah this sounds interesting, I will check it out. Particularly interested in strings, are you doing or plan to do everything the QB64 way like formally Type all variables or do you have plans for some modern things like some OOPs.

Offline luke

  • QB64 Developer
  • Forum Regular
  • Posts: 164
Re: The 65 BASIC Interpreter
« Reply #2 on: July 04, 2020, 12:04:48 PM »
Ultimately it's still a very statically typed language, because I do want something that can eventually compile too and I don't want to make my life too hard. That said, I fully expect to have some niceties like polymorphic functions, optional arguments and returning arrays & UDTs. Don't expect proper objects - I'm trying to implement the language we know and love with just some obvious extensions along the way.

Offline bplus

  • Forum Resident
  • Posts: 4614
  • B+ nots
Re: The 65 BASIC Interpreter
« Reply #3 on: July 04, 2020, 12:11:04 PM »
Well already I see it might become the Immediate Mode someone was looking for awhile back.

I don't remember if Fellippe's was doing that too?

Offline FellippeHeitor

  • QB64 Developer
  • Forum Resident
  • Posts: 2233
  • LET IT = BE
    • QB64.org
Re: The 65 BASIC Interpreter
« Reply #4 on: July 04, 2020, 12:13:43 PM »
Mine is a mere toy. This is the real deal. We should all watch it as it blossoms!

Online Dav

  • Forum Regular
  • Posts: 243
Re: The 65 BASIC Interpreter
« Reply #5 on: July 04, 2020, 01:00:19 PM »
What a great beginning!  Looking forward to watching this grow.

- Dav

Offline Pete

  • Forum Resident
  • Posts: 1983
  • Cuz I sez so, varmint!
Re: The 65 BASIC Interpreter
« Reply #6 on: July 04, 2020, 01:14:52 PM »
You blew it already. 65? Binary school called, your refund check is in the mail! J/K.

Good "luke" with the project,

Pete

Offline bplus

  • Forum Resident
  • Posts: 4614
  • B+ nots
Re: The 65 BASIC Interpreter
« Reply #7 on: July 04, 2020, 01:16:00 PM »
I kinda wish I saw more of the seed before it got 130+ constants and over 2000 (LOC).

I hope Luke has a little time to discuss beginnings, maybe another episode of QB64 talk show.

Yeah where does 65 come from? 1 more that 64?

Offline luke

  • QB64 Developer
  • Forum Regular
  • Posts: 164
Re: The 65 BASIC Interpreter
« Reply #8 on: July 04, 2020, 01:21:09 PM »
I suck at naming things and desperately need suggestions. Ideally a pun of some kind.

A lot of the constants and the DATA tables are auto-generated. See the github link for the actual sources and earlier versions.

Offline bplus

  • Forum Resident
  • Posts: 4614
  • B+ nots
Re: The 65 BASIC Interpreter
« Reply #9 on: July 04, 2020, 01:24:10 PM »
65 works! It is 64 + 1! That's cool!

I will check out the earlier versions thanks for info.

Offline +KZ

  • Newbie
  • Posts: 20
  • an ugly avatar :)
Re: The 65 BASIC Interpreter
« Reply #10 on: July 04, 2020, 03:26:16 PM »
how when you find a BASIC Compiler and that need to be compiled with a BASIC Compiler and that need to be compiled with a BASIC Compiler and that need to be compiled with a BASIC Compiler and that need to be compiled with a BASIC Compiler and that need to be compiled with a BASIC Compiler......
google translate :0

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 2605
    • Steve’s QB64 Archive Forum
Re: The 65 BASIC Interpreter
« Reply #11 on: July 04, 2020, 03:28:03 PM »
how when you find a BASIC Compiler and that need to be compiled with a BASIC Compiler and that need to be compiled with a BASIC Compiler and that need to be compiled with a BASIC Compiler and that need to be compiled with a BASIC Compiler and that need to be compiled with a BASIC Compiler......

They tend to start that way, until they mature to the point where they can self-compile.  When QB64 was first being created, it was compiled with QB45, until it matured enough to start compiling itself.  :)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline luke

  • QB64 Developer
  • Forum Regular
  • Posts: 164
Re: The 65 BASIC Interpreter
« Reply #12 on: July 05, 2020, 01:26:41 AM »
Updated to now support integer division, fix operator precedence and add loops! DO LOOP, WHILE WEND and FOR NEXT all supported. This means it can now run programs like this:
Code: [Select]
const MAGIC_NUMBER = 17

print "Guess the number"
print "I'm thinking of a number, can you guess what it is?"

do
    input "Your guess: ", guess%
    if guess% > MAGIC_NUMBER then print "Nope,"; guess%; "is too high."
    if guess% < MAGIC_NUMBER then print "Nope,"; guess%; "is too low."
loop while guess% <> MAGIC_NUMBER
print "Yes, you got it!"
« Last Edit: July 05, 2020, 01:28:55 AM by luke »

Offline Aurel

  • Newbie
  • Posts: 90
Re: The 65 BASIC Interpreter
« Reply #13 on: July 05, 2020, 03:52:25 AM »
WOW man ...!
That is great ...i like it !
//////////////////////////////////////////////////////////////////
https://aurelsoft.ucoz.com
//////////////////////////////////////////////////////////////////

Offline luke

  • QB64 Developer
  • Forum Regular
  • Posts: 164
Re: The 65 BASIC Interpreter
« Reply #14 on: July 05, 2020, 07:21:40 AM »
Progress continues apace, now supporting the colon (:) for multiple commands on one line and the use of ELSEIF. The interactions between the colon, REM and the IF statement are tricky to get right - I encourage you to give it your most fiendish IF-THEN command and see if you can break it.

Program from Terry Ritchie's tutorials we can now run:
Code: [Select]
DIM Value% 'numeric value the user supplies

INPUT "Enter a number between 1 and 100 >", Value%
IF Value% < 1 THEN
    PRINT "That number is less than one!"
ELSEIF Value% > 100 THEN
    PRINT "That number is greater than one hundred!"
ELSE
    PRINT "Thank you for helping us help you help us all."
END IF