- #1
elusiveshame
- 169
- 35
Hey fellow nerds and geeks!
I'm working on a new version of my compiler, mainly to improve performance on the compiler itself as it was my first attempt at such a program. Since I've learned a ton on compiler design (probably not the best of methods, but hey, it works, right?), I've built a new tokenizer and am now in the works of porting over the routines.
My question comes is what is the best way to handle arrays?
I'm currently using an old version of Visual Basic (VB6) for reference, and the compiler I'm making is also a BASIC dialect aimed for a specific processor.
So what do I mean about handling arrays? What I mean is what is the best way to store information about a declared array (name, # of indices, and size of indices).
What I did in my previous compiler was to take the syntax of, say:
The compiler would store that into a string, like:
If I needed to validate the array (ensure boundaries, for instance), I'd just parse the string (explode it into an array and loop until I found a match of __array_arrayName). This, as you can imagine with large projects, can be slow. I could probably save time by using Instr() to find a match and then search for the next pipe by using the returned value of the Instr() function.
Anyway, any suggestions on the best method?
I'm working on a new version of my compiler, mainly to improve performance on the compiler itself as it was my first attempt at such a program. Since I've learned a ton on compiler design (probably not the best of methods, but hey, it works, right?), I've built a new tokenizer and am now in the works of porting over the routines.
My question comes is what is the best way to handle arrays?
I'm currently using an old version of Visual Basic (VB6) for reference, and the compiler I'm making is also a BASIC dialect aimed for a specific processor.
So what do I mean about handling arrays? What I mean is what is the best way to store information about a declared array (name, # of indices, and size of indices).
What I did in my previous compiler was to take the syntax of, say:
ASP.net:
Dim MyArray(2,4,6) As Integer
The compiler would store that into a string, like:
ASP.net:
arraylist$ = arraylist$ & "__array_MyArray_2_4_6|__array_AnotherArray...etc"
If I needed to validate the array (ensure boundaries, for instance), I'd just parse the string (explode it into an array and loop until I found a match of __array_arrayName). This, as you can imagine with large projects, can be slow. I could probably save time by using Instr() to find a match and then search for the next pipe by using the returned value of the Instr() function.
Anyway, any suggestions on the best method?