Re: ideas for a BASIC compiler
- From: Jim Granville <no.spam@xxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 02 Jun 2008 16:48:49 +1200
Frank Buss wrote:
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:
http://www.frank-buss.de/tmp/test.bas.txt
this is the generated assembler code:
http://www.frank-buss.de/tmp/main.asm.txt
and this is the compiler:
http://www.frank-buss.de/tmp/compiler.lisp.txt
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 = *TMR0
Do you think this is easy to understand for programmer beginners?
If you are gettng that close to C, you are going to confuse beginners.
clearer is more Pascal like :
foo = ADDRESS(TMR0)
Should I implement arrays, structs and strings, too?
Without those, it will be very limited.
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.
That's a big jump, from a vanilla PIC, to ARM.
You need to think about Debug, and simulation, and if possible, allow
syntax that allows a PC version of the compiler to compile code (possible with different header files) - OR make it work really well
with a vendors low cost ICE, so simullation uses silicon.
What are the PIC In_circuit_debug solution priced at ?
-jg
.
- References:
- ideas for a BASIC compiler
- From: Frank Buss
- ideas for a BASIC compiler
- Prev by Date: Re: ideas for a BASIC compiler
- Next by Date: Re: Stack Overflow Detection
- Previous by thread: Re: ideas for a BASIC compiler
- Next by thread: Re: ideas for a BASIC compiler
- Index(es):
Relevant Pages
|
|