KwikBASIC BASIC Interpreter (Updated Link)

User projects written in or related to FreeBASIC.
Post Reply
vdecampo
Posts: 2992
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

KwikBASIC BASIC Interpreter (Updated Link)

Post by vdecampo »

Image
I am currently working on a pet project to build an interpreted version of BASIC. It is coming along nicely, and I am adding features almost daily.

Currently the commands recognized by the interpreter are...

Command Line Switches

KwikBAS.exe sourcefile [-s]ilent [-t]imed [-n]o pause [-d]ebug trace
----------------------------------------------------------------------------
-s | Hides interpreter start/end messsages
-n | No pause when program is finished
-t | Displays execution time
-d | Displays number of line being executed

Supported Commands

Supported Commands v 0.2.10

#! -Shebang directive (Linux Only)
Arrays (x [, y])
Most mathematical operations
Hexadecimal notation (ie: &hAE10)

Const var = [numeric expression]
Dim [Shared] var[(idx1[,idx2])]AS datatype
Dim AS datatype var[(idx1[,idx2])]
var[(idx1[,idx2])] = value
Scope/End Scope

Cls
Colorfore,back
Printexpr
Cons [expr] <- Works like PRINT but always goes to console window

If expr Then / Else | EndIf

Mid / Left / Right
Len(string)
Spc(count)
Space(count)
String(count,char)
Instr(start,string,sub-string)
Chr(ascii_code)
Asc(char_string)

Do {Until|While} / Loop {Until|While} / Exit Do
For/Next | STEP | Exit For
While [expr]/Wend / Exit While

Mid / Left / Right
Len(string)
Spc(count)
Space(count)
String(count,char)
Instr(start,string,sub-string)

Csrlin()
Pos()
Locate row,col,cursorstate
Now()
Date()
Time()


DateSerial(yyyy,mm,dd)
TimeSerial(hh,mm,ss)
Year(date_serial)
Month(date_serial)
Day(date_serial)
Hour(time_serial)
Minute(time_serial)
Second(time_serial)
SetDate date_string
SetTime time_string

Input [prompt][;][,] var
Inkey

Timer
Sleep [ms]

End
Gosub
Return

Cons [expr] <- Works like PRINT but always goes to console window
ScreenRes width,height[,depth][,num_pages][,flags][,refresh]
ScreenSet [work_page][,visible_page]
Pset [dst,](x,y)[,color]
Line [dst,][STEP](x1,y1)-[STEP](x1,y2)[,color][,BF][,style]

Open filename For {INPUT|OUTPUT|APPEND|RANDOM|BINARY} As #file_num [,Len = record_length]
Close #file_num
Print #file_num, var_list [,…]
Write #file_num, var_list [,…]
Input #file_num, var_list [,…]

If you would like to test out the interpreter you can download it here...

Download KwikBASIC
Last edited by vdecampo on Feb 04, 2016 15:25, edited 34 times in total.
wolfman775
Posts: 104
Joined: Apr 30, 2009 15:20
Location: Dumbarton, Scotland

Post by wolfman775 »

Verry nice, I was just wondering how you implemented variables.
angros47
Posts: 2323
Joined: Jun 21, 2005 19:04

Post by angros47 »

Haven't yet tested it, but it seems interesting.... have you used part of code of my or tblank's one? Or it's a new project? If so, can't wait to see the source code.

Good luck!
vdecampo
Posts: 2992
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Post by vdecampo »

wolfman775 wrote:Verry nice, I was just wondering how you implemented variables.
I created a heap object which lets me create named entries with either string or double values and a datatype. Internally all numeric values are double and will be coerced to their final datatype when read. I have not implemented scope yet but it shouldn't be too hard. I plan on just creating a local heap object to track local variables.

-Vince
vdecampo
Posts: 2992
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Post by vdecampo »

angros47 wrote:Haven't yet tested it, but it seems interesting.... have you used part of code of my or tblank's one? Or it's a new project? If so, can't wait to see the source code.

Good luck!
It's a new one based on a lexer project I did a year ago.
I used code from Microsoft Knowledge-Base Article KB86688 for the numeric expression parsing.

-Vince
TheMG
Posts: 376
Joined: Feb 08, 2006 16:58

Post by TheMG »

Is it parsing as it goes along, or does it convert it to some sort of bytecode which it then interprets?
vdecampo
Posts: 2992
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Post by vdecampo »

TheMG wrote:Is it parsing as it goes along, or does it convert it to some sort of bytecode which it then interprets?
I gave that some serious thought, and since this was a learning project for me, I decided to interpret as I go. The entire source is parsed into tokens first, then the tokens are run through the virtual machine.

Perhaps next time I will employ a bytecode scheme.

-Vince
tblanck
Posts: 67
Joined: Jun 15, 2006 15:58

?

Post by tblanck »

vdecampo :

why not working together on the same project ?
I think you're just rewriting something I have already done...
I think it would be more constructive to work together. don't you think ?
vdecampo
Posts: 2992
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Re: ?

Post by vdecampo »

tblanck wrote:vdecampo :

why not working together on the same project ?
I think you're just rewriting something I have already done...
I think it would be more constructive to work together. don't you think ?
I have never seen your source code. This is a project I have wanted to do for a long time and the recent chatter about interpreters spurred me into action. I am not certain our projects have the same goals.

My goals are...

1. To create a virtual machine that interprets a subset of the FreeBASIC syntax.
2. That includes GUI elements from my KwikGUI library
3. To further my understanding of Recursive Descent Parsing (not that this is one)
4. To become the object of womens desire.

...Well maybe not #4... :)

Once I release my source code, you are welcome to participate in KwikBASIC's development.

-Vince
jcfuller
Posts: 325
Joined: Sep 03, 2007 18:40

Post by jcfuller »

Vince,
Why an interpreter as opposed to a translator (bas -> c++).
This would give you experience to help on a full c++ back end for FreeBASIC.

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

Post by vdecampo »

jcfuller wrote:Vince,
Why an interpreter as opposed to a translator (bas -> c++).
This would give you experience to help on a full c++ back end for FreeBASIC.

James
Because I have zero C++ experience. The biggest C++ program I have ever written was a HELLO WORLD test. Another reason is I wanted to experiment which scripting. An interpreter could be used to run apps over the web or create batch files.

Ultimately this is a learning project for me. If it turns out ok, I may work on something more elaborate.

-Vince
Last edited by vdecampo on Aug 14, 2009 2:25, edited 1 time in total.
aurelVZAB
Posts: 666
Joined: Jul 02, 2008 14:55
Contact:

Post by aurelVZAB »

Ahhh what to say...
Exellent and work without bugs.I just joking...
You get the point and like what i see...

Aurel

My small modification of your example (just for test..)

Code: Select all

-----------------------------------------
'     Interpreter Test Source Code
'-----------------------------------------

Dim As String testvar 
Dim Value As Integer

testvar = "Hello" 

Value = 2+4

Value = Value + 1

Print Value

Print testvar, Value+5

Print Int(value*25/7) & " How are you?"

Print "My string = " + value+10 & " Work Exellent,Vince!"

'Cls

'Print "Hello"
vdecampo
Posts: 2992
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Post by vdecampo »

I have updated the download and it now includes the source code.

Here is some documentation.

Command Line Switches

KwikBASIC sourcefile [-s]ilent [-t]imed [-n]o pause
---------------------------------------------------
-s | Hides interpreter start/end messsages
-n | No pause when program is finished
-t | Displays execution time

Supported Commands

Most mathematical operations
Dim var AS datatype 'types not enforced other than string/numeric
Dim AS datatype var
var = value 'String or Numeric
Print expr
Cls
If numeric_expr Then…Else…EndIf
Timer
Chr(ascii_code)
Asc(char_string)

Issues

1. If/Then blocks currently only evaluate numeric expressions.
2. Some errors are not reporting properly.
3. The string expression evaluator is a little buggy.

Enjoy!

-Vince
vdecampo
Posts: 2992
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Post by vdecampo »

ver 0.0.3

I think I got the wigginess worked out of the If/Then implementation

-Updates to the lexer
-Supports single line if/then/...

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

Post by aurelVZAB »

Vince i belive you IF/THEN is always tricky part.
By the way why you have THEN:

IF var=num THEN
'code
ELSE
'code
END IF

Is that for campatibility with FBC?
And just one thing .
I think that is somplier ENDIF instead END IF.
Just a tough...
Post Reply