Herbert Schildt's Little C
jazzed
Posts: 11,803
Herbert Schildt is one of many authors I read in my early programming years. He wrote one of the first basic interpreters I played with. His interpreter uses the recursive descent parsing methodology similar to that used in femto basic.
Recently I found an old book that has Herb's Little C interpreter in it. The code is on line here. Little C is really Herb's basic interpreter with C language additions. Note that there are many limits to the Little C language. The "test.c" program really defines what Little C is capable of doing. The Little C interpreter is described here beginning on pdf page 742.
After a bit of fooling around, I've managed to get a version of Herb's interpreter to run on Propeller from HUB memory. I've attached a binary that you can load using propeller-tool or this loader (shown in the picture) on windows.
You can enter the test.c example Herb's code .zip file by copy/paste into the SimpleIDE Simple Terminal window. SimpleIDE throttles input so that programs are not overwhelmed by copy/paste. If you want to use another terminal like Parallax Serial Terminal, you will have to type it all in a character at a time.
If there is any interest I will post "diffs" between what is in Herb's program and the source I'm using. Herb's books are published by McGraw Hill, and attempts to get responses from the publisher about posting sources have gone un-answered for months. I'll not be posting any derivative source works without permission even with the educational fair use exception in mind.
See this post for updated user info. http://forums.parallax.com/showthread.php/149407-Herbert-Schildt-s-Little-C?p=1198941&viewfull=1#post1198941
Recently I found an old book that has Herb's Little C interpreter in it. The code is on line here. Little C is really Herb's basic interpreter with C language additions. Note that there are many limits to the Little C language. The "test.c" program really defines what Little C is capable of doing. The Little C interpreter is described here beginning on pdf page 742.
After a bit of fooling around, I've managed to get a version of Herb's interpreter to run on Propeller from HUB memory. I've attached a binary that you can load using propeller-tool or this loader (shown in the picture) on windows.
You can enter the test.c example Herb's code .zip file by copy/paste into the SimpleIDE Simple Terminal window. SimpleIDE throttles input so that programs are not overwhelmed by copy/paste. If you want to use another terminal like Parallax Serial Terminal, you will have to type it all in a character at a time.
If there is any interest I will post "diffs" between what is in Herb's program and the source I'm using. Herb's books are published by McGraw Hill, and attempts to get responses from the publisher about posting sources have gone un-answered for months. I'll not be posting any derivative source works without permission even with the educational fair use exception in mind.
See this post for updated user info. http://forums.parallax.com/showthread.php/149407-Herbert-Schildt-s-Little-C?p=1198941&viewfull=1#post1198941
Comments
I'd like to second Martin's question...
operators: &|^~
hex numbers: 0x
getina();
setdira();
setouta();
printhex();
Program grew by about 1KB. May add generic COG register set and get functions later.
I'm trying to get LittleC to run on Spinix ... it runs, but user code must be entered by hand.
Any chance I could convince you to post a .binary which uses P12,P13 for TX/RX?
Jeff
Diffs would be interesting.
Any idea how large of a program can run in this interpreter? For example, do you think there would be space enough for a complex application...something along the lines of a home automation system?
I'll post an update to spinix that fixes those problems. I'll also include the source for the filetest program in the update so you can see how it gets the SD pin definitions to mount the SD card. This would allow you to type something like "littlec file.c" under spinix, and then LittleC could open file.c and compile it.
EDIT: BTW, spinix only works with LMM programs. I still haven't figured out why CMM programs don't work.
LittleC programs are source interpreted comments and all (not compiled, not byte-code interpreted, etc...), and the buffers are in HUB RAM. Performance is horrible because of that, but the advantage is that the interpreter is small enough to fit in HUB RAM.
I'm not sure if it's possible to add any file-system support to LittleC. Maybe there is a really small read-only solution out there .... I suppose just reading the program from SD card as required instead of keeping the code in memory is a possibility, but that's a lot of work and without a disk cache would mean even worse performance. Serial IO for entering programs seems like the only viable LittleC option at this point.
TinkersALot,
LittleC is really just a programmer's toy. At the moment a single source program can be up to 10K bytes.
I haven't even the foggiest idea of what the requirements are for home automation. What needs to be done?
There is a chance ... maybe tonight.
Okay. That lends some perspective. Still sounds like a great learning tool/toy.
Honestly, neither do I, I was just trying to think of something that would sound like a flipping-big-app.
I changed printhex to printx.
main() {
int n;
n = getina();
printx(n);
n = n | 0xa5;
setdira(n);
setouta(n & ~1);
n = getina();
printx(n);
}
I shall play with this a bit as soon as work is done!
Jeff
I've added an editor which the second .avi demos a little.
Ya, I'm starting to have fun with Propeller again.