Express BASIC - an interpreter in C

Started by Lucidapogee, Oct 17, 2023, 06:03 AM

Previous topic - Next topic

johnno56

Here is an interesting wrinkle with "sphere". Using 'extended' via Wine... The program coded and ran without error... I was expecting the sphere to be displayed within the console, just as your example, but it actually draw it directly to the upper left corner of the Desktop... As soon as I hit any key, including 'print screen', the sphere would vanish...

"Riddle me that one, Batman".

I will test the other posted examples and get back to you...

By the way... there were no adverse side effects to the system... Just a bit weird... lol
May your journey be free of incident.  Live long and prosper.

johnno56

The same thing happened when drawing the "fern". The program executed and was drawn onto the desktop.

It was worth a shot...
May your journey be free of incident.  Live long and prosper.

Lucidapogee

#17
This is all crazy and weird to me as well. It started when someone at another forum asked if I will be adding graphics support. Well, this is of course a complicated decision to make in C. There's no standard way, many libraries, and little cross platform solutions.

Especially with the way I am doing things. I wanted to make a console line number mode editor and interpreter like the old days. The complication is that if I want to display graphics, I need to open a window using the console as a parent. How is that even done? From looking at Microsoft documentation, I need to do a "mangled main" and a bunch of stuff that would require a bunch of things to change in a way that would further break portability.

So, using windows.h and gdi in this context seemed too difficult for me. I messed around with Allegro. I finally got it working after realizing it conflicts with windows.h. Problem is it raised my exe size to like 500kb. No way. Not having it.

I tried graphics.h and simply had no luck. I followed steps to setup Dev C++ and the linkers to compile the Borland graphics.h library. When I finally got it to compile the program just crashes and there's no errors left to debug. So I gave up on that for now.

I tried GL. It was too complicated similarly to the windows.h gdi. Gave up on that.

While bouncing around and trying to figure all of this out, I came across some articles discussing unique Windows features and BCX. That's where I got this crazy idea and the functions to draw directly to a console.

https://www.daniweb.com/programming/software-development/code/216430/add-a-little-graphics-to-your-console

https://www.daniweb.com/programming/software-development/code/216431/put-a-bitmap-image-on-your-console-c

http://blog.airesoft.co.uk/2012/10/things-ms-can-do-that-they-dont-tell-you-about-console-graphics/

I decided to create the Minimal and Extended Editions of Express BASIC specifically for Windows using this feature. This way, I would work on making the Minimal Edition more portable. That way I may compile a DOS/9X edition, Linux Edition, and Windows CE edition all separately.

The problem I am having now is that the Extended Edition which is solely intended for Windows.... is sadly only compatible with 32 bit Windows. It doesn't work on 9X and is untested, but probably won't work on anything other than 2000 and XP.

The fact that it partially worked on WINE is interesting. Maybe the results will be similar on Windows 7/10/11. Still waiting for the opportunity to test on newer systems as my newest is XP.

I think what is going on is WINE was unable to allow the program to obtain a handle for the console or something like that. When you use these drawing routines and do not apply a handle, you draw directly to the entire screen over everything. You can create a screensaver like program that takes over the screen like that.

At any rate, I am still keeping this project in the Alpha Version phase, so major changes may still take place. Particularly in the Extended Edition which is very experimental right now. I will likely try finding a better supported graphics implementation. Maybe Visual Studio 2005 is what I need.. Or Borland. Something that can compile from 95 all the way to 11. As opposed to Bloodshed, the noob compiler that I depend on.

johnno56

Ran the "sphere" via my WinXP Virtual Box...

May your journey be free of incident.  Live long and prosper.

johnno56

May your journey be free of incident.  Live long and prosper.

Lucidapogee

Is it running slow? The interpreter is pretty slow, so I imagine that's amplified on a virtual box.

johnno56

#21
The "fern" does perform 10,000 iterations so, regardless of the Basic, it will be slow... But it wasn't too bad...

The 'sphere' was a little slow... but that could be because it was doing the angles 'on the fly'. Storing and reading the angles using an array could possibly speed up the drawing...

Overall, EB performed quite well...

You mentioned that the interpreter was "pretty slow". Logically, that would imply that, you would have had an actual or mental reference for comparison? Regardless, I think it is pretty cool that there are those who are clever enough to create interpreters! Very cool.. (Note: A not very well hidden compliment... Well done!)
May your journey be free of incident.  Live long and prosper.

ZXDunny

Tried testing the sphere in SpecBAS but it wouldn't run.

Took a while to figure out but it's because you guys (and QB et al) re-evaluate your STEP expressions (at the very least!) every loop in FOR?

In mine the STEP expression is evaluated once when the loop is set up, so of course the example code failed to run.

Lucidapogee

#23
Work has kept me pretty busy these past few weeks and I am starting a new job tomorrow. Sadly, I haven't had time to be on the computer.

Quote from: johnno56 on Oct 26, 2023, 07:20 PMThe "fern" does perform 10,000 iterations so, regardless of the Basic, it will be slow... But it wasn't too bad...

The 'sphere' was a little slow... but that could be because it was doing the angles 'on the fly'. Storing and reading the angles using an array could possibly speed up the drawing...

Overall, EB performed quite well...

You mentioned that the interpreter was "pretty slow". Logically, that would imply that, you would have had an actual or mental reference for comparison? Regardless, I think it is pretty cool that there are those who are clever enough to create interpreters! Very cool.. (Note: A not very well hidden compliment... Well done!)
The way I am parsing the code is just really sub optimal. The main focus was getting it to run stable. It means a lot to me that you like it. Thank you.

Quote from: ZXDunny on Oct 30, 2023, 09:53 AMTried testing the sphere in SpecBAS but it wouldn't run.

Took a while to figure out but it's because you guys (and QB et al) re-evaluate your STEP expressions (at the very least!) every loop in FOR?

In mine the STEP expression is evaluated once when the loop is set up, so of course the example code failed to run.

Hmm it never occurred to me that would be non standard. It isn't something I use quite often.

I adapted the sphere example from this Rosetta Code entry for Sinclair ZX81 BASIC on the Draw a Sphere task.

10 LET I=21
20 LET J=2
30 FOR K=-PI TO PI STEP 0.07
40 PLOT 21+I*SIN K,22+21*COS K
50 PLOT 21+21*SIN K,22+(I-1)*COS K
60 NEXT K
70 LET I=I-J
80 LET J=J+1
90 IF I>0 THEN GOTO 30

That version should work on your BASIC with little to no modification.

My adaption has a few differences, but works directly with QBasic and GWBasic. That's probably why I assumed there was nothing unusual. I could have left it the way it was and just replaced the PLOT to PSET, but I am trying to take advantage of any opportunity to demonstrate language features.

Honestly, I kind of like the feature. It isn't something I see in a lot of other languages now that you mention it. I think some languages don't even support expressions at all for the step.

I really don't even know what it is that I am doing. Just poking around the dark trying to figure things out based on how I expect things to work.

With my new job, my posts and updates will be few for a while. Hopefully in the next month or so, I will start making time on my days off to get right back into it.

ZXDunny

Quote from: Lucidapogee on Nov 03, 2023, 05:01 PMHonestly, I kind of like the feature. It isn't something I see in a lot of other languages now that you mention it. I think some languages don't even support expressions at all for the step.

It's something I never considered myself to be honest! On mine (and in Sinclair in general) the loop point is the statement after the FOR statement, we never go back to the FOR - the bounds are tested on NEXT. I'm assuming that in yours you re-interpret the FOR statement each loop, hence you could use expressions for your STEP parameter. I do of course allow those (you can use an expression anywhere a numeric value is expected) but they only evaluate once.

Lucidapogee

That makes me wonder. How exactly do you not return to the FOR? Do you maintain a stack or something?

That way I am doing it is the NEXT searches up for the nearest FOR with a matching index variable. Then pulls the parameters and reevaluates. This method is surely slow. But still, I am proud of it. Wasn't easy to figure out. Took me way too long.  ;D

ZXDunny

Quote from: Lucidapogee on Nov 05, 2023, 05:19 PMThat makes me wonder. How exactly do you not return to the FOR? Do you maintain a stack or something?

Sinclair BASIC stores the loop info with the variable - basically, all numeric vars can store extra information alongside the value they hold. Keep the loop location (the statement after the FOR), the limit and the step inside the var, then when NEXT comes along you test it there. 

Lucidapogee

#27
I would probably never have thought of that. Maybe in tbe future, I will try that method.

Lucidapogee

#28
Updates!

https://lucidapogee.com/forum/viewtopic.php?t=93
https://lucidapogee.com/forum/viewtopic.php?t=99

There now a DOS Edition (8088 compatible), DPMI Edition (386 compatible), Win32 Edition, and Linux Edition. Still alpha version for now.

The Linux Edition has been tested on various distros.
The DOS Edition has been tested on the Book 8088.

The DOS Edition is compiled with Borland Turbo C 1.
The DPMI Edition is compiled with DJGPP.
The Win32 and Linux Editions are compiled with Open Watcom.

Each edition has almost identical source code and the examples are totally identical. This makes Express BASIC a fully cross platform programming language.

The Linux Edition provides an elf file. I'd like to know how it works on other distros. Let me know.

CharlieJV

Quote from: Lucidapogee on Feb 04, 2024, 04:57 AMUpdates!

https://lucidapogee.com/forum/viewtopic.php?t=93
https://lucidapogee.com/forum/viewtopic.php?t=99

There now a DOS Edition (8088 compatible), DPMI Edition (386 compatible), Win32 Edition, and Linux Edition. Still alpha version for now.

The Linux Edition has been tested on various distros.
The DOS Edition has been tested on the Book 8088.

The DOS Edition is compiled with Borland Turbo C 1.
The DPMI Edition is compiled with DJGPP.
The Win32 and Linux Editions are compiled with Open Watcom.

Each edition has almost identical source code and the examples are totally identical. This makes Express BASIC a fully cross platform programming language.

The Linux Edition provides an elf file. I'd like to know how it works on other distros. Let me know.

Very cool!