Shop OBEX P1 Docs P2 Docs Learn Events
Herbert Schildt's Little C — Parallax Forums

Herbert Schildt's Little C

jazzedjazzed Posts: 11,803
edited 2013-08-02 14:40 in Propeller 1
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
574 x 591 - 106K

Comments

  • JonnyMacJonnyMac Posts: 9,107
    edited 2013-07-30 14:34
    I still have some of Herb's books, and turned to them recently as you've given me good reason to learn C.
  • Martin_HMartin_H Posts: 4,051
    edited 2013-07-30 17:57
    This is interesting. Can Little C programs interact with Propeller registers like DIRA, INA, and OUTA? Or is it just console I/O at the moment?
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2013-07-31 09:47
    That's really slick! This could get interesting running on my double-Quickstart configuration.

    I'd like to second Martin's question...
  • jazzedjazzed Posts: 11,803
    edited 2013-07-31 10:00
    I've added code to handle this:

    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.
    Little C Startup.
    Enter program, then ESC to run.
    
    
    main() {
      int n;
      n = getina();
      printhex(n);
      n = n | 0xa5;
      setdira(n);
      setouta(n & ~1);
      n = getina();
      printhex(n);
    }
    
    End of input. Running Program.
    
    F00F0000 F00F00A4 
    
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2013-07-31 10:18
    Nice!

    Any chance I could convince you to post a .binary which uses P12,P13 for TX/RX?

    Jeff
  • TinkersALotTinkersALot Posts: 535
    edited 2013-07-31 12:13
    jazzed wrote: »
    ...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....

    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?
  • Dave HeinDave Hein Posts: 6,347
    edited 2013-07-31 13:54
    jazzed wrote: »
    I'm trying to get LittleC to run on Spinix ... it runs, but user code must be entered by hand.
    I found the problems with spinix and the latest version of C. spinix looks at a couple of long values in the binary to determine if it's a Spin binary or a C binary. These values have changed since I last updated the spinix shell program, so it is identifying C programs as Spin programs. The other problem is that the C loader was patching an instruction into the startup code to allow the stack pointer to be set to something other than $8000. This was fixed a long time ago in the C code, but I hadn't changed the spinix C loader to account for that.

    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.
  • jazzedjazzed Posts: 11,803
    edited 2013-07-31 14:41
    Thanks Dave.

    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?
  • jazzedjazzed Posts: 11,803
    edited 2013-07-31 14:50
    Nice!

    Any chance I could convince you to post a .binary which uses P12,P13 for TX/RX?

    Jeff

    There is a chance ... maybe tonight.
  • TinkersALotTinkersALot Posts: 535
    edited 2013-07-31 17:10
    jazzed wrote: »
    LittleC is really just a programmer's toy. At the moment a single source program can be up to 10K bytes.

    Okay. That lends some perspective. Still sounds like a great learning tool/toy.
    jazzed wrote: »
    I haven't even the foggiest idea of what the requirements are for home automation.

    Honestly, neither do I, I was just trying to think of something that would sound like a flipping-big-app. :)
  • jazzedjazzed Posts: 11,803
    edited 2013-07-31 18:57
    OBC, Try this one with RX=13 TX=12.

    I changed printhex to printx.

    main() {
    int n;
    n = getina();
    printx(n);
    n = n | 0xa5;
    setdira(n);
    setouta(n & ~1);
    n = getina();
    printx(n);
    }
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2013-07-31 21:21
    Thank you @jazzed!

    I shall play with this a bit as soon as work is done!

    Jeff
  • jazzedjazzed Posts: 11,803
    edited 2013-08-01 21:57
    Made some enhancements to this. Here are some videos.
  • jazzedjazzed Posts: 11,803
    edited 2013-08-02 11:51
    Here's a binary for typical propellers (P31,30 RX,TX and 5MHz Crystal).

    I've added an editor which the second .avi demos a little.
    Little C Startup.
    Enter program, and press ESC to end input.
    
    main() { print("Hello\n"); }
    End of input.
    Enter L to list, R to run, or ? for more.
    
    ? r
    Hello
    Ok
    ? 
    
    Usage
     A[#]<CR>text<ESC>  Append text at end or after #
     C[#]<CR>text<CR>   Change line at end or at line #
     D[#]<CR>           Delete line at end or at line #
     I[#]<CR>text<ESC>  Insert text before start or #
     L List program with line numbers
     N Start a new program
     Q Quit
     P Print program without line numbers
     R Run program
     ? Show this help.
     # is optional. CR is Enter. ESC terminates input.
     Commands can be lower case.
    
    ? l
    Program:
    1  main() { print("Hello\n"); }
    2  
    ? 
    
  • David BetzDavid Betz Posts: 14,516
    edited 2013-08-02 12:55
    Hi Steve! Looks like you're having fun with this! How much program space remains after you added the editor?
  • jazzedjazzed Posts: 11,803
    edited 2013-08-02 13:29
    Program array is 5KB. The 10KB estimate was high. The editor took about 2.5KB.

    Ya, I'm starting to have fun with Propeller again.
  • David BetzDavid Betz Posts: 14,516
    edited 2013-08-02 14:27
    jazzed wrote: »
    Program array is 5KB. The 10KB estimate was high. The editor took about 2.5KB.

    Ya, I'm starting to have fun with Propeller again.
    I'm sure it helps when you get a chance to actually program the Propeller rather than tools that run on the PC.
  • Cluso99Cluso99 Posts: 18,069
    edited 2013-08-02 14:40
    Nice to see you are having fun Steve. These "little" versions of the various languages should go great on the prop.
Sign In or Register to comment.