Writing a BASIC-like compiler in PowerBasic 
Author Message
 Writing a BASIC-like compiler in PowerBasic

Hello,

I've been programming for a little over 18 years, on dozens of platforms.
Although I enjoy assembly in it's various flavors first and foremost, my
high-level language of choice is BASIC (although I know several others.)
My favorites over the years were C128 Basic 7.0 for interpreter and Blitz
Basic II (for Amiga) as a compiler.  

After moving to the PC about two years ago from the Amiga platform, I was
stunned and disappointed at the seemingly small amount of "evolution" the
BASIC language has had here.  At the moment I know of no BASIC compilers
for the PC that have all the features I crave for serious development (most
are realmode, a definite hindrance, others lack certain vital language
features, etc.)

In the meantime I've been doing all my serious coding in x86 assembly, and
limiting my use of high-level languages (powerbasic in particular) to
prototyping of algorythms,  and other not-so-serious programming.

Well, I'd really like a good compiler so I didn't have to code in assembly
*all the time* however I've waited forever it seems and PowerBasic hasn't
made any real worthwhile improvements to it's language even though I've
bought every single update and version that they've released.  The only
32-bit PowerBasic is in fact the newly-released PBDLL 5.0, and having just
recieved it I was so disappointed I finally made up my mind:

I'm going to write my own compiler, it seems nobody else will (or can) do
it "right"

I think it'd be easiest to simply create generic .ASM output for NASM to
assemble, otherwise have to dig into all the details of object files,
linkers, etc. and I'm not that patient :)  Besides, I'd end up writing an
assembler anyway if I went that route, because IMO no high-level language
is any good without inline assembler.

I decided to write the compiler in PowerBasic (of course) for two reasons:
First, it will take a bit less time than writing it in assembly, and
second, it'd be nice to eventually compile the compiler with itself... And
using a language that is similar in syntax will make that final conversion
easier.

Since writing the compiler is only something I can do in my (limited) spare
time, it would be great if anyone who is interested would offer to help me
code it.  In fact, I wouldn't mind making the entire thing PD or something
so that it could be developed over the 'net like NASM and other languages
have been.... I know a good BASIC might be something I could sell, but I'd
rather just get it done and use it to write other things I can sell :)

So, if you think you're skilled enough and interested in helping me with
this project, let me know.  I could probably even post the source I've
written so far (mostly just simple parser and data structures for now etc.)
I'm currently worrying about targetting pmode DOS only at the moment, but
once that's working should be easy to add the ability to target Win32 as
well (as a compiler directive or commandline switch, maybe.)

I should mention that the language I've designed is very much LIKE many of
the dialects of Basic you've seen, but a bit more serious/powerful.  That
means I'm not really interested in 100% compatibility with QuickBasic or
any of the other M$-inspired BASICs-- in fact that would only be a
hindrance in the long run.  

I'd just like to have a serious high-level programming language BESIDES
C/C++/Pascal/etc. and I have a feeling a lot of you BASIC fans out there
would appreciate it too.

Please let me if you're interested in helping me out.

--

-= Richard T. Elmore =-
-= "Head" Of HeadSoft Software =-



Sat, 04 Mar 2000 03:00:00 GMT  
 Writing a BASIC-like compiler in PowerBasic

Quote:
>I'd just like to have a serious high-level programming language BESIDES
>C/C++/Pascal/etc. and I have a feeling a lot of you BASIC fans out there
>would appreciate it too.

I've been working through Jack Crenshaw's "Let's Write A Compiler"
tutorial, translating his Turbo Pascal code into QuickBasic 4.5 as I go.
Reading one language and writing in another is a good way to avoid falling
into "clerical mode", where information flows into the eyes and out through
the fingers, bypassing the brain.  I got as far as implementing procedures
when the tutorial petered out.  Crenshaw eventually got back to it, but
after so long that he had to start over.  The second version is cleaner
than the first, but it hasn't gone as far.
So far, i've got a toy-scale compiler and a good idea of how *long* it
would take to write the super-BASIC  that you're thinking of.


Tue, 07 Mar 2000 03:00:00 GMT  
 Writing a BASIC-like compiler in PowerBasic



Quote:
> Hello,

> I'm going to write my own compiler, it seems nobody else will (or can) do
> it "right"

im going the same way 3 month ago.

Quote:

> I think it'd be easiest to simply create generic .ASM output for NASM to
> assemble, otherwise have to dig into all the details of object files,
> linkers, etc. and I'm not that patient :)  Besides, I'd end up writing an
> assembler anyway if I went that route, because IMO no high-level language
> is any good without inline assembler.

my code is MASM or WASM(Watcom) compatible.

Quote:

> I decided to write the compiler in PowerBasic (of course) for two

reasons:
i'm doing it in QB
Quote:
> First, it will take a bit less time than writing it in assembly, and
> second, it'd be nice to eventually compile the compiler with itself...
And
> using a language that is similar in syntax will make that final
conversion
> easier.

> Since writing the compiler is only something I can do in my (limited)
spare
> time, it would be great if anyone who is interested would offer to help
me
> code it.  In fact, I wouldn't mind making the entire thing PD or
something
> so that it could be developed over the 'net like NASM and other languages
> have been.... I know a good BASIC might be something I could sell, but
I'd
> rather just get it done and use it to write other things I can sell :)

> So, if you think you're skilled enough and interested in helping me with
> this project, let me know.  I could probably even post the source I've
> written so far (mostly just simple parser and data structures for now
etc.)
> I'm currently worrying about targetting pmode DOS only at the moment, but
> once that's working should be easy to add the ability to target Win32 as
> well (as a compiler directive or commandline switch, maybe.)

My compiler is making source for PMode-Dos and runs with most of the common
dos-extender.
Im very insterested in your sourcecode. comparing with my source would be
a great help for me.

Quote:
> I'd just like to have a serious high-level programming language BESIDES
> C/C++/Pascal/etc. and I have a feeling a lot of you BASIC fans out there
> would appreciate it too.

I dontt think these languages are more serious than Basic. The source
these compiler do is very slow. They are only good if you optimeze the
source by hand (like Basic).

bye,
Thomas Sch?fer



Tue, 07 Mar 2000 03:00:00 GMT  
 Writing a BASIC-like compiler in PowerBasic


Quote:

>Hello,

>I've been programming for a little over 18 years, on dozens of platforms.

>So, if you think you're skilled enough and interested in helping me with
>this project, let me know.  I could probably even post the source I've
>written so far (mostly just simple parser and data structures for now etc.)
>I'm currently worrying about targetting pmode DOS only at the moment, but
>once that's working should be easy to add the ability to target Win32 as
>well (as a compiler directive or commandline switch, maybe.)

>I should mention that the language I've designed is very much LIKE many of
>the dialects of Basic you've seen, but a bit more serious/powerful.  That
>means I'm not really interested in 100% compatibility with QuickBasic or
>any of the other M$-inspired BASICs-- in fact that would only be a
>hindrance in the long run.  

>I'd just like to have a serious high-level programming language BESIDES
>C/C++/Pascal/etc. and I have a feeling a lot of you BASIC fans out there
>would appreciate it too.

>Please let me if you're interested in helping me out.

>-= Richard T. Elmore =-
>-= "Head" Of HeadSoft Software =-

I've written an interpreted language (originally in MS PDS7.1, then ported to
PowerBASIC).  It's reason to exist is more along the lines of file
manipulation.  I've wanted to create compiler specific code for it, but, like
you, I've not been willing to dig into object modules, linkers, etc.  If you'd
like to see it, it's on my site at http://www.geocities.com/Eureka/9049

If you start putting something together, let me know.  I'd love to at least
take a good look at it.

Paul



Wed, 08 Mar 2000 03:00:00 GMT  
 Writing a BASIC-like compiler in PowerBasic

I've gotten a few replies to this post in e-mail, but I'd like to see more
in the newsgroup itself if possible, I think it will stir more interest.
Thanks!



Thu, 09 Mar 2000 03:00:00 GMT  
 Writing a BASIC-like compiler in PowerBasic


Quote:
>Hello,

>I've been programming for a little over 18 years, on dozens of platforms.
>Although I enjoy assembly in it's various flavors first and foremost, my
>high-level language of choice is BASIC (although I know several others.)
>My favorites over the years were C128 Basic 7.0 for interpreter and Blitz
>Basic II (for Amiga) as a compiler.  

>After moving to the PC about two years ago from the Amiga platform, I was
>stunned and disappointed at the seemingly small amount of "evolution" the
>BASIC language has had here.  At the moment I know of no BASIC compilers
>for the PC that have all the features I crave for serious development (most
>are realmode, a definite hindrance, others lack certain vital language
>features, etc.)

>In the meantime I've been doing all my serious coding in x86 assembly, and
>limiting my use of high-level languages (PowerBasic in particular) to
>prototyping of algorythms,  and other not-so-serious programming.

>Well, I'd really like a good compiler so I didn't have to code in assembly
>*all the time* however I've waited forever it seems and PowerBasic hasn't
>made any real worthwhile improvements to it's language even though I've
>bought every single update and version that they've released.  The only
>32-bit PowerBasic is in fact the newly-released PBDLL 5.0, and having just
>recieved it I was so disappointed I finally made up my mind:

>I'm going to write my own compiler, it seems nobody else will (or can) do
>it "right"

>I think it'd be easiest to simply create generic .ASM output for NASM to
>assemble, otherwise have to dig into all the details of object files,
>linkers, etc. and I'm not that patient :)  Besides, I'd end up writing an
>assembler anyway if I went that route, because IMO no high-level language
>is any good without inline assembler.

>I decided to write the compiler in PowerBasic (of course) for two reasons:
>First, it will take a bit less time than writing it in assembly, and
>second, it'd be nice to eventually compile the compiler with itself... And
>using a language that is similar in syntax will make that final conversion
>easier.

>Since writing the compiler is only something I can do in my (limited) spare
>time, it would be great if anyone who is interested would offer to help me
>code it.  In fact, I wouldn't mind making the entire thing PD or something
>so that it could be developed over the 'net like NASM and other languages
>have been.... I know a good BASIC might be something I could sell, but I'd
>rather just get it done and use it to write other things I can sell :)

>So, if you think you're skilled enough and interested in helping me with
>this project, let me know.  I could probably even post the source I've
>written so far (mostly just simple parser and data structures for now etc.)
>I'm currently worrying about targetting pmode DOS only at the moment, but
>once that's working should be easy to add the ability to target Win32 as
>well (as a compiler directive or commandline switch, maybe.)

>I should mention that the language I've designed is very much LIKE many of
>the dialects of Basic you've seen, but a bit more serious/powerful.  That
>means I'm not really interested in 100% compatibility with QuickBasic or
>any of the other M$-inspired BASICs-- in fact that would only be a
>hindrance in the long run.  

>I'd just like to have a serious high-level programming language BESIDES
>C/C++/Pascal/etc. and I have a feeling a lot of you BASIC fans out there
>would appreciate it too.

>Please let me if you're interested in helping me out.

Richard,

Have you given a look at OmniBasic. It was written in itself. You mentioned
that M$ compatibility was no requirement. Omni has pointers, based variables,
macros, advanced structures, and lots of other goodies. Its predecessor was
CDL Basic which was written for most of the reasons you mention and output
MC68000 assembler code for the OS-9 os. Omni is a follow-up to CDL Basic that
generates C code so that it is portable. We have ports for Amiga, Linux (386),
MSDOS, Win95/NT, OS/2, OS-9, OS-9000, and with any luck there will be an HP-UX
version in a day or so to be followed by a BSD version. I might be willing to
do a joint venture with you if you want to develop the 386 assembler code
thing. The easiest way to accomplish this would be to modify the CDL source to
produce 386 code instead of 68000 code. While Omni was first compiled by CDL
Basic, I have never tried to compile CDL with Omni. It should work without too
much trouble since I have recompiled many CDL programs with Omni with no
modification at all.

Omni also has inline C and inline asm. Omni produces very fast executables of
resonable size. The modification to CDL basic that I proposed above would do
even better in speed and code size. I will eventually do the project myself
anyway, so  it suits your needs and desires also, let me know.

-Mike



Fri, 10 Mar 2000 03:00:00 GMT  
 Writing a BASIC-like compiler in PowerBasic

Michael L. Smith says "I never expected the spanish inquisition when I
said..."

Quote:
> Have you given a look at OmniBasic.

<Big Snip>
Whoops, I seem to have stumbled into the
comp.buy-omnibasic-or-die
NG.
So sorry, I'll try and find my way back to c.l.b.m now...


Fri, 10 Mar 2000 03:00:00 GMT  
 Writing a BASIC-like compiler in PowerBasic

Hey, NOBODY expects the Spanish Inquisition.

Surprise is one of our greatest weapons. Surprise and terror...our TWO
greatest weapons....

Quote:

> Michael L. Smith says "I never expected the spanish inquisition when I
> said..."
> > Have you given a look at OmniBasic.
> <Big Snip>
> Whoops, I seem to have stumbled into the
> comp.buy-omnibasic-or-die
> NG.
> So sorry, I'll try and find my way back to c.l.b.m now...



Fri, 10 Mar 2000 03:00:00 GMT  
 Writing a BASIC-like compiler in PowerBasic


Quote:

> I've gotten a few replies to this post in e-mail, but I'd like to see more
> in the newsgroup itself if possible, I think it will stir more interest.
> Thanks!

I'm the author of Object Basic, a commercial Basic environment for the
Mac. The prototype compiler was actually written in Basic itself, so I
have some experience doing what you're describing.

It sounds obvious and boring, but *plan out your dialect* before you start
writing any of the parser. Don't be scared of a "context free grammar" -
this is just a map of every possible element in your language and how it
fits together.  If you are already familiar with some variety of Basic, it
may be best to copy its dialect and tweak it until you're happy with it.

This is quite important because certain seemingly minor changes to parts
of the language can ripple throughout the whole design and invalidate
scores of assumptions. For example, in my prototype I did not allow for
user-defined data types; you could use the ones that came with the system,
but that was it. This soon became inadequate, and I had to rewrite large
portions of the expression, variable, and database modules to accomodate
custom data types. If you plan this sort of stuff out ahead of time, so
that you know just what you can and can't do with the language, you can
save yourself a lot of grief.

Expect to change this once your compiler is running, though. Once you
start using the language, you will inevitably find rough edges and things
that could be simplified. You'll get this amazingly empowered feeling,
once the full realization of having the compiler bow to your wishes rather
than the other way around kicks in. :-)

There are hundreds of things you can do to optimize a compiler. Don't do
any of them. Just make it work. There will be plenty of time to optimize
it later. Let me assure you, it is a far more enjoyable (and successful)
enterprise to speed up a working compiler than it is to struggle along
optimizing everything as you go with nothing to show for it until the end.

I've found that the compiler's internal database is quite important, and
the scanner and parser are actually fairly straightforward by comparison.
The database keeps track of everything your compiler knows about - all
functions, variables, record types, constants. To do this effectively
you'll need some sort of dynamic memory allocation. ReDim will do, if your
dialect of Basic supports it; if not, you'll need to call some routine
from the OS, or write your own suballocator (which is not too hard, but
requires careful thought).

That's it for the general stuff. If you have specific questions, feel free
to email me, and I'll do what I can to reply. I presume you can decipher
the spam-blocking in my email address. ;-)

-Mars Saxman
programmer & head visionary
Red Planet Software



Sun, 12 Mar 2000 03:00:00 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. PowerBasic Vidual Basic Compiler

2. BASIC compiler written in BASIC yet?

3. PowerBASIC Console Compiler 3.0 Internet Communications

4. New PowerBASIC compilers!

5. Good shareware compiler on PowerBASIC's site

6. PowerBASIC precompiler and C++ cross compiler...

7. Compatibility: PowerBASIC Console Compiler, QB4.5

8. POWERBASIC CONSOLE COMPILER FOR WINDOWS VERSION 1.0

9. Compiler switches for MS Basic Compiler 5.35

10. FS: PowerBasic DLL Compiler

11. PowerBASIC Console Compiler

12. Want to buy older version of Powerbasic DLL compiler

 

 
Powered by phpBB® Forum Software