BASIC Interpreter
A BASIC interpreter written in MUSHCode.
Commands:
@assert,
@break,
@create,
@emit,
@include,
@link,
@lock,
@lset,
@notify,
@parent,
@pemit,
@retry,
@set,
@trigger,
@wait.
Functions:
abs(),
acos(),
add(),
after(),
align(),
ansi(),
asin(),
atan(),
atan2(),
before(),
bound(),
cand(),
ceil(),
chr(),
cond(),
cor(),
cos(),
dec(),
decode64(),
die(),
e(),
edit(),
elements(),
encode64(),
extract(),
filterbool(),
first(),
firstof(),
floor(),
fold(),
grab(),
gt(),
gte(),
hasattr(),
hasattrp(),
hasattrpval(),
if(),
isint(),
isnum(),
lattr(),
lattrp(),
left(),
lexits(),
lit(),
ljust(),
lmath(),
ln(),
localize(),
log(),
map(),
member(),
mod(),
name(),
namegrab(),
not(),
null(),
num(),
pemit(),
pi(),
pos(),
rand(),
randword(),
regeditall(),
regmatch(),
regmatchi(),
repeat(),
rest(),
reswitch(),
revwords(),
round(),
s(),
setdiff(),
setq(),
setr(),
setunion(),
sin(),
sort(),
space(),
sqrt(),
squish(),
step(),
strlen(),
strmatch(),
switch(),
t(),
table(),
tan(),
trim(),
u(),
ucstr(),
v(),
wordpos(),
words().
Features:
#lambda.
Compatibility:
PennMUSH.
Instructions
Copy and paste the below code into a compatible MUSH or MUX.
MUSHCode for BASIC Interpreter
@create Basic chip
@lock Basic chip==me
&AUTHOR Basic chip=Walker@M*U*S*H. Email comments, changes, suggestions to walker@pennmush.org
@set Basic chip/AUTHOR=no_command
&CALC Basic chip=revwords(u(calc_rpn,u(convert,%0)))
@set Basic chip/CALC=no_command no_debug
&CALC_RPN Basic chip=localize(squish(if(regmatch(%0,^\\d+(?:\\.\\d+)?$),%0,[null(regmatch(,repeat(\(\),34),- 0 1 2 3 4 5 6 7 8 9 b c d e f g h i j k l m n o p q r s t u w x y z))]fold(process_rpn,%0,)))
@set Basic chip/CALC_RPN=no_command
&CONVERT Basic chip=revwords(localize(squish(if(regmatch(%0,^-?\\d+(\\.\\d+)?$),%0,[null(setq(0,,s,,o,,p,,a,))][u(process,%0)]))))
@set Basic chip/CONVERT=no_command
&DESCRIBE Basic chip=This is a math chip that contains processing routines for handling mathematical expressions. It is not really intended for direct use, but to be @parented to objects that need it.%r%r%b%bA function is a string, lowercase, followed by a (. Functions on math chip can take up to 10 arguments.%r%b%bA variable is a string of upper case characters and numbers - The first must be an upper case character. (e.g: VAL1 is a variable, 1VAL is 1 * the variable VAL)%r%rPre-set variables and functions:%r%b%bE, PI, sin(), cos(), tan(), sqrt(), abs(), acos(), asin(), atan(), ceil(), floor(), ln()%r%rCommon child-set attributes:%r%r[align(<30 45,%b%b&var`<NAME> child=<expr> -,Set NAME to a constant or a math expression.)]%r%r[align(<30 45,%b%b&dvar`<NAME> child=<ufun> -,If NAME is in an expression\, Math chip calls u(dvar`NAME) to fetch a value or expression.)]%r%r[align(<30 45,%b%b&fun`<name> child=<ufun> -,If name(...) is in an expression\, math chip calls u(fun`name,<stack>) and expects a new\, altered stack back. first(\%0) is the top of the stack.)]%r%rProvided functions:%r%r%b%bu(convert,<expression>) - Convert <expression> to RPN.%r%b%bu(calc_rpn,<rpn>) - Execute an RPN calculation string.%r%b%bu(rpn_to_softcode,<rpn>) - Turn <RPN> into a softcode s()-able string that uses u(get,varname) for unknown variables.%r%b%bu(calc,<expression>) - Just go straight from a math expression to its result.
@set Basic chip/DESCRIBE=no_command visual prefixmatch public nearby
&DESCRIBE`GRAPHING Basic chip=[setq(e,v(rpn))][edit([space(5)].[repeat(-,70)].%r[align(>4 1. 68 1.,[left(v(maxy),4)][repeat(%r,17)][left(v(miny),4)],|,u(graph),|)]%r[space(5)]'[repeat(-,70)]'%r[space(8)][ljust(left(v(minx),4),65)][left(v(maxx),4)],#,%b)]
@set Basic chip/DESCRIBE`GRAPHING=no_command
&DESCRIBE`NORMAL Basic chip=.[repeat(-,20)].%r|[space(20)]|%r[align(1. 18 1.,|,v(function)%r%r> [v(result)]%r,|)]%r|[space(20)]|%r'[repeat(-,20)]'
@set Basic chip/DESCRIBE`NORMAL=no_command
&DVAR Basic chip=
&FIX_NEGATIVES Basic chip=regeditall(edit(regeditall(edit(%0,~,-),lit((^|[^0-9A-Z\)])\-([0-9\.()])),$1[chr(180)]$2),-,-%b,chr(180),-),\\b(-?\\d+(?:\\.\\d+)?)(\[A-Z\]+\[A-Z0-9\]*),$1*$2,(\\d+)(\[a-ce-z\]+|d[a-z]+),$1*$2)
@set Basic chip/FIX_NEGATIVES=no_command
&FUN Basic chip=Function definitions here.
@set Basic chip/FUN=no_command
&FUN`ABS Basic chip=abs(%0)
@set Basic chip/FUN`ABS=no_command
&FUN`ACOS Basic chip=acos(%0,v(trig))
@set Basic chip/FUN`ACOS=no_command
&FUN`ADD Basic chip=lmath(add,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
&FUN`AND Basic chip=lmath(and,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`AND=no_command
&FUN`ASIN Basic chip=asin(%0,v(trig))
@set Basic chip/FUN`ASIN=no_command
&FUN`ATAN Basic chip=atan(%0,v(trig))
@set Basic chip/FUN`ATAN=no_command
&FUN`ATAN2 Basic chip=atan2(%0,%1,v(trig))
&FUN`BAND Basic chip=lmath(band,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`BAND=no_command
&FUN`BOR Basic chip=lmath(bor,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`BOR=no_command
&FUN`BOUND Basic chip=bound(%0,%1,%2)
&FUN`BXOR Basic chip=lmath(bxor,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`BXOR=no_command
&FUN`CEIL Basic chip=ceil(%0)
@set Basic chip/FUN`CEIL=no_command
&FUN`COS Basic chip=cos(%0,v(trig))
@set Basic chip/FUN`COS=no_command
&FUN`DIE Basic chip=die(%0,%1)
&FUN`DIST2D Basic chip=lmath(dist2d,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`DIST2D=no_command
&FUN`DIST3D Basic chip=lmath(dist3d,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`DIST3D=no_command
&FUN`DIV Basic chip=lmath(div,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`DIV=no_command
&FUN`E Basic chip=e()
@set Basic chip/FUN`E=no_command
&FUN`EQ Basic chip=lmath(eq,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`EQ=no_command
&FUN`FDIV Basic chip=lmath(fdiv,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`FDIV=no_command
&FUN`FLOOR Basic chip=floor(%0)
@set Basic chip/FUN`FLOOR=no_command
&FUN`GT Basic chip=lmath(gt,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`GT=no_command
&FUN`GTE Basic chip=lmath(gte,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`GTE=no_command
&FUN`LN Basic chip=ln(%0)
@set Basic chip/FUN`LN=no_command
&FUN`LOG Basic chip=log(%0,firstof(%1,10))
&FUN`LOG2 Basic chip=log(%0,2)
&FUN`LT Basic chip=lmath(lt,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`LT=no_command
&FUN`LTE Basic chip=lmath(lte,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`LTE=no_command
&FUN`MAX Basic chip=lmath(max,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`MAX=no_command
&FUN`MEAN Basic chip=lmath(mean,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`MEAN=no_command
&FUN`MEDIAN Basic chip=lmath(median,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`MEDIAN=no_command
&FUN`MIN Basic chip=lmath(min,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`MIN=no_command
&FUN`MOD Basic chip=mod(%0,%1)
&FUN`MODULO Basic chip=lmath(modulo,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`MODULO=no_command
&FUN`MUL Basic chip=lmath(mul,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`MUL=no_command
&FUN`NAND Basic chip=lmath(nand,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`NAND=no_command
&FUN`NEQ Basic chip=lmath(neq,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`NEQ=no_command
&FUN`NOR Basic chip=lmath(nor,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`NOR=no_command
&FUN`OR Basic chip=lmath(or,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`OR=no_command
&FUN`PI Basic chip=pi()
@set Basic chip/FUN`PI=no_command
&FUN`RAND Basic chip=switch(%+,1,rand(%0),2,rand(%0,%1),#-1 FUNCTION (RAND) EXPECTS ! OR 2 ARGUMENTS BUT GOT %+)
&FUN`REMAINDER Basic chip=lmath(remainder,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`REMAINDER=no_command
&FUN`ROUND Basic chip=round(%0,firstof(%1,2))
&FUN`SIN Basic chip=sin(%0,v(trig))
@set Basic chip/FUN`SIN=no_command
&FUN`SQRT Basic chip=sqrt(%0)
@set Basic chip/FUN`SQRT=no_command
&FUN`STDDEV Basic chip=lmath(stddev,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`STDDEV=no_command
&FUN`SUB Basic chip=lmath(sub,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`SUB=no_command
&FUN`TAN Basic chip=tan(%0,v(trig))
@set Basic chip/FUN`TAN=no_command
&FUN`VAL Basic chip=%0
@set Basic chip/FUN`VAL=no_command
&FUN`XOR Basic chip=lmath(xor,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`XOR=no_command
&FUNCTION Basic chip=ceil(1 / 3)
@set Basic chip/FUNCTION=no_command
&GET Basic chip=switch(1,hasattrp(me,var`%0),u(calc_rpn,v(var`%0)),hasattrp(me,dvar`%0),u(calc,u(dvar`%0)),0)
&MODE Basic chip=graphing
@set Basic chip/MODE=no_command
&MUSHFUNS Basic chip=abs acos add and asin atan band bor bound bxor ceil cos die dist2d dist3d div e eq fdiv floor gt gte ln log log2 lt lte max mean median min mod modulo mul nand neq nor or pi remainder round sin sqrt stddev sub tan val xor
&PEMIT Basic chip=pemit(%0,Calc: %1)
@set Basic chip/PEMIT=no_command
&PROCESS Basic chip=[setq(p,v(process`priority))][if(strlen(regeditall(u(fix_negatives,%0),v(rx),null(u(process`token,$1)),\\s+,)),FORMULA IMPROPER #-1,u(process`finish))]
@set Basic chip/PROCESS=no_command
&PROCESS`FINISH Basic chip=[null(setq(0,1,1,0),map(process`operator_call,%qs))]%qo
@set Basic chip/PROCESS`FINISH=no_command
&PROCESS`FUNCTION Basic chip=setq(o,\) %qo,s,switch(%0,\(,val,*\(,edit(%0,\(,),,wtf:%0) %qs)
@set Basic chip/PROCESS`FUNCTION=no_command
&PROCESS`FUNCTION_CLOSE Basic chip=null(setq(0,1,1,0),map(process`operator_call,%qs),setq(o,first(%qs) %qo,s,rest(%qs)))
@set Basic chip/PROCESS`FUNCTION_CLOSE=no_command
&PROCESS`NUMBER Basic chip=setq(o,%0 %qo)
@set Basic chip/PROCESS`NUMBER=no_command
&PROCESS`OPERATOR Basic chip=null(setq(0,1,1,wordpos(%qp,pos(%0,%qp))),map(process`operator_call,%qs),setq(s,%0 %qs))
@set Basic chip/PROCESS`OPERATOR=no_command
&PROCESS`OPERATOR_CALL Basic chip=switch(0,%q0,,t(gt(wordpos(x %qp,pos(%0,x %qp)),%q1)),setq(0,0),setq(o,%0 %qo)[setq(s,rest(%qs))])
@set Basic chip/PROCESS`OPERATOR_CALL=no_command
&PROCESS`PRIORITY Basic chip=&, ><= -+ %*/ ^ d
@set Basic chip/PROCESS`PRIORITY=no_command
&PROCESS`PUSH Basic chip=null(setq(0,1,1,0),map(process`operator_call,%qs))
&PROCESS`TOKEN Basic chip=reswitch(%0,^\,$,u(process`push,%0),^\[-\%d^+*\\/<>=&\]$,u(process`operator,%0),^\[A-Z\]\[A-Z0-9\]*$,u(process`variable,%0),^-?\\d+(\\.\\d+)?,u(process`number,%0),^(\[a-z\]\[a-z0-8\]+)?\\\(,u(process`function,%0),\\\),u(process`function_close),#-1 INVALID TOKEN)[setq(l,%0)]
@set Basic chip/PROCESS`TOKEN=no_command
&PROCESS`VARIABLE Basic chip=setq(o,%0 %qo)
@set Basic chip/PROCESS`VARIABLE=no_command
&PROCESS_RPN Basic chip=reswitch(%1,^-?\\d+(\\.\\d+)?$,%1 %0,^\[-\%d^+*\\/<>=&\]$,u(process_rpn`operator,%1,%0),^\\\)$,%1 %0,^\[A-Z\]\[A-Z0-9\]*$,u(get,%1) %0,^\[a-z\]\[a-z0-9\]+$,u(process_rpn`function,%1,%0),#-1 INVALID RPN)
@set Basic chip/PROCESS_RPN=no_command
&PROCESS_RPN`FUNCTION Basic chip=squish(step(fun`%0,revwords(before(%1,\))),words(before(%1,\)))) [after(%1,\))])
&PROCESS_RPN`OPERATOR Basic chip=[[switch(%0,\\<,lt,\\>,gt,=,eq,&,cat,\,,cat,-,sub,+,add,d,die,\/,fdiv,^,power,\%,mod,mul)](elements(%1,2),first(%1))] [extract(%1,3,10000)]
@set Basic chip/PROCESS_RPN`OPERATOR=no_command
&RESULT Basic chip=1
@set Basic chip/RESULT=no_command
&RPN Basic chip=1 3 / ceil
@set Basic chip/RPN=no_command
&RPN_TO_SOFTCODE Basic chip=localize(squish(if(regmatch(setr(e,edit(%0,\),CloseParen)),^\\d+(?:\\.\\d+)?$),%qe,[null(regmatch(,repeat(\(\),35),- 0 1 2 3 4 5 6 7 8 9 b c d f g h i j k l m n o p q r s t u v w x y z))][if(pos(%b,setr(m,fold(rpn_to_softcode`each,%qe,))),cat\([edit(%qm,%b,\,)]\),%qm)])))
&RPN_TO_SOFTCODE`EACH Basic chip=reswitch(%1,^-?\\d+(\\.\\d+)?$,%1 %0,^\[-\%d^+*\\/<>=&\]$,u(rpn_to_softcode`operator,%1,%0),^\[A-Z\]\[A-Z0-9\]*$,switch(1,strmatch(%1,X),u\(get\,%1\),isnum(v(var`%1)),v(var`%1),u\(get\,%1\)) %0,^\[a-z\]\[a-z0-9\]+$,u(rpn_to_softcode`function,%1,%0),^CloseParen$,%1 %0,#-1 INVALID RPN)
&RPN_TO_SOFTCODE`FUNCTION Basic chip=squish([switch(1,strmatch(%0,val),,t(member(v(mushfuns),%0)),%0\(,u\(fun`%0\,)][edit(revwords(before(%1,CloseParen)),%b,\,)][if(strmatch(%0,val),,\))] [after(%1,CloseParen)])
&RPN_TO_SOFTCODE`OPERATOR Basic chip=squish(switch(%0,\\<,lt,\\>,gt,=,eq,&,cat,-,sub,+,add,d,die,\/,fdiv,^,power,\%,mod,mul)\([elements(%1,2)]\,[first(%1)]\) [extract(%1,3,10000)])
&RX Basic chip=(-?\d+(?:\.\d+)?|[-%^+*/><=&,]|d(?![a-z])|[()]|\w+\(|[A-Z][A-Z0-9]*)
@set Basic chip/RX=no_command
&TRIG Basic chip=r
@set Basic chip/TRIG=no_command
&USE Basic chip=u(describe)
@set Basic chip/USE=no_command prefixmatch
&VAR Basic chip=Variables go here.
@set Basic chip/VAR=no_command
&VAR`E Basic chip=2.718282
@set Basic chip/VAR`E=no_command
&VAR`PI Basic chip=3.141593
@set Basic chip/VAR`PI=no_command
@create Basic interpreter
@link Basic interpreter = #0
@parent Basic interpreter=[num(Basic Chip)]
@lock/Basic Basic interpreter==me
@lset Basic interpreter/Basic=no_inherit
@set Basic interpreter = !NO_COMMAND
@set Basic interpreter = OPAQUE
&CMD Basic interpreter=
&CMD`CLEAR Basic interpreter=@include me/e`noargs ; @emit %r%r
&CMD`DO Basic interpreter=@force/inplace me=%0
&CMD`END Basic interpreter=think setq(b,1)
&CMD`ERROR Basic interpreter=@include me/error=1,Forced error[if(strlen(%0),: %0)]
&CMD`FLASH Basic interpreter=@include me/e`noargs ; think setq(t,h)
&CMD`FOR Basic interpreter=@include me/error=not(regmatchi(%0,^(\\w+)\\s*=\\s*(\\d+)\\s+to\\s+(\\d+)\\s*(?:\\s+step\\s+(\\d+))?$,- 0 1 2 3)),INVALID FOR SYNTAX ; think u(var_set,%q0,%q1)[setq(f,squish(%q0:%qc:%q2:[firstof(%q3,1)] %qf))]
&CMD`GO Basic interpreter=think setq(0,firstof(namegrab(setr(1,lexits(here)),%0),if(strmatch(%0,randexit),randword(%q1)),namegrab(%q1,u(eval,%0)))) ; @include me/error=not(%q0),GO WHERE? ; goto [name(%q0)]
&CMD`GOSUB Basic interpreter=@include me/e`isint ; think setq(s,%qc %qs,l,u(next,dec(%q0)))
&CMD`GOTO Basic interpreter=@include me/e`isint ; think setq(l,first(filterbool(#lambda/gte(\%0,%q0),%qa)))
&CMD`IF Basic interpreter=@include me/error=not(cor(setq(1,,2,)0,strmatch(%0,* THEN *,0 1),strmatch(%0,* GOTO *,0 2))),IF EXPECTS 'IF <expr> THEN <statement>' OR 'IF <expr> GOTO <expr>' ; @assert u(eval,%q0) ; @assert strlen(%q1)=think setq(l,%q2) ; @include me/runline=%qc,%q1
&CMD`INPUT Basic interpreter=@include me/isvarname ; @wait me/waitingforinput`%qp={ think u(var_set,%0,v(gotinput`%qp)) ; &gotinput`%qp me ; @include me/runner=u(next,%qc) } ; think setq(b,1)
&CMD`INVERSE Basic interpreter=@include me/e`noargs ; think setq(t,i)
&CMD`LET Basic interpreter=@include me/error=not(strmatch(%0,*=*,0 1)),Let must be of form let <var> = <value> ; think u(var_set,squish(%q0),squish(%q1))
&CMD`NEXT Basic interpreter=@include me/error=not(regmatch(%0,^\\s*(\\w+)\\s*$,- 0)),NEXT EXPECTS A VARNAME! ; @include me/error=not(strmatch(grab(%qf,ucstr(%q0):*),*:*:*:*,0 1 2 3)),NO SUCH FOR LOOP SET ; think if(not(gte(setr(4,u(var_get,%q0)),%q2)),u(var_set,%q0,add(%q4,%q3))[setq(l,u(next,%q1))]
&CMD`NORMAL Basic interpreter=@include me/e`noargs ; think setq(t,n)
&CMD`NOTRACE Basic interpreter=think setq(t,0)
&CMD`ONERR Basic interpreter=@include me/error=not(regmatchi(%0,^\\s*GOTO\\s+(\\d+)\\s*$,- 0)),ONERR EXPECTS GOTO <LINENUM> ; think setq(e,%q0)
&CMD`POP Basic interpreter=@include me/e`noargs=%0,POP ; think setq(s,rest(%qs))
&CMD`PRINT Basic interpreter=@pemit %#=u(format,map(#lambda/u(eval,trim(\%0)),%0,;,))
&CMD`REM Basic interpreter=@@ Comment!
&CMD`RESUME Basic interpreter=@include me/e`noargs ; think setq(l,u(next,%qj),e,0)
&CMD`RETURN Basic interpreter=@include me/e`noargs ; @include me/error=not(%qs),NOWHERE TO RETURN TO ; think setq(l,u(next,first(%qs)),s,rest(%qs))
&CMD`SAY Basic interpreter=say u(format,map(#lambda/u(eval,trim(\%0)),%0,;,))
&CMD`SLEEP Basic interpreter=@include me/e`isint ; @wait me/sleeping`%qp/%q0=@include me/runner=u(next,%qc) ; think setq(b,1)
&CMD`STOP Basic interpreter=@include me/error=1,Forced error[if(strlen(%0),: %0)]
&CMD`TRACE Basic interpreter=think setq(t,1)
&DESCRIBE Basic interpreter=MUSH-BASIC program:%r%r[map(describe`line,sort(edit(lattr(me/line`*),LINE`,)),%b,%r)]%r%r[ansi(h,use [name(%!)])] for help.
@set Basic interpreter/DESCRIBE=no_command visual prefixmatch public nearby
&DESCRIBE`LINE Basic interpreter=align(>5 <70,%0,v(line`%0))
&E Basic interpreter=
&E`ISINT Basic interpreter=@include me/error=not(isint(setr(0,u(eval,%0)))),%qi EXPECTS AN INTEGER
&E`ISVARNAME Basic interpreter=@include me/error=not(regmatch(%0,^\\w+$)),%qi EXPECTS AN INTEGER
&E`NOARGS Basic interpreter=@include me/error=strlen(%0),%qi EXPECTS NO ARGUMENTS
&ERROR Basic interpreter=@break %0=@pemit %#=u(format,setq(b,not(%qe),l,u(next,dec(%qe)),j,%qc,e,)BASIC: Error while running the BASIC program: %1)
&EVAL Basic interpreter=cond(hasattrpval(me,keyword`%0),u(keyword`%0),strmatch(%0,"*",0),%q0,strmatch(%0,'*,0),s(squish(%q0)),regmatch(%0,^\\s*(\[a-zA-Z\]\\w+)\\s*$,- 0),u(var_get,%q0),regmatch(%0,^-?\\d+$),%0,u(calc,%0))
&FORMAT Basic interpreter=ansi(%qt,%0)
&GET Basic interpreter=u(var_get,%0)
&INPUT Basic interpreter=$input *:@assert v(waitingforinput`[setr(p,u(whofor))])=@pemit %#=The BASIC program is not waiting for input from you! ; @pemit %#=You enter '%0' into the BASIC program! ; &gotinput`%qp me=%0 ; @notify me/waitingforinput`%qp
&KEYWORD Basic interpreter=
&KEYWORD`RANDEXIT Basic interpreter=randword(lexits(here))
&LINE Basic interpreter=BASIC lines
&NEXT Basic interpreter=first(filterbool(#lambda/gt(\%0,%0),%qa))
&QREGS Basic interpreter=qp: The namespace of the current instance (usually \%#, or \%!).%rqa: List of all instruction line numbers.%rqb: If true, then end execution. %rqc: Current line number.%rqi: Current instruction.%rqe: set by ONERR GOTO, the line to go to on an error.%rqj: If an error is caused, qj is the line that had the error.%rql: Set by commands to instruct the interpreter to jump to that line.%rq0-q9: Left up to the commands.%rqv: Contains all the variables set by the program.%rqs: The gosub stack: a 'return' pops off the first and goes there.%rqf: The 'for loop' stack, used by the 'next <x>' command.%rqt: The ansi changes to text (flash, inverse, hilite, etc)
&RUN Basic interpreter=$run:@break v(waitingforinput`[setr(p,u(whofor))])=@pemit %#=You have input waiting on another program running! ; @break v(sleeping`%qp)=@pemit %#=You have another program currently running! (and in sleep, right now) ; @include me/runner=setq(d,n,t,0,l,first(setr(a,sort(edit(lattr(me/line`*),LINE`,),n))))%ql
&RUNLINE Basic interpreter=think setq(c,%0,i,reswitch(setr(0,%1),^\\s*\\w+\\s*=,let[setq(0,let %q0)],first(%q0))) ; @include/nobreak me/cmd`%qi=rest(%q0)
&RUNNER Basic interpreter=@assert cand(%0,hasattr(me,line`%0)) ; think setq(l,,c,%0,i,reswitch(setr(0,v(line`%0)),^\\s*\\w+\\s*=,let[setq(0,let %q0)],first(%q0))) ; @include/nobreak me/cmd`%qi=rest(%q0) ; @retry not(%qb)=firstof(%ql,u(next,%0))
&USE Basic interpreter=BASIC interpreter:%r%rChange the program: &line`## [name(%!)]=<code>%r%rCommands:%r%r[ansi(h,run)] - Run the program. (Or @trigger %!/run to run and keep no_command)%r[ansi(h,input <text>)] - Input some text, if the program's waiting for it.%r%rList of basic commands available:%r%r[table(sort(edit(lattrp(me/cmd`*),CMD`,)))]%r%rTo write a program: &line`<num> object=<code>
@set Basic interpreter/USE=no_command prefixmatch
&VAR_GET Basic interpreter=decode64(after(grab(%qv,ucstr(%0):*),:))
&VAR_SET Basic interpreter=setq(v,setunion(setdiff(%qv,grab(%qv,ucstr(%0):*)),ucstr(%0):[encode64(%1)]))
&WHOFOR Basic interpreter=%#
give Basic interpreter=Basic Chip
look Basic interpreter
@lock Basic chip==me
&AUTHOR Basic chip=Walker@M*U*S*H. Email comments, changes, suggestions to walker@pennmush.org
@set Basic chip/AUTHOR=no_command
&CALC Basic chip=revwords(u(calc_rpn,u(convert,%0)))
@set Basic chip/CALC=no_command no_debug
&CALC_RPN Basic chip=localize(squish(if(regmatch(%0,^\\d+(?:\\.\\d+)?$),%0,[null(regmatch(,repeat(\(\),34),- 0 1 2 3 4 5 6 7 8 9 b c d e f g h i j k l m n o p q r s t u w x y z))]fold(process_rpn,%0,)))
@set Basic chip/CALC_RPN=no_command
&CONVERT Basic chip=revwords(localize(squish(if(regmatch(%0,^-?\\d+(\\.\\d+)?$),%0,[null(setq(0,,s,,o,,p,,a,))][u(process,%0)]))))
@set Basic chip/CONVERT=no_command
&DESCRIBE Basic chip=This is a math chip that contains processing routines for handling mathematical expressions. It is not really intended for direct use, but to be @parented to objects that need it.%r%r%b%bA function is a string, lowercase, followed by a (. Functions on math chip can take up to 10 arguments.%r%b%bA variable is a string of upper case characters and numbers - The first must be an upper case character. (e.g: VAL1 is a variable, 1VAL is 1 * the variable VAL)%r%rPre-set variables and functions:%r%b%bE, PI, sin(), cos(), tan(), sqrt(), abs(), acos(), asin(), atan(), ceil(), floor(), ln()%r%rCommon child-set attributes:%r%r[align(<30 45,%b%b&var`<NAME> child=<expr> -,Set NAME to a constant or a math expression.)]%r%r[align(<30 45,%b%b&dvar`<NAME> child=<ufun> -,If NAME is in an expression\, Math chip calls u(dvar`NAME) to fetch a value or expression.)]%r%r[align(<30 45,%b%b&fun`<name> child=<ufun> -,If name(...) is in an expression\, math chip calls u(fun`name,<stack>) and expects a new\, altered stack back. first(\%0) is the top of the stack.)]%r%rProvided functions:%r%r%b%bu(convert,<expression>) - Convert <expression> to RPN.%r%b%bu(calc_rpn,<rpn>) - Execute an RPN calculation string.%r%b%bu(rpn_to_softcode,<rpn>) - Turn <RPN> into a softcode s()-able string that uses u(get,varname) for unknown variables.%r%b%bu(calc,<expression>) - Just go straight from a math expression to its result.
@set Basic chip/DESCRIBE=no_command visual prefixmatch public nearby
&DESCRIBE`GRAPHING Basic chip=[setq(e,v(rpn))][edit([space(5)].[repeat(-,70)].%r[align(>4 1. 68 1.,[left(v(maxy),4)][repeat(%r,17)][left(v(miny),4)],|,u(graph),|)]%r[space(5)]'[repeat(-,70)]'%r[space(8)][ljust(left(v(minx),4),65)][left(v(maxx),4)],#,%b)]
@set Basic chip/DESCRIBE`GRAPHING=no_command
&DESCRIBE`NORMAL Basic chip=.[repeat(-,20)].%r|[space(20)]|%r[align(1. 18 1.,|,v(function)%r%r> [v(result)]%r,|)]%r|[space(20)]|%r'[repeat(-,20)]'
@set Basic chip/DESCRIBE`NORMAL=no_command
&DVAR Basic chip=
&FIX_NEGATIVES Basic chip=regeditall(edit(regeditall(edit(%0,~,-),lit((^|[^0-9A-Z\)])\-([0-9\.()])),$1[chr(180)]$2),-,-%b,chr(180),-),\\b(-?\\d+(?:\\.\\d+)?)(\[A-Z\]+\[A-Z0-9\]*),$1*$2,(\\d+)(\[a-ce-z\]+|d[a-z]+),$1*$2)
@set Basic chip/FIX_NEGATIVES=no_command
&FUN Basic chip=Function definitions here.
@set Basic chip/FUN=no_command
&FUN`ABS Basic chip=abs(%0)
@set Basic chip/FUN`ABS=no_command
&FUN`ACOS Basic chip=acos(%0,v(trig))
@set Basic chip/FUN`ACOS=no_command
&FUN`ADD Basic chip=lmath(add,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
&FUN`AND Basic chip=lmath(and,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`AND=no_command
&FUN`ASIN Basic chip=asin(%0,v(trig))
@set Basic chip/FUN`ASIN=no_command
&FUN`ATAN Basic chip=atan(%0,v(trig))
@set Basic chip/FUN`ATAN=no_command
&FUN`ATAN2 Basic chip=atan2(%0,%1,v(trig))
&FUN`BAND Basic chip=lmath(band,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`BAND=no_command
&FUN`BOR Basic chip=lmath(bor,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`BOR=no_command
&FUN`BOUND Basic chip=bound(%0,%1,%2)
&FUN`BXOR Basic chip=lmath(bxor,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`BXOR=no_command
&FUN`CEIL Basic chip=ceil(%0)
@set Basic chip/FUN`CEIL=no_command
&FUN`COS Basic chip=cos(%0,v(trig))
@set Basic chip/FUN`COS=no_command
&FUN`DIE Basic chip=die(%0,%1)
&FUN`DIST2D Basic chip=lmath(dist2d,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`DIST2D=no_command
&FUN`DIST3D Basic chip=lmath(dist3d,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`DIST3D=no_command
&FUN`DIV Basic chip=lmath(div,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`DIV=no_command
&FUN`E Basic chip=e()
@set Basic chip/FUN`E=no_command
&FUN`EQ Basic chip=lmath(eq,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`EQ=no_command
&FUN`FDIV Basic chip=lmath(fdiv,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`FDIV=no_command
&FUN`FLOOR Basic chip=floor(%0)
@set Basic chip/FUN`FLOOR=no_command
&FUN`GT Basic chip=lmath(gt,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`GT=no_command
&FUN`GTE Basic chip=lmath(gte,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`GTE=no_command
&FUN`LN Basic chip=ln(%0)
@set Basic chip/FUN`LN=no_command
&FUN`LOG Basic chip=log(%0,firstof(%1,10))
&FUN`LOG2 Basic chip=log(%0,2)
&FUN`LT Basic chip=lmath(lt,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`LT=no_command
&FUN`LTE Basic chip=lmath(lte,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`LTE=no_command
&FUN`MAX Basic chip=lmath(max,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`MAX=no_command
&FUN`MEAN Basic chip=lmath(mean,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`MEAN=no_command
&FUN`MEDIAN Basic chip=lmath(median,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`MEDIAN=no_command
&FUN`MIN Basic chip=lmath(min,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`MIN=no_command
&FUN`MOD Basic chip=mod(%0,%1)
&FUN`MODULO Basic chip=lmath(modulo,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`MODULO=no_command
&FUN`MUL Basic chip=lmath(mul,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`MUL=no_command
&FUN`NAND Basic chip=lmath(nand,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`NAND=no_command
&FUN`NEQ Basic chip=lmath(neq,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`NEQ=no_command
&FUN`NOR Basic chip=lmath(nor,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`NOR=no_command
&FUN`OR Basic chip=lmath(or,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`OR=no_command
&FUN`PI Basic chip=pi()
@set Basic chip/FUN`PI=no_command
&FUN`RAND Basic chip=switch(%+,1,rand(%0),2,rand(%0,%1),#-1 FUNCTION (RAND) EXPECTS ! OR 2 ARGUMENTS BUT GOT %+)
&FUN`REMAINDER Basic chip=lmath(remainder,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`REMAINDER=no_command
&FUN`ROUND Basic chip=round(%0,firstof(%1,2))
&FUN`SIN Basic chip=sin(%0,v(trig))
@set Basic chip/FUN`SIN=no_command
&FUN`SQRT Basic chip=sqrt(%0)
@set Basic chip/FUN`SQRT=no_command
&FUN`STDDEV Basic chip=lmath(stddev,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`STDDEV=no_command
&FUN`SUB Basic chip=lmath(sub,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`SUB=no_command
&FUN`TAN Basic chip=tan(%0,v(trig))
@set Basic chip/FUN`TAN=no_command
&FUN`VAL Basic chip=%0
@set Basic chip/FUN`VAL=no_command
&FUN`XOR Basic chip=lmath(xor,%0 %1 %2 %3 %4 %5 %6 %7 %8 %9)
@set Basic chip/FUN`XOR=no_command
&FUNCTION Basic chip=ceil(1 / 3)
@set Basic chip/FUNCTION=no_command
&GET Basic chip=switch(1,hasattrp(me,var`%0),u(calc_rpn,v(var`%0)),hasattrp(me,dvar`%0),u(calc,u(dvar`%0)),0)
&MODE Basic chip=graphing
@set Basic chip/MODE=no_command
&MUSHFUNS Basic chip=abs acos add and asin atan band bor bound bxor ceil cos die dist2d dist3d div e eq fdiv floor gt gte ln log log2 lt lte max mean median min mod modulo mul nand neq nor or pi remainder round sin sqrt stddev sub tan val xor
&PEMIT Basic chip=pemit(%0,Calc: %1)
@set Basic chip/PEMIT=no_command
&PROCESS Basic chip=[setq(p,v(process`priority))][if(strlen(regeditall(u(fix_negatives,%0),v(rx),null(u(process`token,$1)),\\s+,)),FORMULA IMPROPER #-1,u(process`finish))]
@set Basic chip/PROCESS=no_command
&PROCESS`FINISH Basic chip=[null(setq(0,1,1,0),map(process`operator_call,%qs))]%qo
@set Basic chip/PROCESS`FINISH=no_command
&PROCESS`FUNCTION Basic chip=setq(o,\) %qo,s,switch(%0,\(,val,*\(,edit(%0,\(,),,wtf:%0) %qs)
@set Basic chip/PROCESS`FUNCTION=no_command
&PROCESS`FUNCTION_CLOSE Basic chip=null(setq(0,1,1,0),map(process`operator_call,%qs),setq(o,first(%qs) %qo,s,rest(%qs)))
@set Basic chip/PROCESS`FUNCTION_CLOSE=no_command
&PROCESS`NUMBER Basic chip=setq(o,%0 %qo)
@set Basic chip/PROCESS`NUMBER=no_command
&PROCESS`OPERATOR Basic chip=null(setq(0,1,1,wordpos(%qp,pos(%0,%qp))),map(process`operator_call,%qs),setq(s,%0 %qs))
@set Basic chip/PROCESS`OPERATOR=no_command
&PROCESS`OPERATOR_CALL Basic chip=switch(0,%q0,,t(gt(wordpos(x %qp,pos(%0,x %qp)),%q1)),setq(0,0),setq(o,%0 %qo)[setq(s,rest(%qs))])
@set Basic chip/PROCESS`OPERATOR_CALL=no_command
&PROCESS`PRIORITY Basic chip=&, ><= -+ %*/ ^ d
@set Basic chip/PROCESS`PRIORITY=no_command
&PROCESS`PUSH Basic chip=null(setq(0,1,1,0),map(process`operator_call,%qs))
&PROCESS`TOKEN Basic chip=reswitch(%0,^\,$,u(process`push,%0),^\[-\%d^+*\\/<>=&\]$,u(process`operator,%0),^\[A-Z\]\[A-Z0-9\]*$,u(process`variable,%0),^-?\\d+(\\.\\d+)?,u(process`number,%0),^(\[a-z\]\[a-z0-8\]+)?\\\(,u(process`function,%0),\\\),u(process`function_close),#-1 INVALID TOKEN)[setq(l,%0)]
@set Basic chip/PROCESS`TOKEN=no_command
&PROCESS`VARIABLE Basic chip=setq(o,%0 %qo)
@set Basic chip/PROCESS`VARIABLE=no_command
&PROCESS_RPN Basic chip=reswitch(%1,^-?\\d+(\\.\\d+)?$,%1 %0,^\[-\%d^+*\\/<>=&\]$,u(process_rpn`operator,%1,%0),^\\\)$,%1 %0,^\[A-Z\]\[A-Z0-9\]*$,u(get,%1) %0,^\[a-z\]\[a-z0-9\]+$,u(process_rpn`function,%1,%0),#-1 INVALID RPN)
@set Basic chip/PROCESS_RPN=no_command
&PROCESS_RPN`FUNCTION Basic chip=squish(step(fun`%0,revwords(before(%1,\))),words(before(%1,\)))) [after(%1,\))])
&PROCESS_RPN`OPERATOR Basic chip=[[switch(%0,\\<,lt,\\>,gt,=,eq,&,cat,\,,cat,-,sub,+,add,d,die,\/,fdiv,^,power,\%,mod,mul)](elements(%1,2),first(%1))] [extract(%1,3,10000)]
@set Basic chip/PROCESS_RPN`OPERATOR=no_command
&RESULT Basic chip=1
@set Basic chip/RESULT=no_command
&RPN Basic chip=1 3 / ceil
@set Basic chip/RPN=no_command
&RPN_TO_SOFTCODE Basic chip=localize(squish(if(regmatch(setr(e,edit(%0,\),CloseParen)),^\\d+(?:\\.\\d+)?$),%qe,[null(regmatch(,repeat(\(\),35),- 0 1 2 3 4 5 6 7 8 9 b c d f g h i j k l m n o p q r s t u v w x y z))][if(pos(%b,setr(m,fold(rpn_to_softcode`each,%qe,))),cat\([edit(%qm,%b,\,)]\),%qm)])))
&RPN_TO_SOFTCODE`EACH Basic chip=reswitch(%1,^-?\\d+(\\.\\d+)?$,%1 %0,^\[-\%d^+*\\/<>=&\]$,u(rpn_to_softcode`operator,%1,%0),^\[A-Z\]\[A-Z0-9\]*$,switch(1,strmatch(%1,X),u\(get\,%1\),isnum(v(var`%1)),v(var`%1),u\(get\,%1\)) %0,^\[a-z\]\[a-z0-9\]+$,u(rpn_to_softcode`function,%1,%0),^CloseParen$,%1 %0,#-1 INVALID RPN)
&RPN_TO_SOFTCODE`FUNCTION Basic chip=squish([switch(1,strmatch(%0,val),,t(member(v(mushfuns),%0)),%0\(,u\(fun`%0\,)][edit(revwords(before(%1,CloseParen)),%b,\,)][if(strmatch(%0,val),,\))] [after(%1,CloseParen)])
&RPN_TO_SOFTCODE`OPERATOR Basic chip=squish(switch(%0,\\<,lt,\\>,gt,=,eq,&,cat,-,sub,+,add,d,die,\/,fdiv,^,power,\%,mod,mul)\([elements(%1,2)]\,[first(%1)]\) [extract(%1,3,10000)])
&RX Basic chip=(-?\d+(?:\.\d+)?|[-%^+*/><=&,]|d(?![a-z])|[()]|\w+\(|[A-Z][A-Z0-9]*)
@set Basic chip/RX=no_command
&TRIG Basic chip=r
@set Basic chip/TRIG=no_command
&USE Basic chip=u(describe)
@set Basic chip/USE=no_command prefixmatch
&VAR Basic chip=Variables go here.
@set Basic chip/VAR=no_command
&VAR`E Basic chip=2.718282
@set Basic chip/VAR`E=no_command
&VAR`PI Basic chip=3.141593
@set Basic chip/VAR`PI=no_command
@create Basic interpreter
@link Basic interpreter = #0
@parent Basic interpreter=[num(Basic Chip)]
@lock/Basic Basic interpreter==me
@lset Basic interpreter/Basic=no_inherit
@set Basic interpreter = !NO_COMMAND
@set Basic interpreter = OPAQUE
&CMD Basic interpreter=
&CMD`CLEAR Basic interpreter=@include me/e`noargs ; @emit %r%r
&CMD`DO Basic interpreter=@force/inplace me=%0
&CMD`END Basic interpreter=think setq(b,1)
&CMD`ERROR Basic interpreter=@include me/error=1,Forced error[if(strlen(%0),: %0)]
&CMD`FLASH Basic interpreter=@include me/e`noargs ; think setq(t,h)
&CMD`FOR Basic interpreter=@include me/error=not(regmatchi(%0,^(\\w+)\\s*=\\s*(\\d+)\\s+to\\s+(\\d+)\\s*(?:\\s+step\\s+(\\d+))?$,- 0 1 2 3)),INVALID FOR SYNTAX ; think u(var_set,%q0,%q1)[setq(f,squish(%q0:%qc:%q2:[firstof(%q3,1)] %qf))]
&CMD`GO Basic interpreter=think setq(0,firstof(namegrab(setr(1,lexits(here)),%0),if(strmatch(%0,randexit),randword(%q1)),namegrab(%q1,u(eval,%0)))) ; @include me/error=not(%q0),GO WHERE? ; goto [name(%q0)]
&CMD`GOSUB Basic interpreter=@include me/e`isint ; think setq(s,%qc %qs,l,u(next,dec(%q0)))
&CMD`GOTO Basic interpreter=@include me/e`isint ; think setq(l,first(filterbool(#lambda/gte(\%0,%q0),%qa)))
&CMD`IF Basic interpreter=@include me/error=not(cor(setq(1,,2,)0,strmatch(%0,* THEN *,0 1),strmatch(%0,* GOTO *,0 2))),IF EXPECTS 'IF <expr> THEN <statement>' OR 'IF <expr> GOTO <expr>' ; @assert u(eval,%q0) ; @assert strlen(%q1)=think setq(l,%q2) ; @include me/runline=%qc,%q1
&CMD`INPUT Basic interpreter=@include me/isvarname ; @wait me/waitingforinput`%qp={ think u(var_set,%0,v(gotinput`%qp)) ; &gotinput`%qp me ; @include me/runner=u(next,%qc) } ; think setq(b,1)
&CMD`INVERSE Basic interpreter=@include me/e`noargs ; think setq(t,i)
&CMD`LET Basic interpreter=@include me/error=not(strmatch(%0,*=*,0 1)),Let must be of form let <var> = <value> ; think u(var_set,squish(%q0),squish(%q1))
&CMD`NEXT Basic interpreter=@include me/error=not(regmatch(%0,^\\s*(\\w+)\\s*$,- 0)),NEXT EXPECTS A VARNAME! ; @include me/error=not(strmatch(grab(%qf,ucstr(%q0):*),*:*:*:*,0 1 2 3)),NO SUCH FOR LOOP SET ; think if(not(gte(setr(4,u(var_get,%q0)),%q2)),u(var_set,%q0,add(%q4,%q3))[setq(l,u(next,%q1))]
&CMD`NORMAL Basic interpreter=@include me/e`noargs ; think setq(t,n)
&CMD`NOTRACE Basic interpreter=think setq(t,0)
&CMD`ONERR Basic interpreter=@include me/error=not(regmatchi(%0,^\\s*GOTO\\s+(\\d+)\\s*$,- 0)),ONERR EXPECTS GOTO <LINENUM> ; think setq(e,%q0)
&CMD`POP Basic interpreter=@include me/e`noargs=%0,POP ; think setq(s,rest(%qs))
&CMD`PRINT Basic interpreter=@pemit %#=u(format,map(#lambda/u(eval,trim(\%0)),%0,;,))
&CMD`REM Basic interpreter=@@ Comment!
&CMD`RESUME Basic interpreter=@include me/e`noargs ; think setq(l,u(next,%qj),e,0)
&CMD`RETURN Basic interpreter=@include me/e`noargs ; @include me/error=not(%qs),NOWHERE TO RETURN TO ; think setq(l,u(next,first(%qs)),s,rest(%qs))
&CMD`SAY Basic interpreter=say u(format,map(#lambda/u(eval,trim(\%0)),%0,;,))
&CMD`SLEEP Basic interpreter=@include me/e`isint ; @wait me/sleeping`%qp/%q0=@include me/runner=u(next,%qc) ; think setq(b,1)
&CMD`STOP Basic interpreter=@include me/error=1,Forced error[if(strlen(%0),: %0)]
&CMD`TRACE Basic interpreter=think setq(t,1)
&DESCRIBE Basic interpreter=MUSH-BASIC program:%r%r[map(describe`line,sort(edit(lattr(me/line`*),LINE`,)),%b,%r)]%r%r[ansi(h,use [name(%!)])] for help.
@set Basic interpreter/DESCRIBE=no_command visual prefixmatch public nearby
&DESCRIBE`LINE Basic interpreter=align(>5 <70,%0,v(line`%0))
&E Basic interpreter=
&E`ISINT Basic interpreter=@include me/error=not(isint(setr(0,u(eval,%0)))),%qi EXPECTS AN INTEGER
&E`ISVARNAME Basic interpreter=@include me/error=not(regmatch(%0,^\\w+$)),%qi EXPECTS AN INTEGER
&E`NOARGS Basic interpreter=@include me/error=strlen(%0),%qi EXPECTS NO ARGUMENTS
&ERROR Basic interpreter=@break %0=@pemit %#=u(format,setq(b,not(%qe),l,u(next,dec(%qe)),j,%qc,e,)BASIC: Error while running the BASIC program: %1)
&EVAL Basic interpreter=cond(hasattrpval(me,keyword`%0),u(keyword`%0),strmatch(%0,"*",0),%q0,strmatch(%0,'*,0),s(squish(%q0)),regmatch(%0,^\\s*(\[a-zA-Z\]\\w+)\\s*$,- 0),u(var_get,%q0),regmatch(%0,^-?\\d+$),%0,u(calc,%0))
&FORMAT Basic interpreter=ansi(%qt,%0)
&GET Basic interpreter=u(var_get,%0)
&INPUT Basic interpreter=$input *:@assert v(waitingforinput`[setr(p,u(whofor))])=@pemit %#=The BASIC program is not waiting for input from you! ; @pemit %#=You enter '%0' into the BASIC program! ; &gotinput`%qp me=%0 ; @notify me/waitingforinput`%qp
&KEYWORD Basic interpreter=
&KEYWORD`RANDEXIT Basic interpreter=randword(lexits(here))
&LINE Basic interpreter=BASIC lines
&NEXT Basic interpreter=first(filterbool(#lambda/gt(\%0,%0),%qa))
&QREGS Basic interpreter=qp: The namespace of the current instance (usually \%#, or \%!).%rqa: List of all instruction line numbers.%rqb: If true, then end execution. %rqc: Current line number.%rqi: Current instruction.%rqe: set by ONERR GOTO, the line to go to on an error.%rqj: If an error is caused, qj is the line that had the error.%rql: Set by commands to instruct the interpreter to jump to that line.%rq0-q9: Left up to the commands.%rqv: Contains all the variables set by the program.%rqs: The gosub stack: a 'return' pops off the first and goes there.%rqf: The 'for loop' stack, used by the 'next <x>' command.%rqt: The ansi changes to text (flash, inverse, hilite, etc)
&RUN Basic interpreter=$run:@break v(waitingforinput`[setr(p,u(whofor))])=@pemit %#=You have input waiting on another program running! ; @break v(sleeping`%qp)=@pemit %#=You have another program currently running! (and in sleep, right now) ; @include me/runner=setq(d,n,t,0,l,first(setr(a,sort(edit(lattr(me/line`*),LINE`,),n))))%ql
&RUNLINE Basic interpreter=think setq(c,%0,i,reswitch(setr(0,%1),^\\s*\\w+\\s*=,let[setq(0,let %q0)],first(%q0))) ; @include/nobreak me/cmd`%qi=rest(%q0)
&RUNNER Basic interpreter=@assert cand(%0,hasattr(me,line`%0)) ; think setq(l,,c,%0,i,reswitch(setr(0,v(line`%0)),^\\s*\\w+\\s*=,let[setq(0,let %q0)],first(%q0))) ; @include/nobreak me/cmd`%qi=rest(%q0) ; @retry not(%qb)=firstof(%ql,u(next,%0))
&USE Basic interpreter=BASIC interpreter:%r%rChange the program: &line`## [name(%!)]=<code>%r%rCommands:%r%r[ansi(h,run)] - Run the program. (Or @trigger %!/run to run and keep no_command)%r[ansi(h,input <text>)] - Input some text, if the program's waiting for it.%r%rList of basic commands available:%r%r[table(sort(edit(lattrp(me/cmd`*),CMD`,)))]%r%rTo write a program: &line`<num> object=<code>
@set Basic interpreter/USE=no_command prefixmatch
&VAR_GET Basic interpreter=decode64(after(grab(%qv,ucstr(%0):*),:))
&VAR_SET Basic interpreter=setq(v,setunion(setdiff(%qv,grab(%qv,ucstr(%0):*)),ucstr(%0):[encode64(%1)]))
&WHOFOR Basic interpreter=%#
give Basic interpreter=Basic Chip
look Basic interpreter