- Notifications
You must be signed in to change notification settings - Fork9
Musl, theMarginally Useful Scripting LanguageorMy UnStructured Language
An interpreter for a silly unstructured programming language.
Author: Werner Stoop.
These sources are provided under the terms of the unlicense:
This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means. In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to <http://unlicense.org/>
The following describes the syntax of the interpreter.Consult the examples if it is unclear.
program ::= [line]* line ::= [label ':'] stmts <LF> | NUMBER stmts <LF> stmts ::= stmt [':' [<LF>+] stmts] stmt ::= [LET] ident ['[' expr ']'] '=' expr | ident '(' fparams ')' | GOTO label | GOSUB label | ON expr GOTO label [',' label]* | ON expr GOSUB label [',' label]* | RETURN | IF expr THEN [<LF>+] stmts | FOR ident = expr TO expr [STEP expr] DO [<LF>+] stmts [<LF>+] NEXT | END fparams ::= '(' [expr ',' expr ',' ...] ')' expr ::= and_expr [OR and_expr]* and_expr ::= not_expr [AND not_expr]* not_expr ::= [NOT] comp_expr comp_expr ::= cat_expr [('='|'<'|'>'|'~') cat_expr] cat_expr ::= add_expr ['&' add_expr]* add_expr ::= mul_expr [('+'|'-') mul_expr]* mul_expr ::= uexpr [('*'|'/'|'%') uexpr]* uexpr ::= ['-'|'+'] atom atom ::= '(' expr ')' | ident | ident '[' expr ']' | ident '(' [fparams] ')' | number | string | '@' ident
These functions are available toMusl scripts.
The Following built-in functions are available to all scripts.
Converts the stringx$
to a number.
Converts the numberx
to a string.
Returns the length of stringx$
Returns then
leftmost characters ins$
Returns then
rightmost characters ins$
Returns the all the characters ins$
betweenn
andm
inclusive.
The string is indexed from 1, that isMID$("Hello World From Musl", 7, 11)
will return"World"
Converts the stringx$
to uppercase.
Converts the stringx$
to lowercase.
Removes leading and trailing whitespace from stringx$
.
Searches forfind$
instr$
and returns the index.
It returns 0 iffind$
was not found.
If the conditioncond
is true, it returnsthen_val
,otherwise it returnselse_val
Populates an array namedlist$
.
Note: The first parameter is a string containing the name of the array.A call
DATA(@array$, "Alice", "Bob", "Carol")
is equivalent to the statements:
LET array$[1] = "Alice" LET array$[2] = "Bob" LET array$[3] = "Carol"
list$["length"]
will contain the number of items in the array.
Subsequent calls toDATA()
on the same array will append more data.
It returns the number of items inserted into the array.
Initializesmymap
as an array of key-value pairs.
A call
MAP(@mymap, "Alice", 111, "Bob", 222, "Carol", 333)
is equivalent to the statements:
LET mymap["Alice"] = 111 LET mymap["Bob"] = 222 LET mymap["Carol"] = 333
Pushes a valueval
onto an internal stack where it can be poppedlater through thePOP()
function.
It is used to simulate local variables in subroutines.
Example:
PUSH(foo)
Note: Don't access__stack[]
and__sp
directly.
Pops a value from the stack that was pushed earlier through thePUSH()
function.
Example:
foo = POP()
Throws an error with the specified message.