Shop OBEX P1 Docs P2 Docs Learn Events
Understanding the Parallax Interpreter — Parallax Forums

Understanding the Parallax Interpreter

microcontrollerusermicrocontrolleruser Posts: 1,194
edited 2018-05-29 15:34 in General Discussion
When you try to compare PBasic to other languages there's something that doesn't fit.

You have to 'add in' the Parallax interpreter.

On second thought. Who adapted the idea after the PBasic?

Parallax did! Used it again on Propeller.

Yet. Unless I'm mistaken. I have never seen it used by anybody else.

Comments

  • Yes, you're mistaken. Java, JavaScript, Python, and others are all examples where various combinations of compilers that turn out an intermediate interpretive code and interpreters for that code are used. In some cases the interpreter can directly interpret source code and in some cases the compiler can turn out instructions for a particular instruction set for direct execution. Usually in that case, most of the instructions are calls to the run-time library so there may not be a large advantage over an interpreter.

    FemtoBasic is an example of a mostly source-level interpreter. Internally, keywords are replaced by single byte codes to simplify parsing, but most of the rest of the source code is kept as-is while being interpreted.

    Spin is an example of an interpreter of an idealized instruction set coupled with a compiler for this instruction set. The instruction set is optimized for program size rather than execution speed and many of the operations are specific to the Prop1.

    This is a "fundamental concept" in most programming education

  • Well. How about that! Looks like a lot of languages are interpreted.

    See the Wikipedia article here.

    https://en.wikipedia.org/wiki/Interpreted_language

    As far as micro's I have not seen any others use an interpreter.

    The languages can be user friendly like PBasic yet they are still compiled.

    With that pesky waiting time while they compile each time you change the program.
  • Mike GreenMike Green Posts: 23,101
    edited 2018-05-29 15:51
    How about microPython (check out SparkFun) and circuitPython (from AdaFruit)? FemtoBasic directly interprets source code ... no separate compilation.
  • microcontrollerusermicrocontrolleruser Posts: 1,194
    edited 2018-05-29 16:00
    'This is a "fundamental concept" in most programming education'

    Gee.Thank you for pointing out that I lack the refinement to appreciate the interpreter and the Propeller.

    'Let it be written. Let it be down'.

    Thank you. You've done me a favor.

    I'm just down here with the masses that hear 'slow' and that sends them running.

    Not all of us are interested in mental exercise' for it's own sake.

    Some of us have things to do.

    We're interested in getting things done in the most direct manner.

    You can consider that passed on to you by a tech higher up.Form him to me to you.
  • SDS 900 series Fortran2 was about half compiler, half interpreter. This was in 1965.

    Wish I could remember the vendor name. Digitec or some such?
  • Mike GreenMike Green Posts: 23,101
    edited 2018-05-29 16:12
    These are not "mental exercise". They're basic concepts. You don't have to know how to design or implement a compiler, but you ought to know how to choose one. It's like understanding RC circuits and their uses ... like debouncing switch closures ... or choosing batteries ... which type of chemistry might you want ... because that choice is affected by environmental concerns and in turn affects which charger chips you need. Do you know how to design an inductor or transformer? I don't mean "off the top of your head" ... I don't do that ... this is a hobby for me, but I do know where on my bookshelf to find all the information I'd need and I do understand what's written down in my reference material.

    How can you "get things done in the most direct manner" if you don't understand the concepts involved and the issues that define 'direct'?

  • My only interest is if an interpreter 'toolkit' for a micro is doable and available.

    Right now it looks like it is either too involved and not readily available.

    I have not seen 'Interpreter Toolkit' pop up at all over the years.
  • I have not looked at the project for microPython or its cousins, but I have seen a variety of implementations for different microcontrollers available on the net. That's probably the closest thing you'll find to an open source interpreter for a microprocessor-based high level language. I don't think you'll find an "interpreter Toolkit". You're talking about a fairly complex project with a significant amount of work required ... roughly what someone taking a one semester seminar type course at a community college might do.

  • Thanks.

    Better use of the time would be article of 'Tips for Beginner's' for assembler and C.

    Sort of apply the Parallax 'simple' method or however they write.

    The PICaxe WJEC assembler achieves the same goal as Parallax language yet keeps it as compile.

    In that the commands are macros plus a few features to get past the configuration.

    Plus they have a smooth program load. I forget how.

    I think that is a good middle road. Parallax used that for SX.

    Taking on interpreter is to unwieldy for the hobbyist.

  • In fact the PICaxe assembler is VERY like the Parallax SX.
  • Parallax seems to have very little interest in supporting assembly language as a beginner’s topic ... I think appropriately. Originally they supported Spin for the Propeller and PBasic for the Stamps. Now that they have C / C++ available for the Propeller, their support is primarily in that direction with BlocklyProp as a beginner’s front end (since it produces C for compilation). Prop1 assembly is an advanced topic and there are formal and informal reference documents for assembly as provided with Spin and with the GCC tool chain (along with C / C++). With the advent of the Prop2, assembly will be treated even more as an advanced topic since it’s much more complex than assembly for the Prop1.

    Stick with other micro controllers for learning assembly since the Prop1 (which is very easy to use) doesn’t appeal to you. Find one that makes sense to you, that you enjoy using and that has tools available that you find comfortable to use at a price that you can afford. The SX is effectively discontinued even though Parallax will sell off stock-on-hand that they don’t need for making Stamps. Parallax doesn’t support PICs ... that’s Microchip’s territory.

  • 'Parallax seems to have very little interest in supporting assembly language as a beginner’s topic '

    Looks like PICaxe crew are a bright bunch to me.You say it's a waste of time though.

    To be quite honest the PICaxe compiler trounces the Stamp IDE.

    For the simple reason PICaxe stuck with it.

    Back to the interpreter.

    Better to leave that be and just write 'Tips for Beginner's' for assembly and C.





  • The PICaxe crew have a good product and they've continued development on their tools. Parallax has, for good reasons for them, gone down a different path (the Prop1 and Prop2). You may not care for that, but it seems to be working for Parallax.
  • jmgjmg Posts: 15,140
    My only interest is if an interpreter 'toolkit' for a micro is doable and available.

    If you are looking around for BASIC on small MCUs there is also BASIC52 and BASCOM51, that support various 8051's.
    If you like Pascal, there is Turbo51 - that's compiled.

    You can get a breakout board with a Bootloader and modern Flash 8051 (N76E003) for just $1.10, that would allow modest programs to download/run over a common USB-UART bridge.

  • Heater.Heater. Posts: 21,230
    Don't forget the wonderful Epruino. Javascript for you STM32 microcontroller: https://www.espruino.com/

    Also runs on the nRF52832 micro: https://www.espruino.com/MDBT42Q,
    the ESP8226, ESP32 and BBC micro:bit.

    If you want an "interpreter tool kit" get Jerry Script from Samsung: http://jerryscript.net/

    Or people have used Lua on microcontrollers: http://www.eluaproject.net/
  • I really hope that there is a Spin2. Spin1 is such a well-structured language compared to some that I have seen, even as well as C#.
  • Heater. wrote: »
    Don't forget the wonderful Epruino. Javascript for you STM32 microcontroller: https://www.espruino.com/

    Also runs on the nRF52832 micro: https://www.espruino.com/MDBT42Q,
    the ESP8226, ESP32 and BBC micro:bit.

    If you want an "interpreter tool kit" get Jerry Script from Samsung: http://jerryscript.net/

    Or people have used Lua on microcontrollers: http://www.eluaproject.net/


    Does The Lua work on the Prop1 too?
  • jmgjmg Posts: 15,140
    I really hope that there is a Spin2. Spin1 is such a well-structured language compared to some that I have seen, even as well as C#.

    Try this
    https://forums.parallax.com/discussion/164187/fastspin-compiler-for-p2/p1
  • Heater.Heater. Posts: 21,230
    JaanDoh,

    I have no idea what the memory requirements of Lua are except we can be certain that they are far bigger than the 32K of the Prop 1. It would also be painfully slow.

  • SDS 900 series Fortran2 was about half compiler, half interpreter. This was in 1965.

    Wish I could remember the vendor name. Digitec or some such?

    Hello!
    SDS? Themselves actually. That was one of several startups who surfaced about the time IBM started building their systems. It eventually evolved into the computer division of Xerox. Oh and DEC got started about then as well.

    Xerox had a few good ideas, and one great one. It didn't go as planned, and yet we run something based on it. (Well some of us do.)
  • Let us not forget the way Apple did their BASIC suite for both their Integer and Floating Point based BASIC. They would do a running interpretation and typically would present the users with interesting error messages as the system would read the programs being written in by the user.

    That's how I got started in programming, I also did a fair bit of Assembly on them.

    But yes I agree entirely with everything Mike has stated there.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2018-05-30 22:49
    Sorry, I don't understand why the word "interpreter" is limited to BASIC but interpreted doesn't mean interactive either which is what I think you mean. Spin is interpreted but it is not interactive. PBASIC is interpreted but it is not interactive. One of the reasons for this is the memory on the chip that would be required to handle the console, the word list, the compiler etc.

    But the Propeller chip has many interactive interpreters, primarily Tachyon Forth:
    Straight up from a serial console is about as direct as you can get
    ...  10 FOR CR PRINT" Hello World!"  NEXT 
    Hello World!
    Hello World!
    Hello World!
    Hello World!
    Hello World!
    Hello World!
    Hello World!
    Hello World!
    Hello World!
    Hello World! ok
    

    or turn that demo into another word that the "interpreter" understands and run it:
    ...  pub DEMO  10 FOR CR PRINT" Hello World!"  NEXT ; 
    ...  DEMO 
    Hello World!
    Hello World!
    Hello World!
    Hello World!
    Hello World!
    Hello World!
    Hello World!
    Hello World!
    Hello World!
    Hello World! ok
    

    Or print that over VGA very directly with "VGA DEMO" etc
    But interpreted doesn't have to mean slowwww. I can find out how long 1 million FOR NEXT loops take:
    ...  LAP 1000000 FOR NEXT LAP .LAP 48,000,352 cycles = 600.004ms  ok
    
    That's 600ns per loop overhead which is mighty snappy for an interpreter.
  • There's also a middle ground between interpreting raw source and compiling to an intermediate pcode: it's called "tokenizing." The first MS BASICs were tokenized, which means that keywords were reduced to single bytes when a line of code was entered, and it was the tokenized code that was interpreted. Since this was lossless compression, the original code could be reconstructed from the tokens for display. Well, it wasn't totally lossless, in that whitespace was simply deleted and reconstructed in "standard" form for display.

    I can't remember how the symbol table was handled, though.

    -Phil
  • I can. I'm not supposed to use that language online though. Poorly at first.

    YOWF! Sorry about that one, cat at work here.

    However by the time of the Apple 2Plus design the method of doing so was considerably better. By the time of the Apple 2E things had improved to the point where I'd type in the classic several hundred line program, save it, and run it, and get no errors, and a splendid output in graphics to match.

    By contrast MS BASIC on the PC was a poorly fit kludge, they took the one he wrote for the Altair and shoehorned it in. By the time we got to DOS 3,30 things were considerably better. Eventually we had professional development tools.

    I can go on, but all of you do see my points.
  • kwinnkwinn Posts: 8,697
    There's also a middle ground between interpreting raw source and compiling to an intermediate pcode: it's called "tokenizing." The first MS BASICs were tokenized, which means that keywords were reduced to single bytes when a line of code was entered, and it was the tokenized code that was interpreted. Since this was lossless compression, the original code could be reconstructed from the tokens for display. Well, it wasn't totally lossless, in that whitespace was simply deleted and reconstructed in "standard" form for display.

    I can't remember how the symbol table was handled, though.

    -Phil

    Not sure if this was a commonly used method but the one I recall stored each unique symbol in a table along with a pointer to the address following the token. Each re-occurence of that symbol resulted in a pointer to the address location of the previous token that used that symbol, creating a linked list of all the references to that symbol. Once the address of the symbol was resolved the list was used to replace the links with the actual address.
Sign In or Register to comment.