Shop OBEX P1 Docs P2 Docs Learn Events
PE-Basic Version 0.16 July 11, 2011 — Parallax Forums

PE-Basic Version 0.16 July 11, 2011

BeanBean Posts: 8,129
edited 2013-02-01 19:04 in Propeller 1
I've been toying around with making a version of femtoBASIC in PropBasic instead of spin for speed.

Here is my first crack at it.
The hard-coded program has a tight 3 line loop that toggles pin 0. It's pretty fast 300,000 (simple) lines per second. So the pin toggles at 100KHz. [edit speed is quite a bit slower now]

I'm sure when I start fleshing it out, I'll need to switch to LMM so that will make it quite a bit slower (about 75,000 lines per second).

Comments welcome...

[edit]I uploaded a new version that uses LMM, speed is about 57,000 (simple) lines per second. Editing the program now works too.

[edit] July 5, 2010 uploaded a new version. Math works but strictly left-to-right evaluation. No "IF" or "FOR" yet. But it's getting there...

[edit] July 7 2010 uploaded a new version. Simple IF ... THEN line# expressions work now.

[edit] July 12 2010 uploaded new version. Added PEEK, POKE, DEBUG, INKEY, DISPLAY, VARS, NEW

[edit] Dec 22 2010 uploaded new version. Added GOSUB/RETURN, FOR/NEXT, and more.

[edit] Dec 23 2010 uploaded version 0.02 Dec 23, 2010. Added LOAD and SAVE.

[edit] Dec 25, 2010 updated version 0.04. Added multiplie commands per line seperated by ":". And READ DATA RESTORE.

[edit] Jan 9 2011 updated version 0.05. Added NTSC display, PS2 Keyboard input. Added LOCATE command. Allow lowercase.

[edit] Jan 12 2011 update version 0.06. Various fixes. Allow IF...THEN commands.

[edit] Feb 1, 2011 allow 8 character variable names (except FOR..NEXT). PLOT, LINE, etc.

[edit] Feb 4, 2011 Full expression evaluator (Thanks Mike Green). Added system variable CHARS to change the bitmap of characters. POKEB CHARS,255 changes the top line of the space(32) character to a solid line.

[edit] Feb 5, 2011 Fixed pin ranges, RND, ABS, backspace at start of line.

[edit] Mar 9, 2011 Updated to version with color video.

[edit] Mar 11, 2011 Updated. Changed name PEBasic (Propeller Embedded BASIC)

[edit] July 11, 2011 Updated. Posted version 0.16.


Bean
«134

Comments

  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2010-07-02 17:43
    Wow... BASIC written in BASIC translated to PASM.. Love it!

    Aren't you going to bump into a PBASIC size limitation pretty quick? Femto is a pretty large Spin program.

    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Propeller Feature Projects: PropellerPowered.com
    Visit the: PROPELLERPOWERED SIG forum kindly hosted by Savage Circuits.
  • BeanBean Posts: 8,129
    edited 2010-07-02 17:48
    OBC,
    Yeah, I'm almost sure it will be a LMM program. That will handle it.

    I'm thinking pretty modest, no SD card (EEPROM for program storage). No video (serial terminal). Of couse I'll add commands for the S2 motors, encoders, LED and such.

    Bean

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Use BASIC on the Propeller with the speed of assembly language.
    PropBASIC thread http://forums.parallax.com/showthread.php?p=867134

    March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    There are two rules in life:
    · 1) Never divulge all information
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    If you choose not to decide, you still have made a choice. [noparse][[/noparse]RUSH - Freewill]
  • Mike GreenMike Green Posts: 23,101
    edited 2010-07-02 18:37
    This is a great idea. FemtoBasic is really a pretty straightforward program. It uses recursive descent for expression handling and recursion isn't available in PropBasic, but there's no reason why you have to use recursive descent. A simple operator precedence table and two stacks (one for data and one for operators) would do. You could also just start with DongleBasic and add some S2 specific statements very much like BoeBotBasic, then replace the Spin version with the PropBasic version when you have time to finish it.

    If you have any questions about FemtoBasic as you go along, PM me or pose them in this thread and I'll try to help.

    BoeBotBasic worked fine over an xBee wireless link. I had preconfigured the xBees (Series 1) storing the destination and source node address assignments in the flash configuration memory using the standard commands so they'd power up all ready to go. I had made my own USB to xBee adapter for the PC end of things, but Parallax now has a nice one.
  • BeanBean Posts: 8,129
    edited 2010-07-02 19:19
    Mike,
    Could you go into more detail about how to use to two stacks ?
    I assume you just push both operators and data, then scan the operator stack and do the operations in precedence order ? I'm I even close ?

    If I use LMM then it wouldn't be too hard to implement recursion.

    Bean

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Use BASIC on the Propeller with the speed of assembly language.
    PropBASIC thread http://forums.parallax.com/showthread.php?p=867134

    March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    There are two rules in life:
    · 1) Never divulge all information
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    If you choose not to decide, you still have made a choice. [noparse][[/noparse]RUSH - Freewill]
  • Mike GreenMike Green Posts: 23,101
    edited 2010-07-02 20:29
    Like I said, you don't really need recursion.

    One stack is the data stack for the intermediate operands. The other stack holds the saved operators and their precedence. You'd have a master table with the operators and their precedences like:

    DAT
    operators byte
    byte 1, "+",0
    byte 1, "-",0
    byte 2, "*",0
    byte 2, "//",0
    byte 2, "/",0
    byte 3, "<>",0
    byte 3, "<=",0
    byte 3, "<",0
    byte 3, ">=",0
    byte 3, ">",0
    byte 3, "=",0

    This table structure is just an example. You can modify it as needed.

    The scanner scans the input line. If it finds a constant or a variable, it pushes the constant or variable value into the data stack. If it finds an operator, it looks to see if the operator stack is empty. If it is, it pushes the operator and its precedence (1, 2, or 3 in this example) into the operator stack. If the operator stack has something in it, the program compares the stacked precedence with the precedence of the new operator. If <=, the stacked operator is popped from the stack and executed (using the data stack for its operands) with the result left on the stack and the process is repeated. If >, the operator and its precedence are pushed onto the stack. Parentheses are treated specially. An opening parenthesis is always pushed into the operator stack and a closing parenthesis causes the operator stack to be popped and the operators executed until an opening parenthesis is popped. Any "end of expression" keyword or punctuation will cause the operator stack to be popped and the operators executed until the operator stack is empty. In a way, there's an implicit opening parenthesis and the "end of expression" acts as a closing parenthesis. You can keep track of nesting level for parentheses and check that a closing parenthesis and the open parenthesis entry in the operator stack match up.

    Obviously, you need overflow and underflow checking for the stacks. You also need special handling for unary operators so that you have a flag that's true if the last item scanned is an operator and false if it's an operand like a constant or variable. If the previous item is an operator, then the next item, if an operator, is a unary operator. You'd have different operator table entries for unary and binary operators (like "+", "-"). You would also check that unary-only or binary-only operators are used properly.

    Does this make sense? Try a simple example like "a + b * c + d" or "a * (b + c) * d" on paper.

    Post Edited (Mike Green) : 7/2/2010 8:36:35 PM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2010-07-02 20:40
    Oops, I think I got the order wrong. It should be "=>" to pop and execute and "<" to push
  • localrogerlocalroger Posts: 3,451
    edited 2010-07-03 00:33
    Actually, when you implement a manual stack to do an expression evaluator you are implementing recursion. You're just doing it at the application level instead of letting the interpreter or compiler automate it for you. But it's a basic capability that must be possible for a language to be Turing complete.

    There are several ways to approach infix expression evaluation, the tightest requiring automatic recursion in the host language, but all of which are best contemplated with at least three beers down.
  • BeanBean Posts: 8,129
    edited 2010-07-04 23:17
    I have done quite a bit of work on embedded Basic. It uses LMM so it's not nearly as fast.

    Still no math yet, but you can edit the program now.

    I have updated the file in the first post with the new version.

    Bean

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Use BASIC on the Propeller with the speed of assembly language.
    PropBASIC thread http://forums.parallax.com/showthread.php?p=867134

    March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    There are two rules in life:
    · 1) Never divulge all information
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    If you choose not to decide, you still have made a choice. [noparse][[/noparse]RUSH - Freewill]
  • BeanBean Posts: 8,129
    edited 2010-07-06 00:46
    I updated the program again.
    Math is evaluated strictly left-to-right.

    This short program show that a simple assignment is 1872 clocks (23.4uSec @ 80MHz)

    10 LET A=CNT
    20 LET B=CNT
    30 PRINT B-A

    Bean

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Use BASIC on the Propeller with the speed of assembly language.
    PropBASIC thread http://forums.parallax.com/forums/default.aspx?f=25&p=1&m=412552
    March 2010 Nuts and Volts articlehttp://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    There are two rules in life:
    1) Never divulge all information
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    If you choose not to decide, you still have made a choice. [RUSH - Freewill]
  • $WMc%$WMc% Posts: 1,884
    edited 2010-07-06 23:50
    Bean
    '
    Cool post, I'm glued

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Truth is out there············___$WMc%___···························· BoogerWoods, FL. USA


    want speed?·want·to use the Propeller?·want to stay with BASIC___www.propbasic.com___


    You can feel stupid by asking a stupid question or You can be really·stupid by not asking at all.

    ·
  • Cluso99Cluso99 Posts: 18,066
    edited 2010-07-07 02:09
    Bean: Great work. Seems you are really onto something here smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Links to other interesting threads:

    · Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
    · Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
    · Prop Tools under Development or Completed (Index)
    · Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)·
    · Prop OS: SphinxOS·, PropDos , PropCmd··· Search the Propeller forums·(uses advanced Google search)
    My cruising website is: ·www.bluemagic.biz·· MultiBlade Props: www.cluso.bluemagic.biz
  • BeanBean Posts: 8,129
    edited 2010-07-07 12:09
    Thanks for the encouragement guys.
    I updated the program, it now supports IF...THEN line#
    5 CLS
    10 LET A=1
    20 LET B=CNT
    30 PRINT A;",";
    40 LET A=A+1
    50 IF A <= 1000 THEN 30
    60 LET C=CNT
    65 PRINT
    70 PRINT C-B/80000;" MILLISECONDS."
    

    Bean


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Use BASIC on the Propeller with the speed of assembly language.
    PropBASIC thread http://forums.parallax.com/showthread.php?p=867134

    March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    There are two rules in life:
    · 1) Never divulge all information
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    If you choose not to decide, you still have made a choice. [noparse][[/noparse]RUSH - Freewill]

    Post Edited (Bean) : 7/7/2010 1:48:03 PM GMT
  • $WMc%$WMc% Posts: 1,884
    edited 2010-07-08 01:10
    Line numbers really take Me back. I remember " LIST " to start back at the top of the code.
    '
    I see the need for " RENUM ", This would be used when edits exceeded 9 between lines. I see and edit between line 60 and 70 "65 PRINT".
    '
    I have no idea on how to renumber the lines and the "THEN x", "GOTO x", " GOSUB x", etc. But I think it will need to be addressed.
    '
    I'm struggling to catch-up with this line of programing. Sorry I can,t be more help. This has Me rethinking alot about whats underneath.
    '
    This POST just gets better and better.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Truth is out there············___$WMc%___···························· BoogerWoods, FL. USA


    want speed?·want·to use the Propeller?·want to stay with BASIC___www.propbasic.com___


    You can feel stupid by asking a stupid question or You can be really·stupid by not asking at all.

    ·
  • RaymanRayman Posts: 13,799
    edited 2010-07-08 01:30
    Bean, regarding wireless, I really like my Wifly GSX (just wish I had more time to play with it).

    I'm pretty sure I'll be using the Wifly GSX for my robot (one day)...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    My Prop Apps:· http://www.rayslogic.com/propeller/Programming/Programming.htm

    My Prop Info: ·http://www.rayslogic.com/propeller/propeller.htm
    My Prop Products:· http://www.rayslogic.com/Propeller/Products/Products.htm
  • BeanBean Posts: 8,129
    edited 2010-07-12 16:21
    I have updated the EmbeddedBasic language.

    I have added PEEK, POKE, DEBUG, INKEY, DISPLAY, VARS, NEW

    Comment welcome...

    Bean

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Use BASIC on the Propeller with the speed of assembly language.
    PropBASIC thread http://forums.parallax.com/showthread.php?p=867134

    March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    There are two rules in life:
    · 1) Never divulge all information
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    If you choose not to decide, you still have made a choice. [noparse][[/noparse]RUSH - Freewill]
  • $WMc%$WMc% Posts: 1,884
    edited 2010-07-13 01:13
    Finally someone that speaks my language.

    This just gets Better and Better!

    Roll with it Bean, You are the MAN!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Truth is out there············___$WMc%___···························· BoogerWoods, FL. USA


    want speed?·want·to use the Propeller?·want to stay with BASIC___www.propbasic.com___


    You can feel stupid by asking a stupid question or You can be really·stupid by not asking at all.

    ·
  • HumanoidoHumanoido Posts: 5,770
    edited 2010-10-04 01:14
    Bean:

    This is so fantastic, we can hardly believe it!
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2010-10-04 01:27
    I'm intrigued. Is this an interpreter or a compiler?

    AFAIK, the only language that can do both is MBASIC with the Microsoft Bascom compiler from the early 1980s (Bascom morphed into QB which morphed into vb.net) It would be cool to replicate such a program.

    Speed is not really the issue for an interpreter. You write a program in an inbuilt IDE editor (on the chip, of course) and type "RUN" and it runs. Who cares if it is only 1000 instructions a second, because what you can do is experiment quickly and easily with each and every instruction. IMHO, instant feedback is the quickest way to learn a language. ('instant' = less than 5 seconds).

    But then once a program is working, you run it through a compiler to make it a lot faster. Is this where things are heading? An interpreter and a compiler?

    vb.net finally achieves something similar with instant compilation, though it took another decade of 'progress' to get there. (1982 to the early 1990s with QB).

    Where is Propbasic up to? I downloaded the latest manual but there are still some instructions mission, eg some string functions. Or maybe the language and the manual are not quite in synch?
  • BeanBean Posts: 8,129
    edited 2010-12-22 17:03
    I have uploaded a new version of embedded BASIC (see the first post in this thread).

    My goal is to implement this in the S2 robot to make a stand-alone programmable robot. When the wireless network module is released, I'd like to make my S2 to you can telnet into it and program it from anywhere in the world.

    I'd also like it to be at LEAST as fast as spin. And I think it is. A "FOR NEXT" loop of 10,000 takes only 230mSec.
    10 LET A=CNT
    20 FOR B=1 TO 10000
    30 NEXT B
    40 PRINT CNT-A/80000; " MILLISECONDS."
    

    It might also make a cool application for the C3 board too.

    Bean
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2010-12-22 22:09
    @Bean,

    Did my eyes deceive me or did I see support for a "DATA" statement?

    Any plans to support strings$ ?

    Nice work!!

    OBC
  • Brian RileyBrian Riley Posts: 626
    edited 2010-12-22 22:24
    Nice work!!!!!!!! I am going to give it a try on my S2 as soon as Christmas furor settles down here.

    Two questions

    1 - RENUMBER was spoken of earlier ... is it feasible in this environment? It would be handy, almost necessary.

    2 - when do you expect SAVE to be enabled?
  • BeanBean Posts: 8,129
    edited 2010-12-23 03:43
    Brian,
    Right now I'm changing the memory layout, and that is giving me headaches. (I had numbers as MSB first instead of LSB first, and I'm making the line length a single bytes instead of two bytes to save space).
    After I get that straightened out, SAVE and LOAD are next on the list.

    As for RENUMBER, that is tricky and will probably require too much code to implement after I get all the S2 commands (or C3 commands) implemented.

    Bean
  • BeanBean Posts: 8,129
    edited 2010-12-23 06:41
    Brian,
    I had some free time this morning so I got the new structure working (I think) and implemented SAVE and LOAD.
    If you have a 64K EEPROM you can save 5 programs total.
    SAVE or SAVE 0 will save to the default location (is loaded at powerup). SAVE 1 thru SAVE 4 will save to extra 32K EEPROM space.
    Any program where the first line is "1 CONT" will auto-run when loaded (or at powerup for default location).

    [edit] I found the first bug in 0.02. Keywords inside quotes get tokenized.

    Bean
  • David BetzDavid Betz Posts: 14,511
    edited 2010-12-23 09:23
    Ummm... I have a really dumb question. Where do I download PropBasic? I tried a forum search but didn't find the message with the attached file and I also didn't find it when I searched the OBEX for "PropBasic".

    Edit: Never mind. I found it through a web search. Sorry.
  • ercoerco Posts: 20,244
    edited 2010-12-23 09:46
    Just found this thread, very interesting. The mere fact that Mike Green said "This is a great idea" is to die for. Cool Beans, Bean!
  • BeanBean Posts: 8,129
    edited 2010-12-23 11:00
    David,
    Sorry I forgot to upload the .spin files as well.
    They are on the first post now.

    Bean
  • BeanBean Posts: 8,129
    edited 2010-12-25 07:41
    I have uploaded a new version 0.04.
    This one allows multiple commands per line by seperating with a colon ":" for example LET A=5:LET B=6
    It also has READ DATA RESTORE implemented. DATA elements can be full expressions for example DATA 1, 2,3, 2+2, A+6

    I think the next step to use a PS/2 keyboard and NTSC monitor to make this truely a stand-alone programable system.

    Comments welcome

    Bean
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2010-12-25 08:02
    Data statements!! Awesome!

    Extremely useful stuff for real BASIC programming. Thanks Bean!
  • BeanBean Posts: 8,129
    edited 2011-01-09 19:44
    I have posted an updated version of Embedded Basic. Version 0.05.

    This version is truly stand-alone. It uses a PS/2 Keyboard and has a NTSC display (48x19 characters). Run as-is on the demo board.

    I will change the video driver later because this one is bitmapped and uses alot of memory and is slow.

    I added a LOCATE command to set the print position.

    Also you can use lowercase characters now (commands get converted to uppercase).

    Comments please...

    Bean
  • HumanoidoHumanoido Posts: 5,770
    edited 2011-01-09 23:10
    Embedded BASIC interpreter
    I've been toying around with making a version of femtoBASIC in PropBasicinstead of spin for speed.

    Bean, is this open source? I looked for the MIT license but didn't see it listed in the code.
Sign In or Register to comment.