***tiny_basic_RS V2 in TCL as partial Basic language interpreter***
 
This page is under development. Comments are welcome, but please load any comments in the comments section at the bottom of the page. Please include your wiki MONIKER and date in your comment with the same courtesy that I will give you. Aside from your courtesy, your wiki MONIKER and date as a signature and minimal good faith of any internet post are the rules of this TCL-WIKI. Its very hard to reply reasonably without some background of the correspondent on his WIKI bio page. Thanks, [gold] 20Sep2020

----
Title: Demo tiny_basic_RS  V2
<<TOC>>

***Preface***
[gold] 20aug2020  Here is extension of program written by Richard Suchenwirth [RS] in 2000, [Basic in TCL].  
----
***Introduction***
Called  tiny_basic_RS V2 in TCL as partial Basic language interpreter. Learning experience, Added some easy eye console displays for my bad eyes. And trying some new features. Some math calculation forms seem to be working. I would like to add a smoother invoking of expr and regexp into the <tiny_basic_RS>.
----
======
     source tiny_basic_RS.tcl
     basic { 10 n=2/7. : 20 print n} ;# returns 0.2857
     basic { 10 n=[/ 2 7. ]: 20 print n} ;# returns 0.2857
     basic { 10 n={2/ 7.}: 20 print n}: 20 print n}  :# returns 0.2857 
     # basic { 10 n=[ expr {2/ 7.} ] : 20 print n} ;#
     # tiny_basic_RS.tcl not invoking expr & regexp smoothly
     # keeper     string map {\{ "" \} ""} $item
======
----
Gathering some references on tiny basic and really surprised how much interest in computer theory of tiny basic. From what i can tell, Richard Suchenwirth has most or all of the original features of Tiny Basic, circa 1976.
----
 
----
***Screenshots***      
---- 
***figure 1. Basic_RS V1 as vaporware*** 
----
[basic_RS_in_TCL png]
----
***figure 2. Basic_RS V2 in TCL***
----
[Basic_RS V2 in TCL as partial Basic language interpreter screenshot]
----
***References:***
----
   * google search engine <  Quickbasic>
   * [BASIC]
   * en.wikipedia.org wiki BASIC
   * en.wikipedia.org wiki QBasic
   * [Call Procedure Like Fortran Example]
   * [Basic in TCL]
   * [https://en.wikipedia.org/wiki/One-liner_program] Draft Wikipedia article on One Liners Programs , TCL Tool Control Language
   * [https://en.wikipedia.org/wiki/QBasic] QBasic wikipedia
   * [https://en.wikibooks.org/wiki/QBasic/Appendix] QBasic wikibook
   * Palo Alto Tiny Basic by Li-Chen Wang
   * originally appeared in Issue No.5, May 1976 of Dr.
   * Dobb's Journal. 
   * SCELBAL -  8008/8080 SYSTEMS, By Mark Arnold and Nat Wadsworth
   * Tiny Basic, all numbers are integers,
   * INTERFACE AGE, By Roger Rauskolb
   * rare books, Dr Dobb's Journal of Computer
   * Calisthenics Orthodontia Apple Tiny Basic 6502
   * QBasic By Example, Special Edition, Que Publishing,1565294394
   * QBASIC Programming for Dummies, by Douglas Hergert ,1994
   * NSC_Tiny_BASIC_Users_Manual_Nov80.pdf
   * SC/MP gets Tiny-BASIC
   * The Arduino Inventor’s Guide:
   * Learn Electronics by Making 10 Awesome Projects
   * using tiny basic games and programs,
   * 13 Pages, 2004
   * Popular Science, Electronics-Experimenter's-Handbook-1979
   * ES MP5 Game Player - support GBA, GBC, SMD, SFC, NES formats
   * [Tcl implementations]
   * [The Very Minimal Tcl Core Command Set]
   * [Does Tcl still fit on 16-bit microcontrollers?]
   * [MicroTcl for Tcl9]
   * [dbohdan]'s list of https://github.com/dbohdan/embedded-scripting-languages%|%embedded scripting languages%|%
   * [https://www.levenez.com/lang/] www.levenez.com history of computer languages
   * [A little math language revisited]
   * [A little math language]
   * [Tcl Math Syntax is Inferior to JavaScript/Python/Ruby/C/C++/Java/Perl/PHP]
   * [Numerical Analysis in Tcl]
   * [a little proving engine]
   * [Parsing Polish notation]
   * [let]
   * [let - a simpler sugar for expr]
   * [AMG's language ideas]
   * [Let's assign with let]
   * The L Programming Language or
   * Tcl for C Programmers, Oscar Bonilla, Tim Daly, Jr., Larry McVoy
   * search keywords <Avoiding Brackets> 
   * [Assign using equals]
   * Partcl - a minimal Tcl interpreter
   * Tiny Tcl 6.8 is a rommable,
   * minimal Tcl for embedded applications.
   * Basic256, So You Want to Learn to Program?, English pdf
   * James M. Reneau, M.S., Shawnee State University
   * Portsmouth Ohio USA
   * German Tutorial for Basic256 , basic256.pdf (Public Domain).   * Some Basic256 documentation is available in
   * English, Russian, Dutch, German, Spanish and Portuguese.
   * SourceForge net, BASIC256, basic language for schools
----
----
 
----
----    
****Appendix TCL programs and scripts ****

**** Pretty Print Version*** 

----
======
        # Title: tiny_basic_RS in TCL V2
        # partial basic language interpreter tiny_basic_RS
        # demo basic from RS, (wiki 2000-08-21)
        # Original program  by Richard Suchenwirth on TCL WIKI
        # wiki page titled Basic in TCL
        # Reorganized code from, https://wiki.tcl-lang.org/915
        # for print and self_help 
        # to tcl console.
        # search keywords < tiny basic 1976 >
        # written on Windows 10 on TCL
        # working under TCL version 8.6
        # on TCL WIKI , 20Sep2020
        # added statements for TCLLIB library
        package require math::numtheory
        package require math::constants
        package require math::trig
        package require math
        namespace path {::tcl::mathop ::tcl::mathfunc math::numtheory math::trig math::constants }
        # Tried to keep clean RS  code in upper section
        # added extension to console below. -gold
        proc lpush {_list what} {
            upvar $_list L
            if ![info exists L] {set L {}}
            set L [concat [list $what] $L]
        }
        proc lpop {_list} {
            upvar $_list L
            if ![info exists L] {return ""}
            set t [lindex $L 0]
            set L [lrange $L 1 end]
            return $t
        }
        proc intgen {{seed 0}} {
            set self [lindex [info level 0] 0]
            proc $self "{seed [incr seed]}" [info body $self]
            set seed
        } ;# RS       
        proc basic {script} {
            # old BASIC had 26 numeric variables..
            foreach i {A B C D E F G H I J K L M N O P Q R S T U V W X Y Z} {
                set $i 0
            }
            set states ""
            set Stack [list Error:Stack]
            foreach line [split [string toupper $script] \n] {
                if [regexp { *([0-9]+) +(.+)} $line -> label rest] {
                    set outline ""
                    foreach stmt [split $rest :] {
                        set step 1
                        if [regexp { ?('|REM)} $stmt] {
                            # start extension for console
                            # wish to print all comments
                            puts $stmt
                            break ;# no statements to be expected after comment                       
                         } elseif [regexp { ?('|PRINT_TXT)} $stmt] { 
                            # wish to print specific text
                            puts $stmt
                            break ;# no statements to be expected
                            # insert extension code here
                        } elseif [regexp {PRINT +(.+)} $stmt -> what] {
                            regsub -all ", *" $what "\t" what
                            regsub -all "; *" $what " " what
                            regsub -all {([A-Z])} $what {$\1} what
                            append outline "puts \"$what\"; "
                        } elseif [regexp {FOR +([A-Z]) *= *(.+) TO (.+)( STEP (.+))?} \
                                $stmt -> looper from to - step] {
                                    regsub -all {([A-Z])} $from {$\1} from
                                    regsub -all {([A-Z])} $to {$\1} to
                                    set here -[intgen]
                                    set step 1 ;# to start with
                                    set next($looper) "incr $looper $step; if {\$$looper<=$to} {goto $here}"
                                    append outline "set $looper $from\}\n$here \{"
                                } elseif [regexp {NEXT (.+)} $stmt -> id] {
                                    append outline $next($id)
                                    unset next($id)
                                } elseif [regexp {IF +([^ ]+) +(THEN|GOTO) +([0-9]+)}\
                                $stmt -> cond - goto] {
                                    regsub -all {([A-Z])} $cond {$\1} cond
                                    append outline "if {$cond} {goto $goto}; "
                                } elseif [regexp {ON (.+) GOTO +(.+)} $stmt -> cond labels] {
                                    regsub -all {([A-Z])} $cond {$\1} cond
                                    append outline "goto \[lindex \{- [split $labels ,]\} \[expr $cond\]\]; "
                                } elseif [regexp {GO *TO ([0-9]+)} $stmt -> id] {
                                    append outline "goto $id; "
                                } elseif [regexp {GO *SUB ([0-9]+)} $stmt -> id] {
                                    set here -[intgen]
                                    append outline "lpush Stack $here; goto $id\}\n$here \{ "
                                } elseif [regexp {RETURN} $stmt] {
                                    append outline "goto \[lpop Stack\]; "
                                } elseif [regexp { *END} $stmt] {
                                    append outline "break; "
                                } elseif [regexp {([A-Z])=(.+)} $stmt -> lhs rhs] {
                                    regsub -all {([A-Z])} $rhs {$\1} rhs
                                    append outline "set $lhs \[expr $rhs\]; "
                                }
                    }
                    append states "$label {$outline}\n"
                }
            }
            states $states
        } ;#RS        
        proc states body {
            proc goto {id} {uplevel set goto $id; return -code continue}
            uplevel set goto [lindex $body 0]
            set tmp [lindex $body 0]
            foreach {cmd label} [lrange $body 1 end] {
                if {$label==""} {set label default}
                lappend tmp "$cmd; goto [list $label]" $label
            }
            lappend tmp break ;# to match last "default" label
            uplevel while 1 "{switch -- \$goto [list $tmp]}"
            rename goto ""
        } ;#RS        
        basic {
            100 J=1:K=1
            110 GOSUB 300
            120 PRINT I,J;K
            130 IF I<5 GOTO 110: REM DONE
            135 for a=100 to J+103
            137    print a
            140 next a
            150 END
            300 REM---------- slight increment
            310 I=I+J: K=K*2
            320 RETURN
        }
        #end of RS deck       
        # add cosmetics below to bottom of file or source Basic_RS.tcl
        # added statements above for TCLLIB library
        console show
        console eval {.console config -bg palegreen}
        console eval {.console config -font {fixed 20 bold}}
        console eval {wm geometry . 40x20}
        console eval {wm title . "Basic_RS in TCL , screen grab and paste from console  to texteditor"}
        console eval {. configure -background orange -highlightcolor brown -relief raised -border 30}
        console eval { proc self_helpx {} {
                set msg "Basic_RS in TCL, large black type on green
                from TCL,
                self help listing
                Conventional text editor formulas grabbed
                from internet screens can be pasted
                into green console
                colon is statement end
                # demo basic from RS, (wiki 2000-08-21) "
                tk_messageBox -title "self_helpxx" -message $msg } }
        console eval {.menubar.help add command -label Self_help -command self_helpx } 
        # proc basic here is a second program or set of commands
            basic {
            50 REM user on basic_RS, TCL 8.6
            70 REM math ops from TCL is loaded
            100 a=1.
            137 print a
            140 b=  [* 5 6 ]             
            150 print b             
            160 c= [/ 5 7. ] 
            170 print c
            175 REM PRINTING D 
            180 d=5*5 
            200 print d
            250 print [* 5 7 ]
            300 REM wish to print all REM strings
            315 PRINT_TXT user on TCL 8.6
            318 PRINT_TXT  [* 5 6 ]
            340 REM wish to use expr math
            350 EXPR  { 2*7 }
            400 RETURN
            }
            puts " returns to TCL 8.6  for check 5*6 = [* 5 6 ]"  
        
======
----
***Extension  Code for console screens ***
----
======
                             # begin extension for console, marked in above deck.
                             # need smoother invoking of expr and regexp assignment
                             # into the <tiny_basic_RS>.
                             # would not mind a alternate assignment ==
                         } elseif [regexp { ?('|EXPR)} $stmt]  { 
                             # wish eval content to expr
                             # $w move [$w find withtag "$tilex"] [expr {$x-$p(X)}] [expr {$y-$p(Y)}]
                             #set numberx [$w  gettags current]
                             #regexp {obj_(\d+)} $numberx -> tilex
                             puts " trick1   \[expr $stmt \] \[expr {[lindex [split $stmt ] 3 ]}\]" ;
                             puts " trick2  [expr   [expr {[lindex [split $stmt ] 3 ]} ]]" ;
                             puts " trick3    [expr {[lindex [split $stmt ] 3 ]} ] " ;
                             set tilex 7777;
                             regexp {EXPR(\a+)} $stmt -> tilex;
                            puts  $tilex;
                            break ;# no statements to be expected
                            # end extension for console. 
======
----
**Hidden Comments Section**

<<discussion>>
Please include your wiki MONIKER and date in your comment with the same courtesy that I will give you. Thanks, [gold] 12Aug2020 

                              
----
<<categories>> Numerical Analysis | Toys | Calculator | Mathematics| Example| Toys and Games | Games | Application | GUI
----
<<categories>> Development | Concept| Algorithm  | Language