Posts: 35
Threads: 4
Joined: Apr 2022
Reputation:
14
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/rel...-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
'Functions can come before the main program
function fact(n)
if n = 1 then fact = 1 else fact = n * fact(n-1)
end function
for i = 1 to 10 step 2
print "fact("; i; ") = "; fact(i)
next i
Code: (Select All) text$ = "hello" + " " + "world"
for i = 1 to len(text) 'Notice you can leave off the $ on text
print left(text, i) 'And the $ is optional on left too
next i
Posts: 1,000
Threads: 50
Joined: May 2022
Reputation:
27
01-06-2023, 08:06 PM
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?
Posts: 21
Threads: 2
Joined: Jun 2022
Reputation:
0
(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.
My question: Why do not you bring your skills to the QB64pe project?
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!
Posts: 1,587
Threads: 59
Joined: Jul 2022
Reputation:
52
01-06-2023, 10:59 PM
(This post was last modified: 01-06-2023, 11:02 PM by mnrvovrfc.)
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.
Posts: 649
Threads: 95
Joined: Apr 2022
Reputation:
22
01-06-2023, 11:01 PM
(This post was last modified: 01-06-2023, 11:06 PM by PhilOfPerth.)
@ 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.
Posts: 2,686
Threads: 326
Joined: Apr 2022
Reputation:
215
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?
Posts: 35
Threads: 4
Joined: Apr 2022
Reputation:
14
01-07-2023, 02:27 AM
(This post was last modified: 01-07-2023, 02:29 AM by luke.
Edit Reason: typos
)
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
Posts: 422
Threads: 27
Joined: Apr 2022
Reputation:
26
01-07-2023, 01:39 PM
(This post was last modified: 01-07-2023, 01:40 PM by Jack.)
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
Posts: 3,922
Threads: 174
Joined: Apr 2022
Reputation:
210
01-07-2023, 02:40 PM
Ah good news, hope you can eventually give FB a run for it's money ;-))
b = b + ...
Posts: 1,000
Threads: 50
Joined: May 2022
Reputation:
27
01-07-2023, 04:01 PM
(This post was last modified: 01-07-2023, 04:12 PM by Kernelpanic.)
(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.
Also an lbasic hello world program is only 76KB and runs instantly, so I'm pretty happy with that
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
Dim As Integer zahlenFeld(5, 5)
Dim As Integer a, i, j, z
Dim As Integer zeile, spalte
Locate 2, 2
z = 1
For i = 1 To 5
For j = 1 To 5
zahlenFeld(i, j) = z
Print Using "## "; zahlenFeld(i, j), '"Using" Fehler!
z = z + 1
Next
Print: Locate , 2
Next
End
'-----------------------------------------------------------
z = 1
For i = 1 To 5 'Zeile 11 Fehler!
For j = 1 To 5
zahlenFeld(i, j) = z
Print "## "; zahlenFeld(i, j),
z = z + 1
Next
Print: Locate , 2
Next
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
Dim As Integer zahlenFeld(5, 5)
Dim As Integer a, i, j, z
Dim As Integer zeile, spalte
Locate 2, 2
z = 1
For i = 1 To 5 'Zeile 11 Fehler!
For j = 1 To 5
zahlenFeld(i, j) = z
Print "## "; zahlenFeld(i, j),
z = z + 1
Next
Print: Locate , 2
Next
End
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
Dim PS As Double, KW As Double
Dim Auswahl As Integer
Print "1 -- PS in Kilowatt"
Print "2 -- Kilowatt in PS"
Print
Input "Ihre Wahl: ", Auswahl
Print
If Auswahl = 1 Then
Input "Anzahl PS: ", PS
KW = PS / 1.36
Print -- Fehler?
Print KW
Else
Input "Anzahl Kilowatt: ", KW
PS = KW * 1.36
Print
Print PS
End If
End
|