Author Topic: The L-BASIC Interpreter  (Read 21262 times)

0 Members and 1 Guest are viewing this topic.

Offline luke

  • Administrator
  • Seasoned Forum Regular
  • Posts: 324
    • View Profile
The L-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.

Latest source attached to this post. Project also at https://github.com/flukiluke/L-BASIC 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
  • $include should be written without a comment character or REM

What's working:
  • Apostrophe comments and REM
  • Line joining with :
  • Variable assignment
  • Arrays: multi-dimensional, arrays of UDTs.
  • Array resizing, including _PRESERVE
  • shared variables
  • UDTs
  • Optional arguments to user-defined functions
  • SUBs and FUNCTIONs, including recursive calls and pass by reference
  • 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)
  • SELECT CASE
  • ABS, ASC (function), _ATAN2, ATN, _AUTODISPLAY
  • BEEP, _BLUE32
  • C* rounding functions, CALL, CHDIR, CHR$, CIRCLE, CLOSE, CLS, COLOR, COMMAND$, _COMMANDCOUNT, CONST, COS, CSRLIN, CV* functions
  • DATE$ (function), DEFINT and friends, _DEFINE, _DEFLATE, _DELAY, _DEST (statement), _DEST (function), DIM, _DISPLAY (statement), DRAW
  • END, ENVIRON$ (function), EOF, ERASE (one variant), EXIT, EXP
  • FILES, FIX, _FONTHEIGHT, _FONTWIDTH, FREEFILE
  • GET (file I/O), GOTO (line numbers only, no line labels), _GREEN32
  • _HEIGHT, HEX
  • _INFLATE, INKEY$, INPUT (command), INPUT$ (function), INSTR, INT
  • _KEYCLEAR, _KEYDOWN, _KEYHIT, KILL
  • LBOUND, LCASE, LEFT$, LEN, _LIMIT, LINE, LINE INPUT, _LOADIMAGE, LOCATE, LOF, LOG, LTRIM$
  • MID$ (function), _MOUSEBUTTON, _MOUSEINPUT, _MOUSEMOVEMENTX, _MOUSEMOVEMENTY, _MOUSEX, _MOUSEY
  • OPEN, OPTION _EXPLICIT
  • PAINT, _PI, PLAY, POINT, PRINT, _PRINTSTRING, _PRINTWIDTH, PSET, PUT (file I/O), _PUTIMAGE
  • RANDOMIZE, RIGHT$, RMDIR, RND, _RED32, _RGB, _RGB32, RTRIM$
  • SCREEN (statement), SGN, SIN, SLEEP, SOUND, _SOURCE (statement), _SOURCE (function), SPACE, SQR, STATIC (statement), STR, _STRCMP, _STRICMP, SWAP, SYSTEM
  • TAN, TIME$ (function), TIMER, _TITLE (statement), _TITLE$ (function), _TRIM$
  • UBOUND, UCASE
  • VAL
  • _WHEEL, _WIDTH

What's not working:
  • Arrays in UDTs
  • NEXT with multiple variables on the same line 'NEXT i, j'
  • Line labels
  • GOSUB
  • Error handling
  • Events
  • Line continuation with _
  • Everything else
* lbasic-v0.1.2.bas (Filesize: 307.71 KB, Downloads: 467)
« Last Edit: February 05, 2022, 08:47:40 am by luke »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
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

  • Administrator
  • Seasoned Forum Regular
  • Posts: 324
    • View Profile
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

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
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?

FellippeHeitor

  • Guest
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!

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
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: 2361
  • Cuz I sez so, varmint!
    • View Profile
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
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
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

  • Administrator
  • Seasoned Forum Regular
  • Posts: 324
    • View Profile
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

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
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: 21
  • an ugly avatar :)
    • View Profile
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: 3972
    • View Profile
    • 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

  • Administrator
  • Seasoned Forum Regular
  • Posts: 324
    • View Profile
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

  • Forum Regular
  • Posts: 167
    • View Profile
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
https://www.facebook.com/groups/470369984111370
//////////////////////////////////////////////////////////////////

Offline luke

  • Administrator
  • Seasoned Forum Regular
  • Posts: 324
    • View Profile
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