March 22nd, 2011, 11:57 AM
Develope structure for Procedural Language
I like to write simple games and one-trick pony apps in VB6 for fun. I finally finished (almost all debugged) a chess program (with no AI though). I designed a spreadsheet with 26 cols x 99 rows and quite a few other middling sized apps. Now I want to try my hand at creating an interpreted procedural language that will be quite similar to BASIC/VB itself though not window based, just text output. I have no plans to make a compiler.
I am considering the structure which we all know is wise to do before just jumping in and start coding. My first question is when I read the source code can I assign all procs, funcs and dimmed vars in one pass or is it better to do a double scan so that routines referenced but not yet defined will be assigned on the second pass?
In order to support scope, I plan to have in my program these variables:
with an element in the array to indicate a source variable is in use. So if a sub uses variable J and calls another sub that also uses J, I need both J's to be independent. What I think will work is to prefix the user's variable with the current sub's name and search the appropriate array data type for an empty slot (not in use) and assign it there.
Dim Proc(name$, Value, required vars as type, optional vars as type, n)
Dim Func(name$, Value, optional vars as type, return as type, n)
Dim StringVar(name$, Value, in use, n)
Dim IntegerVar(name$, Value, in use, n)
Dim LongVar(name$, Value, in use, n)
Dim BooleanVar(name$, Value, in use, n)
Dim SingleVar(name$, Value, in use, n)
Dim DoubleVar(name$, Value, in use, n)
I hope to support the 'Static' keyword so that when found in a proc or func I will not unassign the variables but 'let it ride'.
I do not plan to convert to tokens at this time, maybe later. I love straight ASCII.
I do not plan to support graphics.
User arrays I plan to allocate dynamically or can't I. Maybe I will have to have some 'dummy' 1,2,3 element arrays and redim them at runtime using:
along with another internal array that matches the user's array name with the dummy array I am using.
I do not plan to support Date or Time functions/formats other than Date$ and Time$. Usually on larger projects I like to get important features established then fall into 'Creeping featuritus' mode... meaning add more capability later. I know I have bit off quite a lot in this endeavor. I may even be able to make it work Haha.
Thanks for any suggestions on my approach in structuring this program.