No announcement yet.

SANDBOX-0004 Tiny BASIC Interpreter for xx-P1T displays

  • Filter
  • Time
  • Show
Clear All
new posts

  • SANDBOX-0004 Tiny BASIC Interpreter for xx-P1T displays

    ID: SANDBOX-0004
    STATUS: 100% complete
    AUTHOR: Anna Ceguerra
    DATE: 19 December 2009
    Copyright (C) 2009 Anna Ceguerra

    Tiny BASIC Interpreter on Picaso

    This program takes a text-based Tiny Basic program and runs it. It assumes that you have created a valid .BAS file (see TEST.BAS for example).
    NOTE: The current version of Picaso PmmC runs a 4DGL program from RAM, which limits the size of the program (e.g. number of variables & number of nested GOSUBs)

    The hardware required are:
    4D touchscreen display: uOLED-32028-P1T ( or uLCD-32032-P1T (
    4D CE5 ( or MB5 (
    uSD (microSD) card (

    Software Tools:
    PmmC Program Loader Tool (
    4DGL Workshop Beta v2.4 (

    Device configuration PmmC file:
    4D GFX PmmC (device dependant):
    * uOLED-32028-P1T ( or
    * uLCD-32032-P1T (

    SANDBOX-0004_TinyBASIC_P1_code.4dg file (attached)

    Tiny BASIC program:
    TEST.BAS (attached)

    Connect the display to the CE5/MB5 (connected to the computer's USB port)
    Load the appropriate PmmC configuration file into the display
    Compile the .4dg file using 4DGL Workshop IDE, and load the firmware into the display
    Ensure the format of the uSD card is FAT (equivalent to FAT16)
    Ensure the name of the Tiny BASIC program is all in capital letters
    Load the Tiny BASIC program into the uSD card's root directory
    Insert the uSD card into the uSD slot on the display
    Start up the program (Reset the display). Type in the filename (all in capital letters), hit EXEC. The Tiny BASIC program will run.

    How it works:
    Embedded systems have several limitations such as code size, RAM and speed, but the 4D Systems' Picaso chip can handle a Tiny BASIC interpreter. The implemented grammar is given below.

    The program is divided into 5 main sections: keyboard, tokeniser, parser, executor and high-level functions (including main). The keyboard takes a .BAS filename as input, and the program then opens that file. The tokeniser interprets the text to symbols. The parser ensures that the command is in the proper format, and loads the appropriate symbols and values into the stack. The executor finds the appropriate function and runs that with the contents of the stack.

    * grammar from
    * line ::= number statement CR | statement CR
    * statement ::= PRINT expr-list
    * IF expression relop expression THEN statement
    * GOTO expression
    * INPUT var-list
    * LET var = expression
    * GOSUB expression
    * RETURN
    * CLEAR
    * LIST (not implemented)
    * RUN
    * END
    * REM (this was added by AC for comments)
    * expr-list ::= (string|expression) (, (string|expression)* )
    * var-list ::= var (, var)*
    * expression ::= (+|-|e) term ((+|-) term)*
    * term ::= factor ((*|/) factor)*
    * factor ::= var | number | (expression)
    * var ::= A | B | C .... | Y | Z
    * number ::= digit digit*
    * digit ::= 0 | 1 | 2 | 3 | ... | 8 | 9
    * relop ::= < (>|=|e) | > (