ideas for a BASIC compiler

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:

formatting link

this is the generated assembler code:

formatting link

and this is the compiler:

formatting link

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? 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.

--
Frank Buss, fb@frank-buss.de
http://www.frank-buss.de, http://www.it4-systems.de
Reply to
Frank Buss
Loading thread data ...

Well if you *must* use basic :) why not steal a common extension used by some C compilers and use @ to place a vatiable at a specific address? Something like

DIM TMR0 as Integer @42

Maybe add a prefix to the address if you need to separate address spaces.

Robert

** Posted from
formatting link
**
Reply to
Robert Adsett

Lovely. Pick a language that in it's 'standard' form is too much of a piece of shit to do anything useful. Pick a language that has to be extended to the point of being incompatible with the other thousand varients calling themselves basic. Where can I sign up? I really want a language that won't permit me to reuse any of of my code and which won't work with any previously developed libraries.

At least pascal has data structures. By the time you make your BASIC useable, it won't be BASIC any more.

Read a book on yacc. It'll let you build compilers for just any architecture and in any grammar.

Reply to
AZ Nomad

Welcome to 1974! We hope you enjoy your stay.

Reply to
Clifford Heath

Usually I'm using C, but I think this would be too difficult for the beginner.

Thanks, this looks like a good idea.

--
Frank Buss, fb@frank-buss.de
http://www.frank-buss.de, http://www.it4-systems.de
Reply to
Frank Buss

Usually you don't need previously developed libraries for small embedded systems and products like this:

formatting link
formatting link
formatting link

demonstrates that there is some use for BASIC on embedded systems. Which language would you recommend, which is easy to use for beginners (so no C) and can be compiled to small PICs?

--
Frank Buss, fb@frank-buss.de
http://www.frank-buss.de, http://www.it4-systems.de
Reply to
Frank Buss

Is the embedded application going to be in a playskool busibox? Is that the target audience?

Anybody who can figure out how to incorporate an embedded processor can figure out how to use a real programming language or find somebody who can.

Reply to
AZ Nomad

Pascal, to ISO 7185. Complete, properly designed, with a proper standard.

--
 [mail]: Chuck F (cbfalconer at maineline dot net) 
 [page]: 
            Try the download section.


** Posted from http://www.teranews.com **
Reply to
CBFalconer

If you are gettng that close to C, you are going to confuse beginners. clearer is more Pascal like : foo = ADDRESS(TMR0)

Without those, it will be very limited.

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

Reply to
Jim Granville

Yes, it should be as simple as possible to be used by everybody. There were some experiments with using programming languages even in kindergartens, e.g.

formatting link
I don't know if this makes sense, but maybe starting with the age of 10, I think it would be too difficult to use C.

Or maybe even a visual environment, like LabView or RCX code:

formatting link

But this would be difficult to compile for small PICs.

--
Frank Buss, fb@frank-buss.de
http://www.frank-buss.de, http://www.it4-systems.de
Reply to
Frank Buss

In message , Frank Buss writes

I would recommend C for beginners.

Otherwise they have to learn your BASIC then forget everything they have learned and learn c, C++, Ada or Pascal (?) and "real" tools as the next step.

I cant see the point in learning something that is in a completely different direction to everything else and will have to be unlearned to progress. The problem is not al of it will be unlearned so it wil make matters worse long term.

Rather than write your own version of BASIC use a cut down version of C..... Do a compiler that only does MISRA-C for example.

--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills  Staffs  England     /\/\/\/\/
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
Reply to
Chris H

A quick scan on Sourceforge found this

formatting link

" Great Cow BASIC is an open-source BASIC compiler for Microchip PIC

10/12/16/18 series microcontrollers."

So, why not align yourself with these efforts, and add the apparently missing Debug support, for example ?

and also this : FreeBASIC Compiler

formatting link

Open-source, free, multi-platform BASIC compiler, with the syntax the most compatible possible with MS-QuickBASIC (incl. the GFX statements), but that adds new features such as pointers, unsigned data types, inline-asm, a pre-processor and many others.

This seems to be a reasonably serious PC compiler, so trawl that for ideas.

A pre-processor is a VERY good idea, as they allow block comments, and feature-version control.

-jg

Reply to
Jim Granville

No, there's plenty of hardware engineers that can't program in HLL. I can do excellent assembler in AVR/51, but could never get to grips with c/pascal etc, but BASIC no problem.... just.

Reply to
TT_Man

There is a language called NQC (Not Quite C) for the Lego Brainstorms sets, which might also be worth looking into.

--
Pertti
Reply to
Pertti Kellomäki

Oh, really? You never have to interface to any other devices? You write all your interface code?

Reply to
AZ Nomad

Why go for a compiler. The advantage of BASIC has been the trial'n error learning with an interpreter.

Said this, there is e.g. tiny-BASIC.

--
42Bastian
Do not email to bastian42@yahoo.com, it's a spam-only account :-)
Use @monlynx.de instead !
Reply to
42Bastian Schick
2008 06:23:31 +0200, Frank Buss wrote:

IOW plenty of hardware engineers who are not also software engineers. Software engineering is a different disipline. Embedded software engineering even more specialized. Didn't dykstra say something like BASIC will ruin your mind for programming?

Ed

Reply to
Ed Prochak

Have both...... play with the interpreter, run with the compiler. :)

Reply to
TT_Man

That's the problem I have with Visual Basic. I can never decide if I'm still 10 years old and wiriting in basic, or all grown up and writing in C. Both mindsets sort of work, but neither one really fits that language. So I have these terrible mixes of old basic manipulations next to examples of VB doing a bad job of pretending to be C.

Reply to
cs_posting

There is no reason why an interpreter (interactive) should not compile performant code. The restriction for an embedded system is in Flash and RAM resources to contain the optimising compiler. Many Forth systems use a tethered approach. The PC is used for the interactivity; the embedded system only contains the required runtime and a tiny message-passing monitor.

Current single-chip ARMs have enough resources to contain our VFX code generator, but I wouldn't want to do this on a small PIC.

Stephen

--
Stephen Pelc, stephenXXX@mpeforth.com
MicroProcessor Engineering Ltd - More Real, Less Time
133 Hill Lane, Southampton SO15 5AF, England
tel: +44 (0)23 8063 1441, fax: +44 (0)23 8033 9691
web: http://www.mpeforth.com - free VFX Forth downloads
Reply to
Stephen Pelc

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.