sync on:sync rate 0
set window on
set display mode 1024,768,32
set window title "Logo Programming"
 
 
remstart
Logo Parser created by Lowerlogic
remend
 
cls
global error$
global error1$
global make_function=0
dim parameter$(0)
dim edall$(0)
empty array parameter$(0)
empty array edall$(0)
ink -1,0
box 0,0,screen width(),screen height()
ink 0,0
type window_type
left
top
right
bottom
endtype
global window as window_type
window.right=screen width()
window.bottom=screen height()
type xyz
   x as float
   y as float
   z as float
endtype
type status
   contact as boolean
   width as integer
   penmode as string
   heading as float
   pitch as float
   roll as float
   position as xyz
   which as integer
   visibility as boolean
   pencolor
   floodcolor
   screencolor
   Palette_use as string
endtype
global status as status
dim part$(0)
status.contact=1
status.width=1
status.penmode="paint"
status.heading=0.00
status.pitch=0.00
status.roll=0.00
status.position.x=0
status.position.y=0
status.position.z=0
status.which=0
status.visibility=1
status.pencolor=rgb(0,0,0)
status.floodcolor=rgb(0,0,0)
status.screencolor=rgb(255,255,255)
status.Palette_use="N/A"
 
dim color(15)
color(0)=rgb(0,0,0)           `black
color(1)=rgb(0,0,255)         `blue
color(2)=rgb(0,255,0)         `green
color(3)=rgb(0,255,255)       `cyan
color(4)=rgb(255,0,0)         `red
color(5)=rgb(255,0,255)       `magenta
color(6)=rgb(255,255,0)       `yellow
color(7)=rgb(255,255,255)     `white
color(8)=rgb(155,96,59)       `brown
color(9)=rgb(197,136,18)      `tan
color(10)=rgb(100,162,64)     `olive
color(11)=rgb(120,187,187)    `sky blue
color(12)=rgb(255,149,119)    `salmon
color(13)=rgb(144,113,208)    `medium purple
color(14)=rgb(255,163,0)      `orange
color(15)=rgb(183,183,183)    `gray
do
   read strg$
   `if len(strg$)>0 then print ">> ", strg$
   strg$=clean_up(strg$)
   `if len(strg$)>0 then print ">> ", strg$
   strg$=parse(strg$)
   `print error$,",",strg$
   rem ome error handling
   error$=upper$(error$)
   if len(strg$)>0
      if error$="NOTINST"
         output("You don't say what to do with "+first(strg$))
      endif
      if error$="NOTCOM" and len(strg$)>0
         output("I don't know how to "+first(strg$))
      endif
      if error$="NOLIKE"
         output(first(strg$)+" doesn't like "+error1$+" as input")
      endif
      if error$="NOTENOUGH"
         output("not enough inputs to "+first(strg$))
      endif
      if error$="NOOUTPUT"
         output(first(strg$)+" did not output to "+error1$)
      endif
   endif
   sync
loop
output("done")
sync
sync
wait key
end
 
function parse(strg$)
   while left$(strg$,1)=" "
      strg$=right$(strg$,len(strg$)-1)
   endwhile
   while right$(strg$,1)=" "
      strg$=left$(strg$,len(strg$)-1)
   endwhile
   if make_function=1
      array insert at bottom edall$(0)
      edall$(array count(edall$(0)))=strg$
   endif
 
   error$=""
`if len(strg$)>0 then output("Parsing ["+strg$+"]")
`sync
   sync
`wait key
   base_parameter=array count(parameter$(0))
   original_command$=first(strg$)
   if is_instruction(original_command$)=0
      error$="NOTINST"
      exitfunction strg$
   endif
   if len(original_command$)<1 then exitfunction ""
   strg$=pop(strg$)
   command$=upper$(original_command$)
   if make_function=0
      array delete element part$(0),0
      if command$="CLEARSCREEN" or command$="CS"
         ink -1,0
         box window.left,window.top,window.right,window.bottom
         ink 0,0
         status.position.x=0
         status.position.y=0
         status.position.z=0
         status.heading=0.00
         status.pitch=0.00
         status.roll=0.00
         goto done_command
      endif
      if command$="CLEAN"
         ink -1,0
         box window.left,window.top,window.right,window.bottom
         ink 0,0
         goto done_command
      endif
      if command$="HOME"
         status.position.x=0
         status.position.y=0
         status.position.z=0
         goto done_command
      endif
      if command$="PI"
         build$="3.1415926535897932384626433832795"
         if len(strg$)>0
            strg$=build$+" "+strg$
         else
            strg$=build$
         endif
         goto done_command
      endif
      if command$="PENUP" or command$="PU"
         status.contact=0
         goto done_command
      endif
      if command$="PENDOWN" or command$="PD"
         status.contact=1
         goto done_command
      endif
      if command$="PENDOWN?" or command$="PENDOWNP"
         build$="false"
         if status.contact=1
            build$="true"
         endif
         if len(strg$)>0
            strg$=build$+" "+strg$
         else
            strg$=build$
         endif
         goto done_command
      endif
      if command$="PENPAINT" or command$="PPT"
         status.contact=1
         status.penmode="paint"
         goto done_command
      endif
      if command$="PENERASE" or command$="PE"
         status.contact=1
         status.penmode="erase"
         goto done_command
      endif
      if command$="PENREVERSE" or command$="PX"
         status.contact=1
         status.penmode="reverse"
         goto done_command
      endif
      if command$="PENNORMAL"
         status.contact=1
         status.penmode="paint"
         goto done_command
      endif
      if command$="PENMODE"
         build$=status.penmode
         if len(strg$)>0
            strg$=build$+" "+strg$
         else
            strg$=build$
         endif
         goto done_command
      endif
      if command$="PENCOLOR" or command$="PENCOLOUR" or command$="PC"
         build$="["+str$(rgbr(status.pencolor))+" "+str$(rgbg(status.pencolor))+" "+str$(rgbb(status.pencolor))+"]"
         if len(strg$)>0
            strg$=build$+" "+strg$
         else
            strg$=build$
         endif
         goto done_command
      endif
      if command$="FLOODCOLOR" or command$="FLOODCOLOUR"
         build$="["+str$(rgbr(status.floodcolor))+" "+str$(rgbg(status.floodcolor))+" "+str$(rgbb(status.floodcolor))+"]"
         if len(strg$)>0
            strg$=build$+" "+strg$
         else
            strg$=build$
         endif
         goto done_command
      endif
      if command$="SCREENCOLOR" or command$="SCREENCOLOUR"
         build$="["+str$(rgbr(status.screencolor))+" "+str$(rgbg(status.screencolor))+" "+str$(rgbb(status.screencolor))+"]"
         if len(strg$)>0
            strg$=build$+" "+strg$
         else
            strg$=build$
         endif
         goto done_command
      endif
      if command$="MOUSEPOS"
         strg$="["+str$(mousex()-screen width()/2)+" "+str$(screen height()/2-mousey())+"] "+strg$
         goto done_command
      endif
      if command$="POS"
         strg$="["+str$(status.position.x)+" "+str$(status.position.y)+"] "+strg$
         goto done_command
      endif
      if command$="POSXYZ"
         strg$="["+str$(status.position.x)+" "+str$(status.position.y)+" "+str$(status.position.z)+"] "+strg$
         goto done_command
      endif
      if command$="XCOR"
         if len(strg$)>0
            strg$=str$(status.position.x)+" "+strg$
         else
            strg$=str$(status.position.x)
         endif
         goto done_command
      endif
      if command$="YCOR"
         if len(strg$)>0
            strg$=str$(status.position.y)+" "+strg$
         else
            strg$=str$(status.position.y)
         endif
         goto done_command
      endif
      if command$="ZCOR"
         if len(strg$)>0
            strg$=str$(status.position.z)+" "+strg$
         else
            strg$=str$(status.position.z)
         endif
         goto done_command
      endif
      if command$="HEADING"
         strg$=str$(wrapvalue(status.heading))
         goto done_command
      endif
      if command$="WORD?" or command$="WORDP"
         strg$=get_parameters$(original_command$,strg$,"S")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         build$="false"
         parameter$(base_parameter+1)=getval(parameter$(base_parameter+1))
         if left$(parameter$(base_parameter+1),1)=chr$(34) then build$="true"
         if len(strg$)>0
            strg$=build$+" "+strg$
         else
            strg$=build$
         endif
         goto done_command
      endif
      if command$="LIST?" or command$="LISTP"
         strg$=get_parameters$(original_command$,strg$,"S")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         build$="false"
         parameter$(base_parameter+1)=getval(parameter$(base_parameter+1))
         if is_list(parameter$(base_parameter+1)) then build$="true"
         if len(strg$)>0
            strg$=build$+" "+strg$
         else
            strg$=build$
         endif
         goto done_command
      endif
      if command$="ARRAY?" or command$="ARRAYP"
         strg$=get_parameters$(original_command$,strg$,"S")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         build$="false"
         parameter$(base_parameter+1)=getval(parameter$(base_parameter+1))
         if is_array(parameter$(base_parameter+1)) then build$="true"
         if len(strg$)>0
            strg$=build$+" "+strg$
         else
            strg$=build$
         endif
         goto done_command
      endif
      if command$="EMPTY?" or command$="EMPTYP"
         strg$=get_parameters$(original_command$,strg$,"S")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         build$="false"
         parameter$(base_parameter+1)=getval(parameter$(base_parameter+1))
         if len(parameter$(base_parameter+1))=1
            if is_number(parameter$(base_parameter+1))=0 then build$="true"
         else
            if len(parameter$(base_parameter+1))=2 and left$(parameter$(base_parameter+1),1)="[" then build$="true"
         endif
         if len(strg$)>0
            strg$=build$+" "+strg$
         else
            strg$=build$
         endif
         goto done_command
      endif
      if command$="SETX"
         strg$=get_parameters$(original_command$,strg$,"N")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         oldx#=status.position.x
         oldy#=status.position.y
         oldz#=status.position.z
         status.position.x=val(parameter$(base_parameter+1))
         if status.contact=1 then drawline(oldx#,oldy#,status.position.x,status.position.y)
         goto done_command
      endif
      if command$="SETY"
         strg$=get_parameters$(original_command$,strg$,"N")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         oldx#=status.position.x
         oldy#=status.position.y
         oldz#=status.position.z
         status.position.y=val(parameter$(base_parameter+1))
         if status.contact=1 then drawline(oldx#,oldy#,status.position.x,status.position.y)
         goto done_command
      endif
      if command$="SETZ"
         strg$=get_parameters$(original_command$,strg$,"N")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         oldx#=status.position.x
         oldy#=status.position.y
         oldz#=status.position.z
         status.position.z=val(parameter$(base_parameter+1))
         if status.contact=1 then drawline(oldx#,oldy#,status.position.x,status.position.y)
         goto done_command
      endif
      if command$="FORWARD" or command$="FD"
         strg$=get_parameters$(original_command$,strg$,"N")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         oldx#=status.position.x
         oldy#=status.position.y
         oldz#=status.position.z
         status.position.x=status.position.x+val(parameter$(base_parameter+1))*sin(status.heading)
         status.position.y=status.position.y+val(parameter$(base_parameter+1))*cos(status.heading)
         if status.contact=1 then drawline(oldx#,oldy#,status.position.x,status.position.y)
         goto done_command
      endif
      if command$="LEFT" or command$="LT"
         strg$=get_parameters$(original_command$,strg$,"N")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         status.heading=status.heading-val(parameter$(base_parameter+1))
         goto done_command
      endif
      if command$="RIGHT" or command$="RT"
         strg$=get_parameters$(original_command$,strg$,"N")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         status.heading=status.heading+val(parameter$(base_parameter+1))
         goto done_command
      endif
      if command$="BACK" or command$="BK"
         strg$=get_parameters$(original_command$,strg$,"N")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         oldx#=status.position.x
         oldy#=status.position.y
         oldz#=status.position.z
         status.position.x=status.position.x-val(parameter$(base_parameter+1))*sin(status.heading)
         status.position.y=status.position.y-val(parameter$(base_parameter+1))*cos(status.heading)
         if status.contact=1 then drawline(oldx#,oldy#,status.position.x,status.position.y)
         goto done_command
      endif
      if command$="SQRT"
         strg$=get_parameters$(original_command$,strg$,"N")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         build$=str$((sqrt(val(parameter$(base_parameter+1)))))
         if len(strg$)>0
            strg$=build$+" "+strg$
         else
            strg$=build$
         endif
         goto done_command
      endif
      if command$="ABS"
         strg$=get_parameters$(original_command$,strg$,"N")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         build$=str$((abs(val(parameter$(base_parameter+1)))))
         if len(strg$)>0
            strg$=build$+" "+strg$
         else
            strg$=build$
         endif
         goto done_command
      endif
      if command$="INT"
         strg$=get_parameters$(original_command$,strg$,"N")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         build$=str$((int(val(parameter$(base_parameter+1)))))
         if len(strg$)>0
            strg$=build$+" "+strg$
         else
            strg$=build$
         endif
         goto done_command
      endif
      if command$="ROUND"
         strg$=get_parameters$(original_command$,strg$,"N")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         build$=str$((int(0.5+val(parameter$(base_parameter+1)))))
         if len(strg$)>0
            strg$=build$+" "+strg$
         else
            strg$=build$
         endif
         goto done_command
      endif
      if command$="MINUS"
         strg$=get_parameters$(original_command$,strg$,"N")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         build$=str$((0-(val(parameter$(base_parameter+1)))))
         if len(strg$)>0
            strg$=build$+" "+strg$
         else
            strg$=build$
         endif
         goto done_command
      endif
      if command$="SIGN"
         strg$=get_parameters$(original_command$,strg$,"N")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         build$="0"
         if val(parameter$(base_parameter+1))<0 then build$="-1"
         if val(parameter$(base_parameter+1))>0 then build$="1"
         if len(strg$)>0
            strg$=build$+" "+strg$
         else
            strg$=build$
         endif
         goto done_command
      endif
      if command$="LOG10"
         strg$=get_parameters$(original_command$,strg$,"N")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         build$=str$(log(val(parameter$(base_parameter+1)),10,6))
         if len(strg$)>0
            strg$=build$+" "+strg$
         else
            strg$=build$
         endif
         goto done_command
      endif
      if command$="LN"
         strg$=get_parameters$(original_command$,strg$,"N")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         build$=str$(log(val(parameter$(base_parameter+1)),2.71828183,6))
         if len(strg$)>0
            strg$=build$+" "+strg$
         else
            strg$=build$
         endif
         goto done_command
      endif
      if command$="TAN"
         strg$=get_parameters$(original_command$,strg$,"N")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         build$=str$(tan(val(parameter$(base_parameter+1))))
         if len(strg$)>0
            strg$=build$+" "+strg$
         else
            strg$=build$
         endif
         goto done_command
      endif
      if command$="SIN"
         strg$=get_parameters$(original_command$,strg$,"N")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         build$=str$(sin(val(parameter$(base_parameter+1))))
         if len(strg$)>0
            strg$=build$+" "+strg$
         else
            strg$=build$
         endif
         goto done_command
      endif
      if command$="COS"
         strg$=get_parameters$(original_command$,strg$,"N")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         build$=str$(cos(val(parameter$(base_parameter+1))))
         if len(strg$)>0
            strg$=build$+" "+strg$
         else
            strg$=build$
         endif
         goto done_command
      endif
      if command$="ARCTAN"
         strg$=get_parameters$(original_command$,strg$,"N")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         build$=str$(atan(val(parameter$(base_parameter+1))))
         if len(strg$)>0
            strg$=build$+" "+strg$
         else
            strg$=build$
         endif
         goto done_command
      endif
      if command$="ARCSIN"
         strg$=get_parameters$(original_command$,strg$,"N")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         build$=str$(asin(val(parameter$(base_parameter+1))))
         if len(strg$)>0
            strg$=build$+" "+strg$
         else
            strg$=build$
         endif
         goto done_command
      endif
      if command$="ARCCOS"
         strg$=get_parameters$(original_command$,strg$,"N")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         build$=str$(acos(val(parameter$(base_parameter+1))))
         if len(strg$)>0
            strg$=build$+" "+strg$
         else
            strg$=build$
         endif
         goto done_command
      endif
      if command$="NOT"
         strg$=get_parameters$(original_command$,strg$,"B")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         if parameter$(base_parameter+1)="FALSE" then build$="true" else build$="false"
         if len(strg$)>0
            strg$=build$+" "+strg$
         else
            strg$=build$
         endif
         goto done_command
      endif
      if command$="RANDOM"
         strg$=get_parameters$(original_command$,strg$,"I")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         if val(parameter$(base_parameter+1))<1 then parameter$(base_parameter+1)="1"
         build$=str$(rnd(val(parameter$(base_parameter+1))-1))
         if len(strg$)>0
            strg$=build$+" "+strg$
         else
            strg$=build$
         endif
         goto done_command
      endif
      if command$="EXP"
         strg$=get_parameters$(original_command$,strg$,"N")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         build$=str$(2.71828183^val(parameter$(base_parameter+1)))
         if len(strg$)>0
            strg$=build$+" "+strg$
         else
            strg$=build$
         endif
         goto done_command
      endif
      if command$="WAIT"
         strg$=get_parameters$(original_command$,strg$,"N")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         sleep val(parameter$(base_parameter+1))/60.0*1000.0
         goto done_command
      endif
      if command$="BYE"
         end
         `goto done_command
      endif
      if command$="PRINT" or command$="SHOW" or command$="TYPE"
         strg$=get_parameters$(original_command$,strg$,"S")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         if command$="PRINT" or command$="TYPE"
            if left$(parameter$(base_parameter+1),1)="["
               parameter$(base_parameter+1)=right$(parameter$(base_parameter+1),len(parameter$(base_parameter+1))-1)
               if right$(parameter$(base_parameter+1),1)="]" then parameter$(base_parameter+1)=left$(parameter$(base_parameter+1),len(parameter$(base_parameter+1))-1)
            endif
         endif
         if command$="PRINT" or command$="SHOW"
            output(parameter$(base_parameter+1))
         else
            type0(parameter$(base_parameter+1))
         endif
         goto done_command
      endif
      if command$="SETPOS"
         strg$=get_parameters$(original_command$,strg$,"L")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         if left$(parameter$(base_parameter+1),1)="[" then parameter$(base_parameter+1)=right$(parameter$(base_parameter+1),len(parameter$(base_parameter+1))-1)
         if right$(parameter$(base_parameter+1),1)="]" then parameter$(base_parameter+1)=left$(parameter$(base_parameter+1),len(parameter$(base_parameter+1))-1)
         oldx#=status.position.x
         oldy#=status.position.y
         oldz#=status.position.z
         status.position.x=val(getval(first(parameter$(base_parameter+1))))
         parameter$(base_parameter+1)=pop(parameter$(base_parameter+1))
         status.position.y=val(getval(first(parameter$(base_parameter+1))))
         if status.contact=1 then drawline(oldx#,oldy#,status.position.x,status.position.y)
         goto done_command
      endif
      if command$="TOWARDS"
         strg$=get_parameters$(original_command$,strg$,"L")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         if left$(parameter$(base_parameter+1),1)="[" then parameter$(base_parameter+1)=right$(parameter$(base_parameter+1),len(parameter$(base_parameter+1))-1)
         if right$(parameter$(base_parameter+1),1)="]" then parameter$(base_parameter+1)=left$(parameter$(base_parameter+1),len(parameter$(base_parameter+1))-1)
         targetx#=val(getval(first(parameter$(base_parameter+1))))
         parameter$(base_parameter+1)=pop(parameter$(base_parameter+1))
         targety#=val(getval(first(parameter$(base_parameter+1))))
         targetangle#=wrapvalue(atanfull(-(targetx#-status.position.x),targety#-status.position.y))
         angle#=wrapvalue(status.heading)
         turn#=angle#-targetangle#
         while turn#<0
            inc turn#,360
         endwhile
         while turn#>=360
            dec turn#,360
         endwhile
         build$=str$(turn#)
         strg$=build$+" "+strg$
         goto done_command
      endif
      if command$="DISTANCE"
         strg$=get_parameters$(original_command$,strg$,"L")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         if left$(parameter$(base_parameter+1),1)="[" then parameter$(base_parameter+1)=right$(parameter$(base_parameter+1),len(parameter$(base_parameter+1))-1)
         if right$(parameter$(base_parameter+1),1)="]" then parameter$(base_parameter+1)=left$(parameter$(base_parameter+1),len(parameter$(base_parameter+1))-1)
         targetx#=val(getval(first(parameter$(base_parameter+1))))
         parameter$(base_parameter+1)=pop(parameter$(base_parameter+1))
         targety#=val(getval(first(parameter$(base_parameter+1))))
         distance#=sqrt((targetx#-status.position.x)^2+(targety#-status.position.y)^2)
         build$=str$(distance#)
         strg$=build$+" "+strg$
         goto done_command
      endif
      if command$="SETPOSXYZ"
         strg$=get_parameters$(original_command$,strg$,"L")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         if left$(parameter$(base_parameter+1),1)="[" then parameter$(base_parameter+1)=right$(parameter$(base_parameter+1),len(parameter$(base_parameter+1))-1)
         if right$(parameter$(base_parameter+1),1)="]" then parameter$(base_parameter+1)=left$(parameter$(base_parameter+1),len(parameter$(base_parameter+1))-1)
         oldx#=status.position.x
         oldy#=status.position.y
         oldz#=status.position.z
         status.position.x=val(getval(first(parameter$(base_parameter+1))))
         parameter$(base_parameter+1)=pop(parameter$(base_parameter+1))
         status.position.y=val(getval(first(parameter$(base_parameter+1))))
         parameter$(base_parameter+1)=pop(parameter$(base_parameter+1))
         status.position.z=val(getval(first(parameter$(base_parameter+1))))
         if status.contact=1 then drawline(oldx#,oldy#,status.position.x,status.position.y)
         goto done_command
      endif
      if command$="SETPENCOLOR" or command$="SETPENCOLOUR" or command$="SETPC"
         strg$=get_parameters$(original_command$,strg$,"S")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         if is_list(parameter$(base_parameter+1))=1
            if left$(parameter$(base_parameter+1),1)="[" then parameter$(base_parameter+1)=right$(parameter$(base_parameter+1),len(parameter$(base_parameter+1))-1)
            if right$(parameter$(base_parameter+1),1)="]" then parameter$(base_parameter+1)=left$(parameter$(base_parameter+1),len(parameter$(base_parameter+1))-1)
            red=val(getval(first(parameter$(base_parameter+1))))
            parameter$(base_parameter+1)=pop(parameter$(base_parameter+1))
            green=val(getval(first(parameter$(base_parameter+1))))
            parameter$(base_parameter+1)=pop(parameter$(base_parameter+1))
            blue=val(getval(first(parameter$(base_parameter+1))))
            status.pencolor=rgb(red,green,blue)
         else
            c$=getval(parameter$(base_parameter+1))
            if is_integer(c$)=1
               c=val(c$)
               status.pencolor=color(c)
            endif
         endif
         goto done_command
      endif
      if command$="SETFLOODCOLOR" or command$="SETFLOODCOLOUR" or command$="SETFC"
         strg$=get_parameters$(original_command$,strg$,"S")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         if is_list(parameter$(base_parameter+1))=1
            if left$(parameter$(base_parameter+1),1)="[" then parameter$(base_parameter+1)=right$(parameter$(base_parameter+1),len(parameter$(base_parameter+1))-1)
            if right$(parameter$(base_parameter+1),1)="]" then parameter$(base_parameter+1)=left$(parameter$(base_parameter+1),len(parameter$(base_parameter+1))-1)
            red=val(getval(first(parameter$(base_parameter+1))))
            parameter$(base_parameter+1)=pop(parameter$(base_parameter+1))
            green=val(getval(first(parameter$(base_parameter+1))))
            parameter$(base_parameter+1)=pop(parameter$(base_parameter+1))
            blue=val(getval(first(parameter$(base_parameter+1))))
            status.floodcolor=rgb(red,green,blue)
         else
            c$=getval(parameter$(base_parameter+1))
            if is_integer(c$)=1
               c=val(c$)
               status.floodcolor=color(c)
            endif
         endif
         goto done_command
      endif
      if command$="SETSCREENCOLOR" or command$="SETSCREENCOLOUR" or command$="SETSC"
         strg$=get_parameters$(original_command$,strg$,"S")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         if is_list(parameter$(base_parameter+1))=1
            if left$(parameter$(base_parameter+1),1)="[" then parameter$(base_parameter+1)=right$(parameter$(base_parameter+1),len(parameter$(base_parameter+1))-1)
            if right$(parameter$(base_parameter+1),1)="]" then parameter$(base_parameter+1)=left$(parameter$(base_parameter+1),len(parameter$(base_parameter+1))-1)
            red=val(getval(first(parameter$(base_parameter+1))))
            parameter$(base_parameter+1)=pop(parameter$(base_parameter+1))
            green=val(getval(first(parameter$(base_parameter+1))))
            parameter$(base_parameter+1)=pop(parameter$(base_parameter+1))
            blue=val(getval(first(parameter$(base_parameter+1))))
            status.screencolor=rgb(red,green,blue)
            ink status.screencolor,0
            box window.left, window.top, window.right, window.bottom
         else
            c$=getval(parameter$(base_parameter+1))
            if is_integer(c$)=1
               c=val(c$)
               status.screencolor=color(c)
               ink status.screencolor,0
               box window.left, window.top, window.right, window.bottom
            endif
         endif
         goto done_command
      endif
      if command$="SETHEADING" or command$="SETH"
         strg$=get_parameters$(original_command$,strg$,"N")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         status.heading=val(parameter$(base_parameter+1))
         goto done_command
      endif
      if command$="REPEAT"
         if upper$(first(strg$))="FOREVER"
            forever=1
            strg$=pop(strg$)
            strg$=get_parameters$(original_command$,strg$,"L")
         else
            strg$=get_parameters$(original_command$,strg$,"NL")
         endif
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         if forever=0
            lock pixels
            for n=1 to val(parameter$(base_parameter+1))
               parse(left$(right$(parameter$(base_parameter+2),len(parameter$(base_parameter+2))-1),len(parameter$(base_parameter+2))-2))
            next n
            unlock pixels
         else
            do
               parse(left$(right$(parameter$(base_parameter+1),len(parameter$(base_parameter+1))-1),len(parameter$(base_parameter+1))-2))
               sync
            loop
         endif
         goto done_command
      endif
      if command$="IF"
         strg$=get_parameters$(original_command$,strg$,"BL")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         if upper$(parameter$(base_parameter+1))="TRUE"
            parse(left$(right$(parameter$(base_parameter+2),len(parameter$(base_parameter+2))-1),len(parameter$(base_parameter+2))-2))
         endif
         goto done_command
      endif
      if command$="IFELSE"
         strg$=get_parameters$(original_command$,strg$,"BLL")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         if upper$(parameter$(base_parameter+1))="TRUE"
            parse(left$(right$(parameter$(base_parameter+2),len(parameter$(base_parameter+2))-1),len(parameter$(base_parameter+2))-2))
         else
            parse(left$(right$(parameter$(base_parameter+3),len(parameter$(base_parameter+3))-1),len(parameter$(base_parameter+3))-2))
         endif
         goto done_command
      endif
      if command$="RUN"
         strg$=get_parameters$(original_command$,strg$,"L")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         parse(left$(right$(parameter$(base_parameter+1),len(parameter$(base_parameter+1))-1),len(parameter$(base_parameter+1))-2))
         goto done_command
      endif
      if command$="AND"
         strg$=get_parameters$(original_command$,strg$,"BB")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         if parameter$(base_parameter+1)="TRUE" and parameter$(base_parameter+2)="TRUE" then build$="true" else build$="false"
         if len(strg$)>0
            strg$=build$+" "+strg$
         else
            strg$=build$
         endif
         goto done_command
      endif
      if command$="LIST"
         strg$=get_parameters$(original_command$,strg$,"SS")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         for n=1 to 2
            if left$(parameter$(base_parameter+n),1)=chr$(34)
               parameter$(base_parameter+n)=right$(parameter$(base_parameter+n),len(parameter$(base_parameter+n))-1)
            else
               if left$(parameter$(base_parameter+n),1)=":"
                  parameter$(base_parameter+n)=getval(parameter$(base_parameter+n))
               endif
            endif
         next n
         build$="["
         for n=1 to 1
            build$=build$+parameter$(base_parameter+1)+" "
         next n
         build$=build$+parameter$(base_parameter+n)+"]"
         if len(strg$)>0
            strg$=build$+" "+strg$
         else
            strg$=build$
         endif
         goto done_command
      endif
      if command$="OR"
         strg$=get_parameters$(original_command$,strg$,"BB")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         if parameter$(base_parameter+1)="TRUE" or parameter$(base_parameter+2)="TRUE" then build$="true" else build$="false"
         if len(strg$)>0
            strg$=build$+" "+strg$
         else
            strg$=build$
         endif
         goto done_command
      endif
      if command$="SUM"
         strg$=get_parameters$(original_command$,strg$,"NN")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         build$=str$((val(parameter$(base_parameter+1))+val(parameter$(base_parameter+2))))
         if len(strg$)>0
            strg$=build$+" "+strg$
         else
            strg$=build$
         endif
         goto done_command
      endif
      if command$="DIFFERENCE"
         strg$=get_parameters$(original_command$,strg$,"NN")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         build$=str$((val(parameter$(base_parameter+1))-val(parameter$(base_parameter+2))))
         if len(strg$)>0
            strg$=build$+" "+strg$
         else
            strg$=build$
         endif
         goto done_command
      endif
      if command$="PRODUCT"
         strg$=get_parameters$(original_command$,strg$,"NN")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         build$=str$((val(parameter$(base_parameter+1))*val(parameter$(base_parameter+2))))
         if len(strg$)>0
            strg$=build$+" "+strg$
         else
            strg$=build$
         endif
         goto done_command
      endif
      if command$="QUOTIENT"
         strg$=get_parameters$(original_command$,strg$,"NN")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         build$=str$((val(parameter$(base_parameter+1))/val(parameter$(base_parameter+2))))
         if len(strg$)>0
            strg$=build$+" "+strg$
         else
            strg$=build$
         endif
         goto done_command
      endif
      if command$="POWER"
         strg$=get_parameters$(original_command$,strg$,"NN")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         build$=str$((val(parameter$(base_parameter+1))^val(parameter$(base_parameter+2))))
         if len(strg$)>0
            strg$=build$+" "+strg$
         else
            strg$=build$
         endif
         goto done_command
      endif
      if command$="LESS?" or command$="LESSP"
         strg$=get_parameters$(original_command$,strg$,"NN")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         build$="false"
        ` output("<"+parameter$(base_parameter+1)+">")
        ` output("<"+parameter$(base_parameter+2)+">")
         if val(parameter$(base_parameter+1))<val(parameter$(base_parameter+2)) then build$="true"
         if len(strg$)>0
            strg$=build$+" "+strg$
         else
            strg$=build$
         endif
         goto done_command
      endif
      if command$="GREATER?" or command$="GREATERP"
         strg$=get_parameters$(original_command$,strg$,"NN")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         build$="false"
         if val(parameter$(base_parameter+1))>val(parameter$(base_parameter+2)) then build$="true"
         if len(strg$)>0
            strg$=build$+" "+strg$
         else
            strg$=build$
         endif
         goto done_command
      endif
      if command$="EQUAL?" or command$="EQUALP"
         strg$=get_parameters$(original_command$,strg$,"SS")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         build$="false"
         if parameter$(base_parameter+1)=parameter$(base_parameter+2) then build$="true"
         if build$="false"
            if getval(parameter$(base_parameter+1))=getval(parameter$(base_parameter+2)) then build$="true"
         endif
         if len(strg$)>0
            strg$=build$+" "+strg$
         else
            strg$=build$
         endif
         goto done_command
      endif
      if command$="REMAINDER" or command$="MODULO"
         strg$=get_parameters$(original_command$,strg$,"II")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         negative=0
         if (command$="REMAINDER" and left$(parameter$(base_parameter+1),1)="-") or (command$="MODULO" and left$(parameter$(base_parameter+2),1)="-") then negative=1
         if left$(parameter$(base_parameter+1),1)="-" then parameter$(base_parameter+1)=right$(parameter$(base_parameter+1),len(parameter$(base_parameter+1))-1)
         if left$(parameter$(base_parameter+2),1)="-" then parameter$(base_parameter+2)=right$(parameter$(base_parameter+2),len(parameter$(base_parameter+2))-1)
         tempx=int(val(parameter$(base_parameter+1))/val(parameter$(base_parameter+2)))
         build$=str$(val(parameter$(base_parameter+1))-val(parameter$(base_parameter+2))*tempx)
         if negative=1 then build$="-"+build$
         if len(strg$)>0
            strg$=build$+" "+strg$
         else
            strg$=build$
         endif
         goto done_command
      endif
      if command$="SETXY"
         strg$=get_parameters$(original_command$,strg$,"NN")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         oldx#=status.position.x
         oldy#=status.position.y
         oldz#=status.position.z
         status.position.x=val(parameter$(base_parameter+1))
         status.position.y=val(parameter$(base_parameter+2))
         if status.contact=1 then drawline(oldx#,oldy#,status.position.x,status.position.y)
         goto done_command
      endif
      if command$="SETXYZ"
         strg$=get_parameters$(original_command$,strg$,"NNN")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         oldx#=status.position.x
         oldy#=status.position.y
         oldz#=status.position.z
         status.position.x=val(parameter$(base_parameter+1))
         status.position.y=val(parameter$(base_parameter+2))
         status.position.z=val(parameter$(base_parameter+3))
         if status.contact=1 then drawline(oldx#,oldy#,status.position.x,status.position.y)
         goto done_command
      endif
      if command$="MAKE"
         strg$=get_parameters$(original_command$,strg$,"SN")
         if error$<>"" then prepareexit(base_parameter):exitfunction strg$
         found=0
         infunction=0
         for n=0 to array count(edall$(0))
            if upper$(left$(edall$(n),2))="TO" and infunction=0
               infunction=1
            endif
            if infunction=1 and upper$(left$(edall$(n),3))="END"
               infunction=0
            endif
            if infunction=0 and upper$(left$(edall$(n),5+len(parameter$(base_parameter+1))))="MAKE "+upper$(parameter$(base_parameter+1))
               edall$(n)="Make "+parameter$(base_parameter+1)+" "+parameter$(base_parameter+2)
               found=1
               exit
            endif
         next n
         if found=0
            array insert at bottom edall$(0)
            edall$(array count(edall$(0)))="Make "+parameter$(base_parameter+1)+" "+parameter$(base_parameter+2)
         endif
         goto done_command
      endif
      if command$="TO"
         name$=first(strg$)
         build$="TO "+name$
        for n=0 to array count(edall$(0))
            if upper$(left$(edall$(n),2))="TO"
               name1$=first(pop(edall$(n)))
               if upper$(name1$)=upper$(name$)
                  while endline=0
                     if upper$(left$(edall$(n),3))="END"
                        endline=1
                     endif
                     array delete element edall$(0),n
                  endwhile
               endif
            endif
         next n
         strg$=pop(strg$)
         while len(strg$)>0
            para$=first(strg$)
            strg$=pop(strg$)
            if left$(para$,1)<>":"
               error$="NOLIKE"
               error1$=para$
               prepareexit(base_parameter):exitfunction "[]"
            else
               build$=build$+para$
            endif
         endwhile
         array insert at bottom edall$(0)
         edall$(array count(edall$(0)))=build$
         make_function=1
         is_command=1
         goto done_command
      endif
   endif
   if command$="END"
      if make_function=1
         make_function=0
         goto done_command
      endif
   endif
   if make_function=0
      `print "Looking up command ",command$
     for n=0 to array count(edall$(0))
            `print edall$(n)
         if upper$(left$(edall$(n),2))="TO"
            name$=first(pop(edall$(n)))
 
            if command$=upper$(name$) and is_command=0
               is_command=1
               while endline=0
                  inc n
                  if n>array count(edall$(0))
                     exit
                  endif
                  if upper$(left$(edall$(n),3))="END"
                     endline=1
                  else
                     parse(edall$(n))
                  endif
               endwhile
            endif
         endif
      next n
   endif
   if is_command=0 and make_function=0
      error$="NOTCOM"
      prepareexit(base_parameter):exitfunction original_command$
   endif
   done_command:
   prepareexit(base_parameter)
   `print "Exiting with string:[",strg$,"]"
   if make_function=1 then strg$=""
   if len(strg$)>0 then strg$=parse(strg$)
endfunction strg$
 
function prepareexit(b)
   while array count(parameter$(0))>b
      array delete element parameter$(0), array count(parameter$(0))
   endwhile
endfunction
 
function pop(strg$)
   while left$(strg$,1)=" "
      strg$=right$(strg$,len(strg$)-1)
   endwhile
   while right$(strg$,1)=" "
      strg$=left$(strg$,len(strg$)-1)
   endwhile
   if mid$(strg$,1)="+" or (mid$(strg$,1)="-" and contains_non_number(mid$(strg$,2))) or mid$(strg$,1)="*" or mid$(strg$,1)="/"
      exitfunction right$(strg$,len(strg$)-1)
   endif
   if mid$(strg$,1)="["
      char$="["
      until_close=1
      strg$=right$(strg$,len(strg$)-1)
   endif
   if mid$(strg$,1)="{" and until_close=0
      char$="{"
      until_close=1
      strg$=right$(Strg$,len(strg$)-1)
   endif
   list$=char$
   for n=1 to len(strg$)
      if mid$(strg$,n)="["
         list$=list$+"["
      else
         if mid$(strg$,n)="{"
            list$=list$+"{"
         else
            if mid$(strg$,n)="]"
               if len(list$)=0
                  output("unexpected ']'")
                  error$="1"
                  exitfunction
               else
                  if right$(list$,1)="["
                     list$=left$(list$,len(list$)-1)
                  else
                     output("unexpected ']'")
                     error$="1"
                     exitfunction
                  endif
               endif
            else
               if mid$(strg$,n)="}"
                  if len(list$)=0
                     output("unexpected '}'")
                     error$="1"
                     exitfunction
                  else
                     if right$(list$,1)="{"
                        list$=left$(list$,len(list$)-1)
                     else
                        output("unexpected '}'")
                        error$="1"
                        exitfunction
                     endif
                  endif
               endif
            endif
         endif
      endif
      if until_close=0
         if mid$(strg$,n)=" " or mid$(strg$,n)="," or mid$(strg$,n)="+" or (mid$(strg$,n)="-" and n>1) or mid$(strg$,n)="*" or mid$(strg$,n)="/"
            exitfunction right$(strg$,len(strg$)-n)
         endif
         if mid$(strg$,n)="[" or mid$(strg$,n)="]" or mid$(strg$,n)="{" or mid$(strg$,n)="}"
            exitfunction  right$(strg$,len(strg$)-n+1)
         endif
      else
         if list$=""
            exitfunction right$(strg$,len(strg$)-n)
         endif
      endif
   next n
endfunction ""
 
function first(strg$)
   while left$(strg$,1)=" "
      strg$=right$(strg$,len(strg$)-1)
   endwhile
   while right$(strg$,1)=" "
      strg$=left$(strg$,len(strg$)-1)
   endwhile
   error$=""
   if mid$(strg$,1)="+" or (mid$(strg$,1)="-" and contains_non_number(mid$(strg$,2))) or mid$(strg$,1)="*" or mid$(strg$,1)="/"
      exitfunction mid$(strg$,1)
   endif
   if mid$(strg$,1)="["
      char$="["
      until_close=1
      strg$=right$(Strg$,len(strg$)-1)
   else
      if mid$(strg$,1)="{" and until_close=0
         char$="{"
         until_close=1
         strg$=right$(Strg$,len(strg$)-1)
      endif
   endif
   list$=char$
   for n=1 to len(strg$)
      if mid$(strg$,n)="["
         list$=list$+"["
      else
         if mid$(strg$,n)="{"
            list$=list$+"{"
         else
            if mid$(strg$,n)="]"
               if len(list$)=0
                  output("unexpected ']'")
                  error$="1"
                  exitfunction
               else
                  if right$(list$,1)="["
                     list$=left$(list$,len(list$)-1)
                  else
                     output("unexpected ']'")
                     error$="1"
                     exitfunction
                  endif
               endif
            else
               if mid$(strg$,n)="}"
                  if len(list$)=0
                     output("unexpected '}'")
                     error$="1"
                     exitfunction
                  else
                     if right$(list$,1)="{"
                        list$=left$(list$,len(list$)-1)
                     else
                        output("unexpected '}'")
                        error$="1"
                        exitfunction
                     endif
                  endif
               endif
            endif
         endif
      endif
      if until_close=0
         if (mid$(strg$,n)=" " or mid$(strg$,n)="," or mid$(strg$,n)="+" or (mid$(strg$,n)="-" and n>1) or mid$(strg$,n)="*" or mid$(strg$,n)="/" or mid$(strg$,n)="[" or mid$(strg$,n)="]" or mid$(strg$,n)="{" or mid$(strg$,n)="}")
            exitfunction left$(strg$,n-1)
         endif
      else
         if list$=""
            exitfunction char$+left$(strg$,n)
         endif
      endif
   next n
endfunction strg$
 
function get_parameters$(command$,strg$,mylist$)
   if error$<>"" then exitfunction strg$
   not_enough=0
   num=0
   base_parameter=array count(parameter$(0))
   for n=1 to len(mylist$)
      if len(strg$)<1
         not_enough=1
         error$="NOTENOUGH"
         exitfunction
      endif
      array insert at bottom parameter$(0)
      ac=array count(parameter$(0))
      parameter$(ac)=first(strg$)
      `output("STRING:"+strg$)
      strg$=pop(strg$)
      com$=parameter$(ac)
      `output("STRING:"+strg$)
      if is_instruction(parameter$(ac)) or is_operator(first(strg$))
         strg$=parse(parameter$(ac)+" "+strg$)
         if error$="NOTINST" then error$=""
         if error$<>"" then exitfunction strg$
         parameter$(array count(parameter$(0)))=first(strg$)
         strg$=pop(strg$)
         if len(parameter$(array count(parameter$(0))))=0
            error$="NOOUTPUT"
            error1$=command$
            exitfunction com$
         endif
      endif
      if mid$(mylist$,n)="N" rem the instruction wants a number here
         parameter$(array count(parameter$(0)))=getval(parameter$(array count(parameter$(0))))
         if is_number(parameter$(array count(parameter$(0))))=0
            error$="NOLIKE"
            error1$=parameter$(array count(parameter$(0)))
            exitfunction command$
         endif
      endif
      if mid$(mylist$,n)="I" rem the instruction wants an integer here
         parameter$(array count(parameter$(0)))=getval(parameter$(array count(parameter$(0))))
         if is_integer(parameter$(array count(parameter$(0))))=0
            error$="NOLIKE"
            error1$=parameter$(array count(parameter$(0)))
            exitfunction command$
         endif
      endif
      if mid$(mylist$,n)="L" rem the instruction wants a list here
         if is_list(parameter$(array count(parameter$(0))))=0
            error$="NOLIKE"
            error1$=parameter$(array count(parameter$(0)))
            exitfunction command$
         endif
      endif
      if mid$(mylist$,n)="B" rem the instruction wants a list here
         if is_boolean(parameter$(array count(parameter$(0))))=0
            error$="NOLIKE"
            error1$=parameter$(array count(parameter$(0)))
            exitfunction command$
         else
            parameter$(array count(parameter$(0)))=upper$(parameter$(array count(parameter$(0))))
         endif
      endif
`      if mid$(mylist$,n)="S" rem the instruction wants a string here
`         if left$(parameter$(array count(parameter$(0))),5)="$str$"
`            parameter$(array count(parameter$(0)))=right$(parameter$(array count(parameter$(0))),len(parameter$(array count(parameter$(0))))-5)
`         endif
`      endif
 
   next n
endfunction strg$
 
function is_instruction(strg$)
   strg$=upper$(strg$)
   if left$(strg$,1)<>chr$(34) and left$(strg$,1)<>":" and left$(strg$,1)<>"[" and contains_non_number(strg$) and len(strg$)>0 and left$(strg$,1)<>"{" and left$(strg$,1)<>"(" and strg$<>"TRUE" and strg$<>"FALSE" and left$(strg$,5)<>"$STR$"
      exitfunction 1
   endif
endfunction 0
 
function contains_alpha(strg$)
   strg$=upper$(strg$)
   for n=1 to len(strg$)
      if mid$(strg$,n)="A" or mid$(strg$,n)="B" or mid$(strg$,n)="C" or mid$(strg$,n)="D" or mid$(strg$,n)="E" or mid$(strg$,n)="F" or mid$(strg$,n)="G" or mid$(strg$,n)="H" or mid$(strg$,n)="I" or mid$(strg$,n)="J" or mid$(strg$,n)="K" or mid$(strg$,n)="L" or mid$(strg$,n)="M" or mid$(strg$,n)="N" or mid$(strg$,n)="O" or mid$(strg$,n)="P" or mid$(strg$,n)="Q" or mid$(strg$,n)="R" or mid$(strg$,n)="S" or mid$(strg$,n)="T" or mid$(strg$,n)="U" or mid$(strg$,n)="V" or mid$(strg$,n)="W" or mid$(strg$,n)="X" or mid$(strg$,n)="Y" or mid$(strg$,n)="Z"
         exitfunction 1
      endif
   next n
endfunction 0
 
function contains_non_number(strg$)
   strg$=upper$(Strg$)
   for n=1 to len(strg$)
      if mid$(strg$,n)<>"0" and mid$(strg$,n)<>"1" and mid$(strg$,n)<>"2" and mid$(strg$,n)<>"3" and mid$(strg$,n)<>"4" and mid$(strg$,n)<>"5" and mid$(strg$,n)<>"6" and mid$(strg$,n)<>"7" and mid$(strg$,n)<>"8" and mid$(strg$,n)<>"9" and mid$(strg$,n)<>"." and mid$(strg$,n)<>"-"
         exitfunction 1
      endif
   next n
endfunction 0
function is_operator(strg$)
   if strg$="+" or strg$="-" or strg$="*" or strg$="/"
      exitfunction 1
   endif
endfunction 0
 
function clean_up(strg$)
   build$=""
   last_char=-1
   list$=""
   for n=1 to len(strg$)
      if mid$(strg$,n)="["
         list$=list$+"["
      else
         if mid$(strg$,n)="{"
            list$=list$+"{"
         else
            if mid$(strg$,n)="]"
               if len(list$)=0
                  output("unexpected ']'")
                  error$="1"
                  exitfunction
               else
                  if right$(list$,1)="["
                     list$=left$(list$,len(list$)-1)
                  else
                     output("unexpected ']'")
                     error$="1"
                     exitfunction
                  endif
               endif
            else
               if mid$(strg$,n)="}"
                  if len(list$)=0
                     output("unexpected '}'")
                     error$="1"
                     exitfunction
                  else
                     if right$(list$,1)="{"
                        list$=left$(list$,len(list$)-1)
                     else
                        output("unexpected '}'")
                        error$="1"
                        exitfunction
                     endif
                  endif
               endif
            endif
         endif
      endif
      if mid$(strg$,n)=" "
         if last_char=n-1 or instring=1
            if (mid$(strg$,n+1)<>"," and mid$(strg$,n+1)<>"+" and mid$(strg$,n+1)<>"*" and mid$(strg$,n+1)<>"/" and mid$(strg$,n+1)<>"[" and mid$(strg$,n+1)<>"]" and mid$(strg$,n-1)<>"," and mid$(strg$,n-1)<>"+"  and mid$(strg$,n-1)<>"*" and mid$(strg$,n-1)<>"/" and mid$(strg$,n-1)<>"[" and mid$(strg$,n-1)<>"]") or instring=1
               build$=build$+mid$(strg$,n)
            endif
         endif
      else
         if mid$(strg$,n)=";" or mid$(strg$,n)="`" then goto end0
         last_char=n
         build$=build$+mid$(strg$,n)
      endif
   next n
   end0:
   if right$(build$,1)=" " then build$=left$(build$,len(build$)-1)
   while len(list$)>0
      build$=build$+mirror(right$(list$,1))
      list$=left$(list$,len(list$)-1)
   endwhile
endfunction build$
 
function mirror(char$)
  if char$="{" then exitfunction "}"
  if char$="[" then exitfunction "]"
  if char$="(" then exitfunction ")"
endfunction char$
 
function output(strg$)
   if left$(strg$,1)=chr$(34) then strg$=right$(strg$,len(strg$)-1)
   ink rgb(255-rgbr(status.screencolor),255-rgbg(status.screencolor),255-rgbb(status.screencolor)),0
`   ink 0,0
   if len(strg$)>0
   print strg$
   sync
   endif
endfunction
 
function type0(strg$)
   if left$(strg$,1)=chr$(34) then strg$=right$(strg$,len(strg$)-1)
   ink rgb(255-rgbr(status.screencolor),255-rgbg(status.screencolor),255-rgbb(status.screencolor)),0
   if len(strg$)>0
   print strg$;
   sync
   endif
endfunction
 
function infixs(char$)
   if char$="*" or char$="/" or char$="+" or char$="-" or char$="=" or char$="<" or char$=">" then exitfunction 1
endfunction 0
 
function getval(part$)
   error$=""
   if contains_non_number(part$)
      if left$(part$,1)=":"
         found=0
         infunction=0
         name$=right$(part$,len(part$)-1)
         for n=0 to array count(edall$(0))
            if upper$(left$(edall$(n),2))="TO" and infunction=0
               infunction=1
            endif
            if infunction=1 and upper$(left$(edall$(n),3))="END"
               infunction=0
            endif
            if infunction=0 and upper$(left$(edall$(n),6+len(name$)))="MAKE "+chr$(34)+upper$(name$)
               found=1
               p$=pop(pop(edall$(n)))
               exitfunction p$
            endif
         next n
         if found=0
            output(name$+" has no value")
            error$="UNDEF"
            exitfunction strg$
         endif
      else
         if left$(part$,1)=chr$(34)
            strg$=right$(part$,len(part$)-1)
            exitfunction strg$
         endif
      endif
   endif
endfunction part$
 
function is_integer(num$)
   if left$(num$,1)="-" then num$=right$(num$,len(num$)-1)
   for n=1 to len(num$)
      isint=0
      if mid$(num$,n)="0" or val(mid$(num$,n))>0 then isint=1
      if isint=0 then exitfunction 0
   next n
endfunction 1
 
function is_number(num$)
   if left$(num$,1)="-" then num$=right$(num$,len(num$)-1)
   if val(num$)>0 then exitfunction 1
   for n=1 to len(num$)
      isnum=0
      if mid$(num$,n)="0" or val(mid$(num$,n))>0 or mid$(num$,n)="." then isnum=1
      if isnum=0 then exitfunction 0
   next n
endfunction 1
 
function is_boolean(strg$)
   strg$=upper$(strg$)
   if strg$="TRUE" or strg$="FALSE" then exitfunction 1
endfunction 0
 
function is_list(strg$)
   if left$(strg$,1)="[" then exitfunction 1
endfunction 0
 
function is_array(strg$)
   if left$(strg$,1)="{" then exitfunction 1
endfunction 0
 
function drawline(x#,y#,x1#,y1#)
   if status.penmode="paint"
      ink status.pencolor,0
   endif
   if status.penmode="erase"
      ink status.screencolor,0
   endif
   line screen width()/2+x#,screen height()/2-y#,screen width()/2+x1#,screen height()/2-y1#
endfunction
 
function log(nr#, base#,acc)
 
   result# = 0.00
 
   for c = 0 to acc
      repeat
         inc result#, base#^(c*-1)
      until base#^result# >= nr#
      if base#^result# = nr#
         exitfunction result#
      else
         dec result#, base#^(c*-1)
      endif
   next c
 
endfunction result#
 
LogoData:
rem I used several setpos commands to spread out all the shapes (for less overlap)
rem red ink black background
data "run [setpencolor [255 0 0] setscreencolor 0]"
rem data "repeat 120 [type random 10]"
data "`Square"
data "forward 100"
data "right 90"
data "forward 100"
data "right 90"
data "forward 100"
data "right 90"
data "forward 100"
data "right 90"
data ""
data "pu setpos [-30 0] pd"
data ""
data "`Multiple commands per line - Triangle"
data "fd 100 lt 120 fd 100 lt 120 fd 100 lt 120"
data ""
data "pu setpos [0 0] pd"
data ""
data "`Circle"
data "Repeat 360 [ fd 1 rt 1 ]"
data ""
data "pu setpos [320 -200] pd"
data ""
data "`Repeat instructions - Hexagon"
data "repeat 6 [forward 100 right 60]"
data ""
data "pu setpos [300 0] pd"
data ""
data "`Pen Up/Down - Dashed Line"
data "repeat 4 [pendown forward 20 penup forward 20]"
data ""
data "pu setpos [200 -50] pd"
data ""
data "`Nested repeat functions - Dashed Octagon"
data "repeat 8[repeat 4[pd fd 20 pu fd 20] pd fd 20 lt 45]"
data ""
data "pu setpos [0 0] pd"
data ""
data "to pentagon"
data "repeat 5 [forward 100 left 72]"
data "end"
data "pentagon"
data ""
data "pu setpos [-280 -200] pd"
data ""
data "`Geometric Shape#1"
data "TO NestRep"
data "REPEAT 8 [REPEAT 8 [ FD 50 RT 45 ] RT 45]"
data "END"
data "`I added this to show that you can define and manipulate variables."
data "TO spiral"
data "make "x 10 repeat 225 [make "x sum :x 2 fd 6 rt quotient 720 :x]"
data "END"
data "pu setxy -240 150 pd spiral"
data "NestRep"
data "`Spirograph#1"
data "REPEAT 36 [ REPEAT 180 [ FD 2 RT 2 ] RT 10 ]"
data ""
data "pu setxy 280 200 pd"
data ""
data "`Snowflake"
data "REPEAT 6 [ REPEAT 360 [ FD 100 RT 100 ] RT 60 ]"
data "setpencolor 2 pu setpos mousepos pd repeat forever [ifelse less? distance mousepos 300[setheading 0 right towards mousepos] [right difference random 21 10] fd 3]"