I've started a BASIC compiler, first for PICs, but later I plan to use this for ARM platforms, too. This is an example source code:
this is the generated assembler code:
and this is the compiler:
A lot of things are missing, like a full expression evaluator and a some more BASIC keywords, like if-endif, but at least it works.
It is inspired by BASIC stamp and PIC Basic, but I'm not sure about how to handle register access (or memory access on ARM). PEEK and POKE looks too cumbersome to write each time I need it, because in embedded systems it is needed a lot. My idea is to use some default rules: If you write
timerValue = TMR0
this means, the register TMR0 is read and the result is saved in the register timerValue. But if you write:
foo = 42
this means, the value 42 is saved to register foo. So in general, if you use symbols, the values of the symbols are read or written, but if you use numbers, the numbers themselfs are used. I think this is the most common usage.
If you really want to read the register 42, I think a C-like syntax would be good:
foo = *42
Same if you want to get the register address, instead of the register value:
foo = &TMR0
You can write the full form every time you want. This is the same:
timerValue = TMR0
*timerValue = *TMR0Do you think this is easy to understand for programmer beginners? Should I implement arrays, structs and strings, too? The goal is that it can be used by beginners without problems, but it should be powerful enough to use all features of the platform where it runs.
Another question is how to use functions. On a PIC there is no data stack, so parameter passing has to be done with implicit defined variables, which makes the compiler more complex. And I'm not sure, if it makes sense for small PICs like the 12F508, which has a call stack of 2 levels, only.
But on ARM CPUs the BASIC programs could become really large, so structured programming with functions would be nice. Do you think it is better to develop two different BASIC implementations, a small one for small PICs and a large one, with functions, arrays, interrupts, mutithreading etc., for bigger PICs and other bigger CPUs? This would make it more difficult to share source code between the systems, e.g. a general program for a sigma delta converter.