-
Notifications
You must be signed in to change notification settings - Fork 9
Home
Musl, the Marginally Useful Scripting Language or My 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 to Musl scripts.
The Following built-in functions are available to all scripts.
Converts the string x$
to a number.
Converts the number x
to a string.
Returns the length of string x$
Returns the n
leftmost characters in s$
Returns the n
rightmost characters in s$
Returns the all the characters in s$
between n
and m
inclusive.
The string is indexed from 1, that is
MID$("Hello World From Musl", 7, 11)
will return "World"
Converts the string x$
to uppercase.
Converts the string x$
to lowercase.
Removes leading and trailing whitespace from string x$
.
Searches for find$
in str$
and returns the index.
It returns 0 if find$
was not found.
If the condition cond
is true, it returns then_val
,
otherwise it returns else_val
Populates an array named list$
.
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 to DATA()
on the same array will append more data.
It returns the number of items inserted into the array.
Initializes mymap
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 value val
onto an internal stack where it can be popped
later through the POP()
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 the
PUSH()
function.
Example:
foo = POP()
Throws an error with the specified message.