BASIC Interpreter

General discussion for topics related to the FreeBASIC project or its community.
tblanck
Posts: 67
Joined: Jun 15, 2006 15:58

BASIC Interpreter

Post by tblanck »

Hello everybody,

I'm writing this post because I'm working on a BASIC Interpreter and I need help to improve it. At this moment, the interpreter can interpret most of the FreeBASIC functions. I hope it will be possible to make it 100% compatible with FreeBASIC.

The current main thing to improve is speed and, first of all, it could be very usefull to improve the mid() function to make it work faster.

So if somebody has got a fast code (maybe in assembler) for the mid() function, don't hesitate to post it.

Note : the interpreter will be free and at least partly, if not completely, open source. Everybody contributing to this project will have his/her name mentionned in the credits.

I will send the code and give more information very soon.

Thanks to everybody !
Galeon
Posts: 563
Joined: Apr 08, 2009 5:30
Location: Philippines
Contact:

Post by Galeon »

Interesting.
vdecampo
Posts: 2992
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Post by vdecampo »

So if somebody has got a fast code (maybe in assembler) for the mid() function, don't hesitate to post it.
Why don't you use the FreeBASIC versions? Aren't they fast enough?

-Vince
aurelVZAB
Posts: 666
Joined: Jul 02, 2008 14:55
Contact:

-

Post by aurelVZAB »

Hi...
I'm interested to becose i already have one written in CBasic called
'Project One' maby you can use something if you interested.
My atention is rewrite code to Free Basic but i'm still lerning FB(argh..).
vdecampo
Posts: 2992
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Post by vdecampo »

It is funny this should come up now because I have been toying with the idea of making an interpreted version of FreeBASIC for some time.

-Vince
aurelVZAB
Posts: 666
Joined: Jul 02, 2008 14:55
Contact:

Post by aurelVZAB »

Why not vdecampo...
Interpreters are good for test code on the fly before compiling.
Many people dont like interpreters becose most interpreters can't make
standalone exe but on the other side offer quick executing .
Free Basic is really great programming language which offer many
ways of programming and i'm fascinating with his capabilities.
I always wanna make simple basic compiler but my current knowlege
about this thematic is still on start becose i'm to busy with real life.
And one simple but very good example of compiler is written in
VB 6 called Libry Compiler which code is free.
I think that will be posible convert this code to FB and make similiar
compiler in Free Basic.

Aurel
marcov
Posts: 3462
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Post by marcov »

Well, interpreting and compiling are fundamentally different processes, and achieving 100% compatibility will be hard.

However that is not the thing that worries me about this thread. It is more why mid$ would be rate-limiting for an interpreter?
tblanck
Posts: 67
Joined: Jun 15, 2006 15:58

mid() function

Post by tblanck »

Concerning the mid() function, maybe what I wrote wasn't really clear. In fact I don't know if there is a way to make a mid() function that works faster than the FreeBASIC one. I was just asking if somebody had an idea ?

Some people will certainly ask why the mid() function is so important in my interpreter : simply because I use it to extract parts of the script lines (extract the function names, parameters, etc...) but maybe there is a faster way to do the same without using mid.

I will send a post with a link to download the interpreter this week end.
jevans4949
Posts: 1186
Joined: May 08, 2006 21:58
Location: Crewe, England

Post by jevans4949 »

Depending how your parser works, you might be able to get better performance with zstrings, or zstring pointers, and C library functions like strcopy /strncopy /strcmp /strncmp.
srvaldez
Posts: 3379
Joined: Sep 25, 2005 21:54

Post by srvaldez »

aurelVZAB
Posts: 666
Joined: Jul 02, 2008 14:55
Contact:

Post by aurelVZAB »

Yes depending on your current parser.
I think that best option for parser will be inline assembly.
I have one somwhere but i dont know where written by Charles Pagge.
by the way i use my own in ABasic which parse trough RichEdit control:

Code: Select all

'---- count words in string ----------------------------------
	WC = 1
    Pos = InStr(text, " ",0)
    While Pos > 0
        WC = WC + 1
        Pos = InStr(text, " ",pos+1)
    Wend
    CountWords = WC

'------------------------------------------------
'extract words
'-------------------------------------------------
IF wc>0       
    SPos = 1      
    EPos = InStr(text, " ",SPos) - 1
    If EPos <= 0 Then EPos = Len(text)
    ' GW1 is first word(string)
    GW1 = RTrim$(LTrim$(Mid$(text, SPos, EPos - SPos + 1))) 
ENDIF

IF wc>1
SPos=EPos+2      
    EPos = InStr(text, " ",SPos) - 1
    If EPos <= 0 Then EPos = Len(text)
    GW2 = RTrim$(LTrim$(Mid$(text, SPos, EPos - SPos + 1))) 
ENDIF
etc ...
Depends on how many words you have in one line.

[/code]
Galeon
Posts: 563
Joined: Apr 08, 2009 5:30
Location: Philippines
Contact:

Post by Galeon »

Like what I said, interesting...

It's very useful for IDE's, since they don't need compiling the sources, you can easily find the problem, if there is any...

I would like to help, but I don't know I can, or where
Antoni
Posts: 1393
Joined: May 27, 2005 15:40
Location: Barcelona, Spain

Post by Antoni »

Just a suggestion:
Those of you able to write a serious interpreter should join the FB developers team and help improving FB too.
vdecampo
Posts: 2992
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Post by vdecampo »

Antoni

I would love to help the FB developers but unfortunately I am lost on some of the concepts used in the current compiler. My goal in writing an interpreter was to hopefully learn some of these concepts and techniques. After which I would be in a better position to understand whats going on in the compiler.

-Vince

PS: I have already written a lexer which breaks down the source code into literals, numbers, and operators. My next step is to design a VM and work on processing this source.
aurelVZAB
Posts: 666
Joined: Jul 02, 2008 14:55
Contact:

Post by aurelVZAB »

I'm glad that you interested Galeon.
I will present here in few steps how i do that for ABasic.

1. Define buffer string like Dim buffer[32766] as String
2.Open file and fill buffer string with source code
3.Load buffer to richedit control
4.Start script with gosub RUNSCRIPT
5.In sub runscript:
6.Get line count - calc how many lines is in richedit
7.decrease conunt to -1
8.Get first line of code in temp string
9.Parse temp string to words
10.If first word in temp string keyword then execute line.
11.repeat this proces to last line.

Like you see my concept is reading code from richedit control not from
file directrly and maby is not so good ( I think that is slower then reading code from file - i'm not sure?

aurel
Post Reply