Author Topic: Hello to all  (Read 16083 times)

Steve A.

  • Guest
Hello to all
« on: September 05, 2010, 08:02:40 PM »
Hello,
to all new and future members.
It appears that I have the great fortune of making the first post to this forum.

Some time ago, I wrote an online tutorial, titled: "Let's Build a Scripting Engine-Compiler"
after starting the "Blunt Axe Basic Project", (simply called Bxbasic).
The tutorial is downloadable in different formats from the link at the bottom of this page.

What is Bxbasic ?
Bxbasic is presented as a programming tutorial, to develop and construct a Console Mode Scripting Engine and Byte Code Compiler. The Bxbasic dialect is a subset of the GW-Basic and QBasic programming languages.


How did Bxbasic get started ?
Well, this whole thing started years ago, when a number of programmers and I, that frequented the Rapid-Q developer’s group site, decided that we just didn't like what was going on out there in the realm of Rapid-Q and Basic programming in general.  So, we set out to form our own programmer’s group, that being the QDepartment group.

A number of us were toying around with the various dialects of Basic currently available and we just weren't satisfied with what we were seeing. Microsoft has entirely and long ago abandoned QBasic/QuickBasic. A language many of us got a great deal of enjoyment programming in. Some of us program as an occupation and others just for pleasure. At any rate, Visual Basic (VB) costs an absolute fortune and some of the other alternatives just don't have the 'Touch and Feel' of QBasic. Not that QBasic is the greatest dialect or language ever written, by any means, but, (IMHO) it's just a fun environment to program in.

Unfortunately, QBasic (and Quick Basic 4.5) are still relegated to the world of 16 bit programming. When I first got involved with this, I was just looking for a tool that I could use to recompile some old Quick Basic programs I had written so that they could run in a 32 bit environment.

Like so many others, I experimented with the various dialects of Basic now available, with mixed results. Some Basics claimed to be nearly QBasic, others claimed to need only minimal rewriting. Some were available for 'free' while others cost quite a hefty chunk. Some of the so-called 'free' ones ended up really being crippled or minimal versions of a commercially available full featured product. Rapid-Q, one that I thought I liked (and so did a lot of other people) ended up requiring a full 50% rewrite before I could get any pre-existing code to run on it. And then, it didn't do all the things I needed it to do.

One day, some one suggested that maybe we should try to develop our own version of QBasic. If we could do that, then we would control what it did, what it didn't do and what it might do. So, after spending a few years learning what you need to know about writing interpreters and compilers, I began writing Bxbasic. From that point forward, in my spare time, I’ve been slogging through it. Writing code and finding out what worked and what didn't and finding out why not. Little by little, I started putting together the beginnings of a QBasic like scripting engine (interpreter). I needed to start with what I considered the most rudimentary aspects of the "Console Mode" GW-Basic and QBasic dialects.

Anyway, I figured I'd start with a "Console Mode" scripting engine-compiler and work up gradually, to bigger and better things. I'd add features a little at a time and eventually build this into something I might actually be able to use. That's where we are now.

Today, (in 2010, after a number of years on the back-burner), Bxbasic consists of:
A) a BASIC interpreter,
B) a BASIC scripting engine / byte-code compiler,
C) and a BASIC-to-MASM translator.


There are also two ports of Bxbasic, done by others;
1) a Pocket PC port,
2) and an Allegro port, which adds GUI support.

Work is ongoing on the intepreter and translator, heading in the direction of a stand-alone Basic Compiler.

Download Blunt_Axe_Basic tutorial:

http://sites.google.com/site/bluntaxebasic/tutor/

-or- visit:

http://tech.groups.yahoo.com/group/QDepartment/
« Last Edit: September 06, 2010, 07:55:09 AM by Steve A. »

JRS

  • Guest
Re: Hello to all
« Reply #1 on: September 05, 2010, 08:09:30 PM »
Thanks Steve for the intro to your Basic interpreter. Good to hear you still have plans for Bxbasic.


E.K.Virtanen

  • Guest
Re: Hello to all
« Reply #2 on: September 08, 2010, 07:02:17 AM »
I have to say that without Steve's excellent tutorial, i would propably have dropped my plans to create interpreter atleast for a while.
Now, in three days i have done it over 1000 lines and im impatient to get my hands released to code for more. But i guess it is better to feed the kids and such before opening a editor  :D

jcfuller

  • Guest
Re: Hello to all
« Reply #3 on: September 10, 2010, 03:54:50 AM »
Steve,
  I wanted to take a look at bxb but it appears you make no provisions for those that already have masm installed?
I don't want to unzip anything into my already functioning masm directory.

James

Steve A.

  • Guest
Re: Hello to all
« Reply #4 on: September 10, 2010, 06:34:26 AM »
I don't want to unzip anything into my already functioning masm directory.

Hello James,

Actually, the one file:    BxbAsm-Masm.zip

contains everything you need:
        BxbUpdate.zip
               executable and dependant Bxb files.
and
        sources.zip
               C source files.

Just don't extract: Bxbasm.zip

Steve

E.K.Virtanen

  • Guest
Re: Hello to all
« Reply #5 on: September 14, 2010, 01:08:55 AM »
Steve. I have studied your excellent tutorial now for many days. Eventhough i am not good with C, my personal feeling is that it should not be hard to port your C code to FreeBASIC.

Due im not sure, what you think? Would be interesting and goood for learning to port your C codes to FB.

JRS

  • Guest
Re: Hello to all
« Reply #6 on: September 14, 2010, 02:30:32 AM »
If your a Basic programmer and trying to learn C then download a copy of BCX and look at your translated Basic code in C.

BCX only generates what it needs and there is no static runtime to link to.

I'm currently excited about Charles's OxygenBasic JIT compiler and it's ease of use, flexibility and seemingly unlimited possibilities.



E.K.Virtanen

  • Guest
Re: Hello to all
« Reply #7 on: September 14, 2010, 07:52:55 AM »
Hi JRS.

For sure, i am interested to learn atleast basic's of C/C++ in future. However, currently family, job and plans of our future keeps me so busy that i can do only one out of two things in this scene.

A. Learn concept and ways to build a interpreter.
B. Learn C.

Cant do both, due i am not good enough to focus my braincells for both  ::) ;D

I decided to learn A. with basic, then possibly learn C/C++ programming by porting my basic interpreter code for it.

Steve A.

  • Guest
Re: Hello to all
« Reply #8 on: September 14, 2010, 11:15:20 AM »
Steve. I have studied your excellent tutorial now for many days. Eventhough i am not good with C, my personal feeling is that it should not be hard to port your C code to FreeBASIC.

Probably.
I am not familiar with FreeBasic.
So, it should probably be done by someone who is familiar with it.
And, who has the available time to do it.

jcfuller

  • Guest
Re: Hello to all
« Reply #9 on: September 14, 2010, 11:44:22 AM »
I took a quick look and it  should port to Bcx quite well, but as you said Steve; Who has the time?

James

E.K.Virtanen

  • Guest
Re: Hello to all
« Reply #10 on: September 14, 2010, 11:53:24 AM »
Well, if ill move my plans to build my own interpreter and give my time for this then yes, i might be able to do it incase someone is ready to answer multiple times for questions about C language  ;D

E.K.Virtanen

  • Guest
Re: Hello to all
« Reply #11 on: September 14, 2010, 11:57:10 AM »
Well, i did once port nearly 30% of your C code to yabasic, but then limits of it stopped my work. Cant remember closely anymore.

Instead of porting source files, it might be easier to follow your tutorial and code examples there. Then i do understand what the code does, and i can use my FB "knowledge" to solve the situation.

Well, i can only be unsuccesful in worst.

jcfuller

  • Guest
Re: Hello to all
« Reply #12 on: September 14, 2010, 12:12:02 PM »
I couldn't resist a try.

James

Code: [Select]
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
'Let's Build a Scripting Engine-Compiler
'Blunt Axe Basic Project
'By: S. Arbayo
'=======================================================================
'Code converted to Bcx using MinGwTD g++ compiler
' James C. Fuller
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
$CPP
$NOMAIN

$ONEXIT "GCTD.BAT $FILE$ -m32"
#include <iostream>
#include <string>
#include <fstream>

$USENAMESPACE std
CONST fsout=fstream::out
CONST fsin=fstream::in
CONST fsapp= fstream::out OR fstream::in OR fstream::app
CONST stdstr = std::string

CONST BUFSIZE = 81
CONST LINE_NUM = 6
CONST TOKEN_LEN = 21


Dim f_in AS FILE
Dim f_out AS FILE
Dim prog_name AS char Ptr
Dim p_string[BUFSIZE] As char
Dim array1 As char Ptr Ptr
Dim array2 As char Ptr Ptr
Dim t_holder[20] As char
Dim s_holder[BUFSIZE] As char
Dim token[TOKEN_LEN] As char
Dim xstring As char Ptr
Dim ncolumns = BUFSIZE
Dim nrows As Integer
Dim line_ndx As Integer
Dim s_pos As Integer
Dim e_pos AS Integer
'easier than converting to Bcx
$CCODE
/* ----- function prototypes ----- */
    void a_bort(int,int);
    void line_cnt(char *argv[]);
    void program_array(void);
    void pgm_parser(void);
    void get_token(void);
    void parser(void);
    void beep(void);
    void cls(void);
    void xstring_array(void);
    void get_prnstring(void);
    void go_to(void);
$CCODE

Function main( argc As Integer,argv As char Ptr Ptr)
Raw x As Integer
Raw ab_code As Integer
x = 0
ab_code = 1
cout << "BXBasic Interpreter" << endl
If argc <> 2 Then
a_bort(ab_code,x)
Exit Function
EndIf
t_holder = argv[1]
line_cnt(argv)
End Function
'==============================================================================
Sub a_bort(code As Integer,line_ndx As Integer)
Select Case code
Case 1
cout << "Unspecified Program Name." << endl
cout << "Enter: " << DQ$ << "bxbasic program_name.bas" << DQ$ << endl
cout << "code " << code << endl
Case 2
cout << "Program file " << DQ$ << t_holder << DQ$ << " not found" << endl
cout << "Enter: " << DQ$ << "bxbasic program_name.bas" << DQ$ << endl
cout << "Program Terminated code " << code << endl
Case Else
cout << "Program aborted, undefined error." << endl
End Select

End Sub
'==============================================================================
'I got lazy here and just added the whole "c" function as is
' I did have to cast prog_name (char*) 
$CCODE
void line_cnt(char *argv[])
{   int line_counter=0, ab_code=2;
    int fnam_len, x=0;

    fnam_len = strlen(argv[1]);
    fnam_len++;
    prog_name = (char*)malloc(fnam_len * sizeof(char));
    strcpy(prog_name, argv[1]);
    f_in = fopen(prog_name,"r");    /*' does program_name.bas exist */
    if(f_in == NULL)                /*' file not found */
    {   a_bort(ab_code, x);
    }
    else
    {   while(!feof(f_in)) /*' until EOF, read-in and */
        {   fgets(p_string, BUFSIZE, f_in); /*' count each line */
            if(!feof(f_in))
            {    line_counter++;
            }
        }
        fclose(f_in);
    }
    nrows=line_counter;
}
$CCODE


Steve A.

  • Guest
Re: Hello to all
« Reply #13 on: September 14, 2010, 03:46:52 PM »
Instead of porting source files, it might be easier to follow your tutorial and code examples there. Then i do understand what the code does, and i can use my FB "knowledge" to solve the situation.

I think that's the correct approach.
If you follow the tutorial, at least you have a description of what you should be getting.

Otherwise, you pretty much need to know what the C source code is intended to do.
Heck, sometimes I have to dig out my printed copy of the tutorial, to study what I wrote.

Doing it that way, with FreeBasic, or any dialect, I think it could be done.

Steve A.

  • Guest
Re: Hello to all
« Reply #14 on: September 14, 2010, 03:50:59 PM »
I couldn't resist a try.

James
Code: [Select]
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
'Let's Build a Scripting Engine-Compiler
'Blunt Axe Basic Project
'By: S. Arbayo
'=======================================================================
'Code converted to Bcx using MinGwTD g++ compiler
' James C. Fuller
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=

Hah !  :D
Pretty clever.