The L-BASIC compiler - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3) +---- Forum: Works in Progress (https://qb64phoenix.com/forum/forumdisplay.php?fid=9) +---- Thread: The L-BASIC compiler (/showthread.php?tid=1369) |
The L-BASIC compiler - luke - 01-06-2023 For some time now I have been working on a BASIC compiler which I've called L-BASIC. In many ways it's still rather primitive and in early stages, but it's reached the point where it can compile simple programs to executable format so I thought I'd make a thread for it. Although all the source is available here on github and it's mostly written in QB64, it's rather complicated to build. If you'd like to try it, there's a prebuilt download-and-run version for 64 bit windows here: https://github.com/flukiluke/L-BASIC/releases/download/v0.1.9/lbasic-v0.1.9-windows-x86_64.7z You'll need to run it from a command prompt: "lbasic.exe test.bas" to compile test.bas, then run "test.exe" assuming you got no errors. Some notes and warnings: - Very poor support for most commands. All programs are console programs, you have a primitive PRINT but no input. - DO, WHILE, IF, ELSE, FOR should work. ELSEIF, SELECT and EXIT don't. - No GOTO or GOSUB, but SUB and FUNCTION can create subs/functions, and you can call them. Recursion works. - Data types are INTEGER, LONG, INTEGER64 (no underscore), SINGLE, DOUBLE, QUAD, STRING. No _UNSIGNED. The usual suffixes %, & etc. are available. - Basic string support: concatenation (a$ + b$), LEFT$, RIGHT$, MID$, CHR$ - All numeric operators are available and should work with proper precedence. This includes bitwise (AND, OR, XOR, NOT, IMP, EQV), relational (<, >, <=, >=, =, <>), arithmetic (+, -, *, /, \, MOD, ^). Some programs that work: Code: (Select All) 'Recursive factorial Code: (Select All) text$ = "hello" + " " + "world" RE: The L-BASIC compiler - Kernelpanic - 01-06-2023 Hello Luke, I do not want to discourage you, but all the basic versions now remind me of Linux. Around 5,555 distris, and also a reason why Linux never became an alternative, albeit a small one, to Windows; kind of like MacOS. My question: Why do not you bring your skills to the QB64pe project? RE: The L-BASIC compiler - cage - 01-06-2023 (01-06-2023, 08:06 PM)Kernelpanic Wrote: Hello Luke, I do not want to discourage you, but all the basic versions now remind me of Linux. Around 5,555 distris, and also a reason why Linux never became an alternative, albeit a small one, to Windows; kind of like MacOS.Why would even say something like that. You think that just because you use a closed source, one size fits all OS that you have the right to belittle someone who has taken the time to make a contribution to FreeBasic, just because he uses Linux! RE: The L-BASIC compiler - mnrvovrfc - 01-06-2023 Choice is good with Linux, the problem is a bunch of distros are garbage (such as Linux Mint although the D.E. they created is OK). @Kernelpanic I don't know what you mean by "all the basic versions now remind me of Linux" but somebody is trying to share something which is not easy to program, and even if it's incomplete or it works differently from a BASIC dialect somebody is most comfortable with. I've had a hard time getting accustomed to SICK64 because it wants line numbers and single-letter variables, and doesn't support string arrays but those are my ignorance and limitations. EDIT: How about a BASIC that supports full-blown subprograms (not "GOSUB" and not half-effort like "DEF FN") and a full math/logic expression parser? Two things difficult to do for somebody who doesn't have enough patience and time but would like to have his/her own BASIC-like or MS-DOS-batch-language-like interpreter. Maybe somebody could team up with Luke and come up with a BASIC dialect that supports graphics and music, although in a limited way. Because a few BASIC interpreters are offered for Linux which don't dare go beyond 16-bit stuff. Also, not everybody could install or compile Freebasic because it's fairly demanding with dependencies. It seems to want a specific version of "gcc" or "glibc" and refuses to work if that's not put down correctly. One of the "QB64 Samples" programs is a LISP interpreter. I should have taken some time to play with it, instead of trying to dive into Racket. I mean, Racket has good documentation but it's not really suitable for a beginner into a 60-year-old programming language trying to compete with other heavyweights like Python. Could I welcome another LISP interpreter written by someone anyhow? Absolutely. Only please be based on Scheme, I had to choose between that and Common LISP and I'm beginning to resent the latter seems to be more commonplace. Originally I was going to learn Scheme ("script-fu") to mess around with pictures in GIMP LOL. RE: The L-BASIC compiler - PhilOfPerth - 01-06-2023 @ Luke: Sorry to hear you see Kernelpanic's comment that way. I'm sure it was made in good spirit and with the growth of PE at heart. He's right; you have skills that will be a great asset here. RE: The L-BASIC compiler - SMcNeill - 01-07-2023 One thing to remember guys: Luke has did as much for the project as anyone. Take a look at his contribution chart in the github, if you would. I think he's more than earned to right to work on whatever the BLEEP he wants to work on, whether that's L-Basic or just picking his nose and flicking boogers at his cat. **NO ONE** is obligated to work on the project, and everyone who does work on it does so **at their own pace and willingness to contribute, with the understanding that they can step back and take a break from the project at any time**. And another thing to keep in mind -- though he may have stepped back and doesn't work *AS HARD* on the project as he did at one point in the past -- Luke is *still* contributing to the project. Check our repo and you'll see where he made a fix to help optimize compile times, put in a pull request for that fix, and had it approved and become part of the official language which you guys will all get to enjoy in the next release, which should be coming real soon(tm). So as to the question: "Why do not you bring your skills to the QB64pe project?" The answer is: "He has, and he still is." At 15+ million bytes of code contributed to the source, I think he's definitely earned the right to work on and share whatever the HONK he wants to work on with us. Don't you guys? RE: The L-BASIC compiler - luke - 01-07-2023 It's a sensible question to ask, why work on another compiler when we already have one? I see this largely as a research project. It's never going to be a replacement for QB64 because it doesn't have full backward compatibility with QBasic (the biggest example being that x& and x% aren't allowed as separate variables here), and so I don't expect it to gain much general use. However it's an opportunity to experiment with a different architecture, both in terms of the compiler itself and the runtime libraries. The underlying machine code generator (llvm) has support for Just-In-Time compilation, which I expect to be able to use to add an interactive interpreter mode while reusing most of the parsing and runtime code. It is also possible to target webassembly, which opens interesting possibilities for compiling programs to run in the browser. I doubt I'll ever be able to catch up to QB64 in terms of command support; at the rate Matt & the team are adding things, they keep getting further away. But that's okay because I'm not trying to be a replacement, just a look at how things could be done. Also an lbasic hello world program is only 76KB and runs instantly, so I'm pretty happy with that RE: The L-BASIC compiler - Jack - 01-07-2023 luke, I am very interested in your project, thank you for sharing your work a number of programming languages started with a humble goal, like an intellectual challenge but later took a life of it's own RE: The L-BASIC compiler - bplus - 01-07-2023 Ah good news, hope you can eventually give FB a run for it's money ;-)) RE: The L-BASIC compiler - Kernelpanic - 01-07-2023 (01-07-2023, 02:27 AM)luke Wrote: However it's an opportunity to experiment with a different architecture, both in terms of the compiler itself and the runtime libraries. The underlying machine code generator (llvm) has support for Just-In-Time compilation, which I expect to be able to use to add an interactive interpreter mode while reusing most of the parsing and runtime code. It is also possible to target webassembly, which opens interesting possibilities for compiling programs to run in the browser. Thanks for the answer. Yes, that's right, one learn from experimenting like this; I did that too when I started with Basic & Co. Ok! I put "lbasic" in the path and tried it with arrays, there are problems; see messages. Maybe it helps. Code: (Select All) Rem Luke-Basic, 7. Jan. 2023 Here is the mistake message: For i = 1 To 5 'Zeile 11 Fehler! PS D:\Lab\Lukebasic> lbasic LFeld.bas codegen: bad ll type: INTEGER[2] Code: (Select All) Rem Luke-Basic, 7. Jan. 2023 There is also an error message that I don't understand: 18 is Print(?) Error with or without "Print". In QB64 it works. Code: (Select All) Option _Explicit |