Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Werner Stoop edited this pageDec 26, 2013 ·5 revisions

Musl, theMarginally Useful Scripting LanguageorMy UnStructured Language

An interpreter for a silly unstructured programming language.

License

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/>

Syntax

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

Functions

These functions are available toMusl scripts.

Built-In Functions

The Following built-in functions are available to all scripts.

VAL(x$)

Converts the stringx$ to a number.

STR$(x)

Converts the numberx to a string.

LEN(x$)

Returns the length of stringx$

LEFT$(s$, n)

Returns then leftmost characters ins$

RIGHT$(s$, n)

Returns then rightmost characters ins$

MID$(s$, n, m)

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"

UCASE$(x$)

Converts the stringx$ to uppercase.

LCASE$(x$)

Converts the stringx$ to lowercase.

TRIM$(x$)

Removes leading and trailing whitespace from stringx$.

INSTR(str$, find$)

Searches forfind$ instr$ and returns the index.

It returns 0 iffind$ was not found.

IFF(cond, then_val, else_val)

If the conditioncond is true, it returnsthen_val,otherwise it returnselse_val

DATA(@list$, item1, item2, item3, ...)

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.

MAP(@mymap, key1, val1, key2, val2, ...)

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

PUSH(val)

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.

POP()

Pops a value from the stack that was pushed earlier through thePUSH() function.

Example:

 foo = POP()

THROW(msg$)

Throws an error with the specified message.


[8]ページ先頭

©2009-2025 Movatter.jp