Hello,
I'm looking for a Basic interpreter which can run on the Arduino. I've seen many such as TinyBasic, but the problem I always had is that they are not very generic. They can be easily compiled to the Arduino, but I was rather looking for a 'library' where you could you know... Pass the code as string and the library executes it? I don't necessarily need the shell that many interpreters provide. I can do this myself. But in order to be able to implement other things, some structured code is needed.
I hope you know what I mean. Does anyone know a good interpreter language (not necessarily Basic), which can be easily included?
Thanks.
I've got to ask - Why?
Is there a good Basic interpreter?
No.
I've got to ask - Why?
I want to build a computer like the C64 including screen and keyboard. I want it to be completely programmable. Therefore I need a scripting language.
What's good is highly subjective.
They can be easily compiled to the Arduino, but I was rather looking for a 'library' where you could you know..
How hard would it be for you to stripe out the "shell"?
I guess it shouldn't be so hard. But as these sources evolve, I would have to change the code over and over again in order to make the new version fit.
Bitlash might be a good fit for your application: http://bitlash.net
Bitlash is an iterpreter for a tiny language that runs entirely on the Arduino. It's easy to integrate into your Arduino application, and to extend the interpreter with functions you write in C and in the Bitlash language.
-br
I've seen bitlash before and to be honest, I don't like it. It has a weird syntax and only allows variables 27 from a-z.
De gustibus non disputandum est.
Good luck with your project. :)
-br
I've seen bitlash before and to be honest, I don't like it. It has a weird syntax and only allows variables 27 from a-z.
You know, a reality check would be a good thing. Which Arduino are you using? Look at how much SRAM it has. The "code" to be interpreted has to fit in that space. Along with the interpreters variables.
Currently, I'm using the Mega 2560. But I already ordered a Due.
But as these sources evolve,
Life isn't supposed to be perfect.
I've seen bitlash before and to be honest, I don't like it. It has a weird syntax and only allows variables 27 from a-z.
27 variables from a-z. Clever !
Got another idea: What about an assembly compiler on the Arduino? Pass ASM code as string and get binary code as return and then execute it by setting the instruction pointer? Is that somehow possible or does it sound ridiculous?
Is that somehow possible or does it sound ridiculous?
Yes on both counts.
Okay... But how can I execute a set of instructions, and how can I compile assembly code into binary code?
how can I compile assembly code into binary code?
The gcc compiler is really good at that.
That still leaves the question on how to execute a set of binary code on the Arduino. I think you need to add the instruction pointer on the stack, then excecute the binary code and at the end of that code pop esi and jump to it, right? Though I haven't found any examples yet...
Also, is it possible to compile asm on the Arduino?
Hmmm
"...lightweight interpreter..." , "... sources evolving...", "... life perfecting ..."
Of course!
....+++---> brainf*ck
http://hackaday.com/2013/01/29/genetic-algorithms-become-programmers-themselves/ (http://hackaday.com/2013/01/29/genetic-algorithms-become-programmers-themselves/)
Oh. And this guy has already written the interpreter for atmega:
http://www.omnimaga.org/index.php?topic=15152.0 (http://www.omnimaga.org/index.php?topic=15152.0)
Cheers,
John
That still leaves the question on how to execute a set of binary code on the Arduino.
The bootloader allows you to do that.
I know, but I meant from within running code, like this:
void setup()
{
char *binary = .....
push esi
execute(binary);
pop esi
}
Forth might be a good option:
http://arduino.cc/forum/index.php/topic,8838.0.html
Got another idea: What about an assembly compiler on the Arduino? Pass ASM code as string and get binary code as return and then execute it by setting the instruction pointer? Is that somehow possible or does it sound ridiculous?
Not possible. On these processors (Harvard architecture) you can't execute code from RAM.
http://en.wikipedia.org/wiki/Harvard_architecture
Got another idea: What about an assembly compiler on the Arduino? ....
Do you mean ON the Arduino or FOR the Arduino?
I meant on the Arduino from memory. Well, as Nick stated, it is not possible. I think I'm best off by writing my own Basic interpreter. It shouldn't be so hard, I've written one a couple of years ago. When something useful comes around, I'll share it :)
Again, thank you all for help. I will also take a closer look at bitlash and some of the posted links.
Here is one:
#include <stdio.h>
#define Q r=R[*p++-'0'];while(
#define B ;break;case
char*s="Qjou!s\\311^-g\\311^-n\\311^-c\\::^-q-ma%mO1JBHm%BQ-aP1J[O1HB%[Q<nbj\
o)*|gps)<<*txjudi)m*|aQdbtf!::::;sfuvso<aQefgbvmu;aQ<m,,a%CQ<csfbla%bQ<aN2!Q\
\ndbtf!aP2Q;m>aP2Q<a%!D12J!JGJHJOJQJFJSJJJMHS%HD12D12N3!N4\nJUJT%UQm>aP4HC%T\
Qs\\q,,^>m,2<m>aP4HC%SD12N1\nJNQm>s\\..q^aHC%NHb%GN1!D32P3%RN1UP1D12JPQUaP1H\
R%PN4\nQ<g\\(aP3Q(^>aP2Q,2<n\\(aP3Q(^>aP4Hb%OD12D12N2!N3\nJVP3Q,,<jg)aP3Q=>n\
\\(aP3Q(^*m>g\\(aP3Q(^<fmtf!m,,aHC%QN1!N1\nJ#Qqsjoug)#&e]o#-aP1Q*aHb%#Qqvut)\
aP1Q*aHb%FN1\nQm>::::aHC%VP3Q>bupj)hfut)c**aHb%JD12JON1!Qjg)a%LN1UP1D12JIQUa\
P1HL%IQ*m>aN2!N2\nP2Q<fmtf!m,,aHC%MN1!N2>P2Q>aN2\nP2Hbdd!b/d";k;char R[4][99]
;main(c,v)char**v;{char*p,*r,*q;for(q=s;*q;q++)*q>' '&&(*q)--;{FILE*i=fopen(v
[1],"r"),*o=fopen(q-3,"w");for(p=s;;p++)switch(*p++){B'M':Q(k=fgetc(i))!=EOF
&&k!=*p)*r++=k;if(k==EOF){fputs("}}\n",o);fclose(o);return system(q-6);}*r=0
B'P':while(*p!='`')fputc(*p++,o)B'O':Q*r)fputc(*r++,o);p--B'C':k=0;Q k<*p-'0'
)(*r++=fgetc(i),k++);*r=0 B'I':k= *p;if(**R==k)goto G B'G':k= *p;G:p=s;while(
*p!='$'||p[1]!= k)p++;p++B'N':R[*p-'0'][0]++;}}}
8^)
I used to code in Visual Basic 6 for a living... hopefully never again. I've slowly evolved to languages that actually work and make sense.
It shouldn't be so hard
Nothing is difficult, until you start doing it.
Here is one:
#include <stdio.h>
#define Q r=R[*p++-'0'];while(
#define B ;break;case
char*s="Qjou!s\\311^-g\\311^-n\\311^-c\\::^-q-ma%mO1JBHm%BQ-aP1J[O1HB%[Q<nbj\
o)*|gps)<<*txjudi)m*|aQdbtf!::::;sfuvso<aQefgbvmu;aQ<m,,a%CQ<csfbla%bQ<aN2!Q\
\ndbtf!aP2Q;m>aP2Q<a%!D12J!JGJHJOJQJFJSJJJMHS%HD12D12N3!N4\nJUJT%UQm>aP4HC%T\
Qs\\q,,^>m,2<m>aP4HC%SD12N1\nJNQm>s\\..q^aHC%NHb%GN1!D32P3%RN1UP1D12JPQUaP1H\
R%PN4\nQ<g\\(aP3Q(^>aP2Q,2<n\\(aP3Q(^>aP4Hb%OD12D12N2!N3\nJVP3Q,,<jg)aP3Q=>n\
\\(aP3Q(^*m>g\\(aP3Q(^<fmtf!m,,aHC%QN1!N1\nJ#Qqsjoug)#&e]o#-aP1Q*aHb%#Qqvut)\
aP1Q*aHb%FN1\nQm>::::aHC%VP3Q>bupj)hfut)c**aHb%JD12JON1!Qjg)a%LN1UP1D12JIQUa\
P1HL%IQ*m>aN2!N2\nP2Q<fmtf!m,,aHC%MN1!N2>P2Q>aN2\nP2Hbdd!b/d";k;char R[4][99]
;main(c,v)char**v;{char*p,*r,*q;for(q=s;*q;q++)*q>' '&&(*q)--;{FILE*i=fopen(v
[1],"r"),*o=fopen(q-3,"w");for(p=s;;p++)switch(*p++){B'M':Q(k=fgetc(i))!=EOF
&&k!=*p)*r++=k;if(k==EOF){fputs("}}\n",o);fclose(o);return system(q-6);}*r=0
B'P':while(*p!='`')fputc(*p++,o)B'O':Q*r)fputc(*r++,o);p--B'C':k=0;Q k<*p-'0'
)(*r++=fgetc(i),k++);*r=0 B'I':k= *p;if(**R==k)goto G B'G':k= *p;G:p=s;while(
*p!='$'||p[1]!= k)p++;p++B'N':R[*p-'0'][0]++;}}}
8^)
CODE TAGS!!!!
Nothing is difficult, until you start doing it.
The mind boggles. Truly.
A maybe 10 second search got this:
http://amigojapan.github.com/Arduino-Retro-Computer-with-SD-card-and-LCD-display-and-Keyboard-input-with-BASIC-interpreter/
and this:
http://hackaday.com/2012/05/01/arduino-basic-interpreter-using-lcd-keyboard-and-sd/
and this:
http://ec2-122-248-210-243.ap-southeast-1.compute.amazonaws.com/mediawiki/index.php/Arduino_Basic
and a few more before results from this forum made the list. Your mileage may vary.
Interpreter Basic is a ancient and cruel form of torture supported by masochists and the ingnorant.
Interpreter Basic is a ancient and cruel form of torture supported by masochists and the ingnorant.
Mostly the latter.
Pass the code as string and the library executes it? I don't necessarily need the shell that many interpreters provide
BASIC is sorta all about the shell...
As for the provided code, it didn't work! And it's obvious that that is not actually a basic interpreter, but only a "compiler" that translates BASIC code into C code! And it needs more comments!
( http://forum.basicprogramming.org/index.php?topic=1824.0;wap2 Follow the links...)
Interpreter Basic is a ancient and cruel form of torture supported by masochists and the ingnorant.
Mostly the latter.
And I actually heard that they encourage the use of GOTO statements. ;)
Yup. When your business package crashes you maybe load a variable or two and type GOTO some-line-number to keep running. Ain't life good?
Interpreter Basic is a ancient and cruel form of torture supported by masochists and the ingnorant.
A joke I'm sure, but don't be so dismissive. A tiny number of us were assembling back in the day, an increasing number of people who had to have abstraction used proto C (You talk about torture - they loved error reports), but there was a mass of people who were introduced to microprocessors via Basic (go find the philosophy behind it's development), Fortran, Pascal (later) forth etc. ALL of those pioneers provide the shoulders that we now stand on. The C used in Arduino is stripped down and has to be the easiest implementation I have ever come across and yet it still throws errors from artefacts, at least Basic has the good manners to point out the error and only the error ;) And what exactly is wrong with a goto? It just provides a method for stepping over code, structures like 'case' do the goto's for you. In fact, if you read the reference, you'll find a goto. Anyone can write sloppy code in any language. If you want to be dogmatic and write tight code, pick up the data sheet and start assembling.
The advocates of all languages look down their noses at the other language users, however, if you see someone smiling quietly to himself, trying not to look too aloof, he'll be the assembler in the room ;)
For a real insight, writing languages (and even small OS's) is fun, everyone should try it.
if you see someone smiling quietly to himself, trying not to look too aloof, he'll be the assembler in the room
No, he'll be the real engineer, who has tweaked the microcode 8)
he'll be the assembler in the room
I thought for a moment you said "elephant in the room". ;P
People paid me to write Basic on and off from 1980 to 1999 (last Y2K maintenance). I would BEG them to let it be C or Forth and they'd insist that if it was Basic then it would be more maintainable. Well at least by 85 it was compiled Basic.
Interpreter Basic is missing so much it is cruelty to work with. Compiler Basic is less so in proportion to how much it is C/C++ in disguise. I speak from a lot of experience!
Every time I'd get into assembler it seemed like no time before the new chips were out. I did some segments for pay and more for learning but as compilers got really good I said to hell with it. I wasn't making my living keeping with the latest. If anyone is then I'm happy for you, good on yer!
Basic was like a bad habit with no redeeming qualities that I couldn't find in a better, more capable language.
what exactly is wrong with a goto?
It doesn't provide inferior people the ability to feel otherwise.
What is wrong with GOTO? Nothing in particular if you can keep your program from turning into spaghetti.
OTOH spend time fixing other people's goto-ridden spaghetti code and you might get an idea about goto's.
Basic goto's get over-used by beginners who haven't figured out what gosub is for. But mind you they are superior beginners who already have a way and don't need to rely on gosub tricks.
... It has a weird syntax and only allows variables 27 from a-z.
I want to say that early BASIC was the same. Well, maybe 26 variables. Am I remembering correctly?
A1, A2, A%, A$, A... at least by the mid-70's, probably sooner.
From the Wikipedia article on Dartmouth Basic at http://en.wikipedia.org/wiki/Dartmouth_BASIC
Variable names were limited to A to Z, A0 to A9, B0 to B9, ..., Z0 to Z9, giving a maximum of 286 possible distinct variables. Array names were restricted to A to Z only
I have found that Bitlash users tend to run out of eeprom before they run out of variable names. And at least they can give their _functions_ proper names so they are steered toward that habit.
While I have the podium may I point out that the syntax of the Bitlash language is much less weird / more compatible with C and Javascript in the 2.0 version and if you haven't given it a look in a while it might be worth dusting off. Here's the User's Guide: http://bitlash.net/bitlash-users-guide.pdf
-br
It doesn't provide inferior people the ability to feel otherwise.
Check out this thread: http://arduino.cc/forum/index.php/topic,146205
You may be able to advise the poster about the best way of using goto.
Disclaimer: I don't really understand what "It doesn't provide inferior people the ability to feel otherwise." means. Maybe someone else does?
No.. Nick The God *dhenry* has spoken it isn't for us mere mortals to understand the words or meaning, If as you say, there ever was one...
Bob
You can take away my GOTO when you can pry it out of my cold dead fingers.
It's my right! Anyone who doesn't like it can take an unconditional jump!
It's my right!
So is shooting yourself in the foot. Not recommended, though.
Next thing, they'll want background checks!
Anyone who doesn't like it can take an unconditional jump!
Whoa, whoa. That's like a GOTO isn't it?
Suggest amendment:
if (YouDontLikeIt)
exit (1);
You can take away my GOTO when you can pry it out of my cold dead fingers.
Your proposal is acceptable.
Well there does come a time in all Basic code where you just have to say NOP to GOTO's.
No, no, no! No new GOTO's!
In fact, make GOTO cuts! Cut-cut-cut!
Sign the NOR-logic pledge and join the NOP party today!
And yeah, I'm playing at something extreme here. can ya guess what?
Smoke!
Bob
*fetches beer*
*pulls us a chair*
*throws a few GOTOs into the melee, sits back and watches the show"
]:D ]:D ]:D
I've encountered a few variations of Basic starting from mid 80's. All of them felt somehow broken and I've had to learn to work around the most serious issues.
Most recently I worked with VB6. In VB6 there is no way of resizing a dynamic array back to zero elements other than dedicating a separate unassigned array type for that purpose. If you did ReDim a(0), you'd get an array with a single element, not an empty one. Of course, ReDimming to -1 does not work either.
You can't really test does an array have zero elements either because there are only functions for finding the first and last index in the array. So, you need to write a function of your own with exception handling that would catch the case where the array has not been added any values to. That way, it'll return 0.
Localization has always provided plenty of error cases. For some reason, if you take code from one system to another, it fails, because in the other system, the decimal separator is different. String to double conversion throws an exception, funny that. At least in DotNet, you could at least make the conversions culture invariant.
It kinda supports object oriented programming, but you need to have each class in a separate file and they come with some limitations.
And I still have not found a way to "continue" a loop, so in that case, I'm forced to use a GOTO in order to skip the rest of the loop and continue with the next iteration.
For scripting, it's almost usable, and easy to debug, but I can't imagine myself writing an application in Basic. Then there are plenty of other options for scripting that easier to work with in my opinion. I haven't really been coding in any form of Basic for almost 2 years, good riddance.
good riddance.
No language (or any tool, for that matter) can do everything effectively and efficiently to everyone's satisfaction - that's why we have so many different langues / tools.
Judging a language's "inferiority" on its inability to perform a task is futile.
What's faster to cut logs with?
A flint ax?
A hatchet?
A bow saw?
A buzzsaw?
Would there be a task that I'd rather use a flint ax for that none of the others isn't better for?
Be a museum piece?
No language (or any tool, for that matter) can do everything effectively and efficiently to everyone's satisfaction - that's why we have so many different langues / tools.
Judging a language's "inferiority" on its inability to perform a task is futile.
That was meant as a personal remark as in I'm happy not to be coding in this language any more. You are right, most modern languages have their place even if they had some peculiar perks that look weird if you moved from another language. One has to learn to pick the right tool for the task at hand. It's just that we didn't have much of choice in the product back then, so I grew frustrated when I learned the tool wasn't really fitting the tasks and as a result I got bugs to fix.
VB String class apparently handles character data in 64K blocks and this can result in exponential growth in execution time if you go over the bound. You can work around this too but for handling of very large text files, VB is not good at all.
Another thing that can bother a C coder. Basic interpreter evaluates all the conditions in a clause while C quits evaluating if the following conditions couldn't change the result.
I still think the language, at least VB6, is more or less broken, call that a judgement or not. However, Microsoft has later added operators like OrElse and AndAlso into later VB versions to cover the conditional operator topic. I'm sure VB as language has progressed in other topics too. I'm not this familiar with non-VB Basic interpreters.
What's better for understanding the development of humans?
A flint ax?
A hatchet?
A bow saw?
A buzzsaw?
Would there be a task that I'd rather use a buzzsaw for that none of the others would be better for?
Making a chainsaw massacre movie. All arguments can be inverted.
No language (or any tool, for that matter) can do everything effectively and efficiently to everyone's satisfaction - that's why we have so many different langues / tools.
Indeed, and how many offerings of C do we have?
No language is written to create bad code! The goto was put there for good reason, and that was not to provide a method for making spaghetti. Just as it was in C!
Our understanding of what is considered to be good code has developed over time.
IMO it isn't the job of a language to impose structure, the language should be open and flexible. Maybe that is why I like assembler so much, the quality of the finished code is purely down to me. It's more than writing code, it's competition, a game, a challenge that I enjoy.
And as I said below, anyone can write "bad" or sloppy code, even, yes even on the Arduino, just take a look though these annals.
One has to separate the vagrancies of the workman from his tools before casting judgement from on high.
One has to separate the vagrancies of the workman from his tools before casting judgement from on high.
Right on. As they say, only incompetent carpenters blame their tools.
One has to separate the vagrancies of the workman from his tools before casting judgement from on high.
Right on. As they say, only incompetent carpenters blame their tools.
Quite right. Competent carpenters choose the best tool for the job. Which I expect you'd find is why Basic is so rarely used for professional software development these days.
One has to separate the vagrancies of the workman from his tools before casting judgement from on high.
Right on. As they say, only incompetent carpenters blame their tools.
Quite right. Competent carpenters choose the best tool for the job. Which I expect you'd find is why Basic is so rarely used for professional software development these days.
Next thing you know we'll be telling people they should cook their food. Ugg.