Pro's:
* PureBasic has no dependency's.
* It compiles to native executables and does not need any dll's.
* It's very fast.
* It supports 64 bit.
* Has some handy functionality build in.
As many basic programmers i came from VB6 and discovered PureBasic.
The main difference tho, is that PureBasic has it's limits compared to VB..
Cons:
* no variant types possible.
* functions can only return basic types like numbers or strings.
* no support for OOP.
* lists can only be nested with dirty looking hacks that involve pointers and allocating memory.
* ActiveX COM is 'somewhat supported' if you know what you're doing.
The main goal of this project is to build a VBScript like interpreter that works with script files,
the status of this project:
- My interpreter has to read a file (given as a parameter) -> DONE!
- My interpreter has to tokenize the contents of that file -> DONE!
- My interpreter has to check for lexical errors -> DONE!
- My interpreter has to handle variants -> WORKAROUND = use a structure that holds every type like this:
Code: Select all
structure token
type.i ; if the type would change then i have to empty and fill one of those guys here:
number.d
string.s
endstructure
- My interpreter has to convert it's input to an abstract syntax tree -> PROBLEM
In VB i would create classes for every action and nest those classes in a tree, here is a peace of code from VB to show what i mean:
Using the GoldParser back in the days: http://goldparser.org
Code: Select all
Public Function CreateSimpleIfStm(IfClause As Object, ThenClause As Object, Optional ElseClause As Object = Nothing) As SimpleIfStm
Dim Obj As New SimpleIfStm
Set Obj.IfClause = IfClause
Set Obj.ThenClause = ThenClause
Set Obj.ElseClause = ElseClause
Set CreateSimpleIfStm = Obj
End Function
Public Function CreateSimpleWhileStm(WhileClause As Object, DoClause As Object) As SimpleWhileStm
Dim Obj As New SimpleWhileStm
Set Obj.WhileClause = WhileClause
Set Obj.DoClause = DoClause
Set CreateSimpleWhileStm = Obj
End Function
Public Function CreateSimpleStmList(CurrentStm As Object, Optional NextStm As Object = Nothing) As SimpleStmList
Dim Obj As New SimpleStmList
Set Obj.CurrentStm = CurrentStm
' currentstm is nothing
If Not NextStm Is Nothing Then
Set Obj.NextStm = NextStm
End If
Set CreateSimpleStmList = Obj
End Function
Okay i can deal with that, what about instead of objects i use arrays or lists and nest them so i can traverse the tree later?
also not possible! Heck it's not even possible to nest lists with different types or add different types to lists..
What about function blocks? Filling nested arrays in our script language and store them?
So yeah... now I'm stuck and i have no idea how anyone else would solve this problem.
I know there are a few guys on this forum that are interested in making interpreters or programming languages (or already did that).
Can anyone with experience show me the way / share some example code?
regards, TheAutomator.