It is currently Wed Jun 28, 2017 12:20 pm



Welcome
Welcome to rfobasic

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. In addition, registered members also see less advertisements. Registration is fast, simple, and absolutely free, so please, join our community today. **You are not required to provide truthful information to any registration questions. Be whomever you wish to be.!


Post new topic Reply to topic  [ 48 posts ]  Go to page 1, 2, 3, 4, 5  Next
Author Message
 Post subject: BEXGen - the RFO BASIC compiler for Win
Unread postPosted: Sat Sep 03, 2016 10:47 am 
Offline
User avatar

Joined: Sun Nov 23, 2014 8:15 am
Posts: 2185
Location: romania
Hi
This is RFO Basic executable generator for Windows!.
This is the lab version, just to see the principle and test.
these are the BASIC! instructions it knows for the moment:
DIM...
ARRAY.LOAD...
PRINT, ?...
IF...
FOR...
FN.DEF...
demo included
in the left panel you can edit the BAS default program.
click 'Format' button to generate EXE; overwrites default BAS program!.
the second blue panel is the formated BAS; you can save it.
download here:
ftp://86.125.99.23/pub/bexgen1.zip
extract all to any folder.
run BEXGEN.EXE
have fun
Gikam


Last edited by gikam on Sun Sep 04, 2016 12:38 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: BEXGen - the RFO BASIC compiler for Win
Unread postPosted: Sat Sep 03, 2016 10:56 am 
Offline
User avatar

Joined: Thu Jan 08, 2015 11:28 am
Posts: 1088
Location: .NET
i'd love to see the source tho :P

_________________
https://github.com/evolbug
http://toobasic.jimdo.com


Top
 Profile  
 
 Post subject: Re: BEXGen - the RFO BASIC compiler for Win
Unread postPosted: Sat Sep 03, 2016 11:00 am 
Offline
User avatar

Joined: Sun Nov 23, 2014 8:15 am
Posts: 2185
Location: romania
evolbug wrote:
i'd love to see the source tho :P

no problem.
which source?


Top
 Profile  
 
 Post subject: Re: BEXGen - the RFO BASIC compiler for Win
Unread postPosted: Sat Sep 03, 2016 11:09 am 
Offline
User avatar

Joined: Thu Jan 08, 2015 11:28 am
Posts: 1088
Location: .NET
source code of bexgen, if you want you could use a version control system like GitHub to easily keep track of changes, like i do with TooBASIC

_________________
https://github.com/evolbug
http://toobasic.jimdo.com


Top
 Profile  
 
 Post subject: Re: BEXGen - the RFO BASIC compiler for Win
Unread postPosted: Sat Sep 03, 2016 11:30 am 
Offline
User avatar

Joined: Sun Nov 23, 2014 8:15 am
Posts: 2185
Location: romania
syntax conversion and all the preliminary stuff is done in the main program, actual implementation of BASIC functions and device behaviour is done in a separate library.
which u want?
thanks, but I don't need Githup in this stage.


Top
 Profile  
 
 Post subject: Re: BEXGen - the RFO BASIC compiler for Win
Unread postPosted: Sat Sep 03, 2016 11:52 am 
Offline
User avatar

Joined: Thu Jan 08, 2015 11:28 am
Posts: 1088
Location: .NET
how aboot the library? that should be interesting

_________________
https://github.com/evolbug
http://toobasic.jimdo.com


Top
 Profile  
 
 Post subject: Re: BEXGen - the RFO BASIC compiler for Win
Unread postPosted: Sat Sep 03, 2016 12:06 pm 
Offline
User avatar

Joined: Sun Nov 23, 2014 8:15 am
Posts: 2185
Location: romania
i think you'll find interesting only PRINT and ARRAY.LOAD, for now:
Code:
unit rfobox;

interface

uses forms,StdCtrls,ExtCtrls,variants,sysutils,classes,windows,messages;

type tmyvararray=array of variant;

var _mainform_:tform;
    _backbut_,rotbut:tbutton;
    consmemo:tmemo;
    grimage:timage;
    refvars:tstringlist;
    _dummyref_:string=#0;

procedure print(sourcea:array of variant);
procedure array_load(var desta:tmyvararray;sourcea:array of variant);overload;
procedure _pushref_(sourcea:array of variant);
procedure _popref_(var dest:extended); overload;
procedure _popref_(var dest:string); overload;
procedure _terminare_;



implementation

const devicew=320;
      deviceh=480;

procedure print(sourcea:array of variant);
var i:Integer; tstr,prevstr:string;
begin
if length(sourcea)=0 then
  consmemo.Text:=consmemo.Text+#13#10
else
  begin
  for i:=0 to High(sourcea) do
    begin
    case vartype(sourcea[i]) of
        varstring:tstr:=sourcea[i];
        varboolean:if sourcea[i] then tstr:='1.0' else tstr:='0.0';
      else
        tstr:=FormatFloat('0.0#############',sourcea[i]);
      end; //case
    if i=0 then
      begin
      consmemo.Text:=consmemo.Text+tstr;
      continue;
      end
    else
      begin
      if tstr<>#1 then
        begin
        if prevstr=#1 then
          consmemo.Text:=consmemo.Text+tstr
        else
          consmemo.Text:=consmemo.Text+', '+tstr;
        end;
      end;
    prevstr:=tstr;
    end;   //for
    if tstr<>#1 then consmemo.Text:=consmemo.Text+#13#10;
  end;
end;

procedure array_load(var desta:tmyvararray;sourcea:array of variant);
var i:integer;
begin
setlength(desta,length(sourcea)+1); //BASIC 1-based array
for i:=0 to high(sourcea) do
  desta[i+1]:=sourcea[i];   //BASIC 1-based array
end;

procedure _pushref_(sourcea:array of variant);
var i:integer;
begin
refvars.Clear; //nu ar trebui (_popref_ sterge)
for i:=0 to high(sourcea) do
  begin
  if vartype(sourcea[i])=varstring then
    refvars.Add(sourcea[i])
  else
    refvars.Add(floattostr(sourcea[i]));
  end;
end;

procedure _popref_(var dest:extended); overload;
begin
dest:=strtofloat(refvars[0]);
refvars.Delete(0);
end;

procedure _popref_(var dest:string); overload;
begin
if dest<>_dummyref_ then dest:=refvars[0];
refvars.Delete(0);
end;

procedure _terminare_;
begin
_mainform_.Free;
refvars.Free;
removefontresource('RobotoMono-Regular.ttf');
sendmessage(hwnd_broadcast,wm_fontchange,0,0);
application.Terminate;
end;

procedure rotate;
var temp:Integer;
begin
with consmemo do
  begin
  temp:=Width; width:=Height; Height:=temp;
  end;
with grimage do
  begin
  temp:=Width; width:=Height; Height:=temp;
  end;
end;

begin
  _mainform_:=tform.Create(application);
  _mainform_.ClientHeight:=560;
  _mainform_.ClientWidth:=560;
  _mainform_.Caption:='RFOBOX.EXE';
  consmemo:=tmemo.Create(_mainform_);
  consmemo:=tmemo.Create(_mainform_);
  consmemo.Width:=devicew;
  consmemo.Height:=deviceh;
  consmemo.WordWrap:=true;
  consmemo.ReadOnly:=True;
  consmemo.Parent:=_mainform_;
  grimage:=timage.create(_mainform_);
  grimage.Parent:=_mainform_;
  grimage.Width:=devicew;
  grimage.Height:=deviceh;
  _backbut_:=tbutton.Create(_mainform_);
  _backbut_.Top:=_mainform_.Height-80;
  _backbut_.Left:=10;
  _backbut_.Width:=_backbut_.Height;
  _backbut_.Caption:='<';
  _backbut_.Parent:=_mainform_;
  rotbut:=TButton.Create(_mainform_);
  rotbut.Top:=10;
  rotbut.Left:=500;
  rotbut.Width:=40;
  rotbut.caption:='rotate';
  rotbut.Parent:=_mainform_;
  refvars:=tstringlist.create;
  refvars.Clear;
  addfontresource('RobotoMono-Regular.ttf');
  sendmessage(hwnd_broadcast,wm_fontchange,0,0);
  consmemo.Font.Name:='Roboto Mono';

  @rotbut.OnClick:[email protected];
  _mainform_.Show;

end.


Top
 Profile  
 
 Post subject: Re: BEXGen - the RFO BASIC compiler for Win
Unread postPosted: Sat Sep 03, 2016 12:42 pm 
Offline
User avatar

Joined: Thu Jan 08, 2015 11:28 am
Posts: 1088
Location: .NET
this looks weird :D
it reminds me i should probably start work on a "device screen" type of thing. soon enough i will have to implement graphics...
meanwhile, this is how i implement print and array.load, it's way different since it's an interpreter not a compiler (yet, anyway).

PRINT statement
Code:
from . import *

class Print(Statement):
    """ PRINT expression """

    def __init__(self, expression, line=0):
        self.line = line
        self.expression = expression

    def execute(self):
        string = str(self.expression.evaluate())
        if string[-len('\\<\\cont\\>\\'):] == '\\<\\cont\\>\\':
            # continue the line: print str;
            # acts on a "magic" sequence which i should probably change
            print(string[:-len('\\<\\cont\\>\\')], end='')
        else:
            print(string)

    @staticmethod
    def parse():
        return __class__(
            Parser.expression(string=True) if not Parser.match(Type['EOL']) \
            else String(), Parser.line()
        )

#add keywords to the pool
keywords.append('print')
keywords.append('?')

#add node to parser
nodes.update({'print': Print, '?': Print})


ARRAY.LOAD
Code:
from . import *

class ArrayLoad(Statement):
    """ ARRAY.LOAD identifier, expression* """

    def __init__(self, name, args, line=0):
        self.line = line
        self.name = name
        self.args = args

    def execute(self):
        if self.name[-1] == '$':
            array = StrArray(self.name, ArrayDim([Number()])).evaluate()
        else:
            array = NumArray(self.name, ArrayDim([Number()])).evaluate()

        for a in self.args:
            array.extend([a.evaluate()])

    @staticmethod
    def parse():
        name = Parser.consume(Type['word']).value
        Parser.match('[', ']')
        args = list()
        while not Parser.match(Type['EOL']) and Parser.match(','):
            args.append(Parser.expression())

        return __class__(name, args, Parser.line())

keywords.append('array.load')
nodes.update({'array.load': ArrayLoad})


python lets me do fancy stuff, every command is in it's own file, which may seem fragmented but in the end is very clean and easy to maintain, and makes adding new commands a breeze.

this is the base code that goes basically inside every package's header file (__INIT__.py). this one is from Array package.
Code:
# package specific imports here...

nodes = {} #parser nodes, parser imports these
pool = [
    'ArrayCreate',
    'ArrayDelete',
    'ArrayAverage',
    'ArrayCopy',
    'ArrayDims',
    'ArrayFill',
    'ArrayLength',
    'ArrayLoad',
    'ArrayMax',
    'ArrayMin',
    'ArrayReverse',
    'ArraySearch',
    'ArrayShuffle',
    'ArraySort',
    'ArrayStdDev',
    'ArraySum',
    'ArrayVariance',
    # to add a new command i literally just have to add a name here,
    # and create a file with that name. the importer takes care of the rest
]

for module in pool:
    try:
        exec('from .{} import *'.format(module))
    except:
        print('WARNING: missing command class {}'.format(module))
        pass

_________________
https://github.com/evolbug
http://toobasic.jimdo.com


Top
 Profile  
 
 Post subject: Re: BEXGen - the RFO BASIC compiler for Win
Unread postPosted: Sun Sep 04, 2016 12:27 am 
Offline
User avatar

Joined: Sun Nov 23, 2014 8:15 am
Posts: 2185
Location: romania
this is more weird :D
but as you said: compiler<>interpreter, python<>pascal


Top
 Profile  
 
 Post subject: Re: BEXGen - the RFO BASIC compiler for Win
Unread postPosted: Sun Sep 04, 2016 5:34 am 
Offline
User avatar

Joined: Mon Aug 18, 2014 1:16 pm
Posts: 1337
Is all look very interesting especially the duel between yourself and evolbug. :)

Anyway when I run your program I get the results in the pics below.

Regards Roy
Attachment:
g1.PNG
g1.PNG [ 117.16 KiB | Viewed 614 times ]

Attachment:
g2.PNG
g2.PNG [ 110.42 KiB | Viewed 614 times ]


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 48 posts ]  Go to page 1, 2, 3, 4, 5  Next


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
suspicion-preferred