|
|
(25 intermediate revisions by the same user not shown) |
Line 1: |
Line 1: |
− | [[The Original SCI Documentation]]<br /> | + | [[Official SCI Documentation]]<br /> |
| | | |
| <div align="center"><span style="font-size: 22pt">The Script Programming Language</span><br /> | | <div align="center"><span style="font-size: 22pt">The Script Programming Language</span><br /> |
Line 5: |
Line 5: |
| Date: 4 April 1988</div> | | Date: 4 April 1988</div> |
| | | |
| + | <blockquote> |
| + | *[[The Script Programming Language/Introduction | Introduction]] |
| *[[The Script Programming Language/Files | Files]] | | *[[The Script Programming Language/Files | Files]] |
| *[[The Script Programming Language/Definitions | Definitions]] | | *[[The Script Programming Language/Definitions | Definitions]] |
Line 17: |
Line 19: |
| *[[The Script Programming Language/Procedures | Procedures]] | | *[[The Script Programming Language/Procedures | Procedures]] |
| *[[The Script Programming Language/Using SC | Using SC]] | | *[[The Script Programming Language/Using SC | Using SC]] |
− | | + | *[[The Script Programming Language/Index | Index]] |
− |
| |
− | | |
− | ==<br /> Introduction ==
| |
− | | |
− | The Script adventure game language is an object-oriented language with a Lisp-like syntax. It is compiled by the sc compiler into the pseudo-code which is used by the interpreter, sci. | |
− | | |
− | We will begin our discussion of the language with its basic Lisp-like characteristics, then go on to the object-oriented parts of the language.
| |
− | | |
− | As is Lisp, Script is based on parenthesized expressions which return values. An expression is of the form
| |
− | | |
− | <blockquote>
| |
− | <div class="CodeBlockHeader">Code:</div>
| |
− | <syntaxhighlight lang="sci">
| |
− | (procedure [parameter parameter ...]).
| |
− | </syntaxhighlight>
| |
| </blockquote> | | </blockquote> |
| | | |
− | The parameters to a procedure may themselves be expressions to be evaluated, and may be nested until you lose track of the parentheses. | + | <div align="center"> |
| + | Chapter: |
| + | [[The Script Programming Language/Introduction|1]] | |
| + | [[The Script Programming Language/Files|2]] | |
| + | [[The Script Programming Language/Definitions|3]] | |
| + | [[The Script Programming Language/Data Types and Variables|4]] | |
| + | [[The Script Programming Language/Primitive Procedures|5]] | |
| + | [[The Script Programming Language/Control Flow|6]] | |
| + | [[The Script Programming Language/Procedures|7]] | |
| + | [[The Script Programming Language/Using SC|8]] | |
| + | [[The Script Programming Language/Index|Index]] |
| + | </div><br /> |
| | | |
− | Unlike Lisp, the procedure itself may NOT be the result of an evaluation. An example of an expression is
| + | * [[Media:SCRIPT.pdf|Download The Script Programming Language in PDF Form]]<br /> |
| | | |
− | <blockquote>
| |
− | <div class="CodeBlockHeader">Code:</div>
| |
− | <syntaxhighlight lang="sci">
| |
− | (+ (- y 2) (/ x 3))
| |
− | </syntaxhighlight>
| |
− | </blockquote>
| |
| | | |
− | which would be written in infix notation as
| + | |
| | | |
− | <blockquote> | + | <span style="float: left"><span class="Inactive">< Previous: </span></span><span style="float: right">[[The Script Programming Language/Introduction|Next: Introduction >]]</span> |
− | <div class="CodeBlockHeader">Code:</div> | |
− | <syntaxhighlight lang="sci"> | |
− | (y - 2) + (x / 3).
| |
− | </syntaxhighlight>
| |
− | </blockquote> | |
| | | |
− | All expressions are guaranteed to be evaluated from left to right. Thus,
| + | |
− | | |
− | <blockquote>
| |
− | <div class="CodeBlockHeader">Code:</div>
| |
− | <syntaxhighlight lang="sci">
| |
− | (= x 4)
| |
− | (= y (/ (+= x 4) (/= x 2)))
| |
− | </syntaxhighlight>
| |
− | </blockquote>
| |
− | | |
− | will result in y = 2 and x = 4.
| |
− | | |
− | Comments in Script begin with a semi-colon, ';', and continue to the end of the line.
| |
− | | |
− | == <br />Files ==
| |
− | | |
− | == <br /> Definitions ==
| |
− | | |
− | ==<br /> Data Types and Variables ==
| |
− | | |
− | === <br /> Characters: ===
| |
− | | |
− | Characters are single ASCII characters, and are denoted by preceding the character with the reverse single quote ("tick") character:
| |
− | | |
− | <blockquote>
| |
− | `A represents uppercase A and
| |
− | `? represents the question mark
| |
− | </blockquote>
| |
− | | |
− | Several character sequences represent special key combinations:
| |
− | | |
− | <blockquote>
| |
− | `^a represents ctrl-A
| |
− | `@b represents alt-B
| |
− | `#4 represents the F4 key
| |
− | </blockquote>
| |
− | | |
− | === <br /> Literal selectors: ===
| |
− | | |
− | Sometimes, as in the code
| |
− | | |
− | <blockquote>
| |
− | <div class="CodeBlockHeader">Code:</div>
| |
− | <syntaxhighlight lang="sci">
| |
− | (cast eachElementDo: #showSelf:)
| |
− | </syntaxhighlight>
| |
− | </blockquote>
| |
− | | |
− | you want to send the value of selector rather than use the selector as the start of another message to an object (these terms will be described in Object Oriented Programming in Script). Preceding the selector with a '#' produces the literal value of the selector rather than using it as a message.
| |
− | | |
− | == <br /> Primitive Procedures ==
| |
− | | |
− | === <br /> Arithmetic primitives: ===
| |
− |
| |
− | In the following, e1, e2, ... are arbitrary expressions.
| |
− |
| |
− | ==== <br />(+ e1 e2 [e3...]) ====
| |
− | <blockquote>Evaluates to e1 + e2 [+ e3 ...]</blockquote>
| |
− |
| |
− | ==== <br />(* e1 e2 [e3...]) ====
| |
− | <blockquote>Evaluates to e1 * e2 [* e3 ...]</blockquote>
| |
− |
| |
− | ==== <br />(- e1 e2) ====
| |
− | <blockquote>Evaluates to e1 - e2</blockquote>
| |
− |
| |
− | ==== <br />(/ e1 e2) ====
| |
− | <blockquote>Evaluates to e1 / e2</blockquote>
| |
− |
| |
− | ==== <br />(mod e1 e2) ====
| |
− | <blockquote>Evaluates to the remainder of e1 when divided by e2.</blockquote>
| |
− |
| |
− | ==== <br />(<< e1 e2) ====
| |
− | <blockquote>Evaluates to e1 << e2 where the << operation shifts its left hand side left by the number of bits specified by its right hand side. (As in C).</blockquote>
| |
− |
| |
− | ==== <br />(>> e1 e2) ====
| |
− | <blockquote>Evaluates to e1 >> e2 as in << except a right shift.</blockquote>
| |
− |
| |
− | ==== <br />(^ e1 e2 [e3 ...]) ====
| |
− | <blockquote>Evaluates to e1 ^ e2 [^ e3 ^ ...] where '^' is the bitwise exclusive-or operator.</blockquote>
| |
− |
| |
− | ==== <br />(& e1 e2 [e3 ...]) ====
| |
− | <blockquote>Evaluates to e1 & e2 [& e3 & ...] where '&' is the bitwise and operator.</blockquote>
| |
− |
| |
− | ==== <br />(| e1 e2 [e3]) ====
| |
− | <blockquote>Evaluates to e1 | e2 [| e3 | ...] where '|' is the bitwise or operator.</blockquote>
| |
− |
| |
− | ==== <br />(! e1) ====
| |
− | <blockquote>Evaluates to TRUE if e1 == 0, else FALSE.</blockquote>
| |
− |
| |
− | ==== <br />(~ e1) ====
| |
− | <blockquote>Evaluates to the bit-wise not of e1, i.e. all 1 bits are changed to 0 and all 0 bits are changed to 1.</blockquote>
| |
− | | |
− | === <br /> Boolean primitives: ===
| |
− | | |
− | These procedures are always guaranteed to evaluate their parameters left to right and to terminate the moment the truth value of the expression is determined. If the truth value of the boolean is determined before an expression is reached, the expression is never evaluated.
| |
− | | |
− | | |
− | ====<br /> (> e1 e2 [e3...]) ====
| |
− | <blockquote>Evaluates to TRUE if e1 > e2 [> e3 ...], else FALSE.</blockquote>
| |
− |
| |
− | ====<br /> (>= e1 e2 [e3...]) ====
| |
− | <blockquote>Evaluates to TRUE if e1 >= e2 [>= e3 ...], else FALSE.</blockquote>
| |
− |
| |
− | ====<br /> (< e1 e2 [e3...]) ====
| |
− | <blockquote>Evaluates to TRUE if e1 < e2 [< e3 ...], else FALSE.</blockquote>
| |
− |
| |
− | ====<br /> (<= e1 e2 [e3...]) ====
| |
− | <blockquote>Evaluates to TRUE if e1 <= e2 [<= e3 ...], else FALSE.</blockquote>
| |
− |
| |
− | ====<br /> (== e1 e2 [e3...]) ====
| |
− | <blockquote>Evaluates to TRUE if e1 == e2 [== e3 ...], else FALSE.</blockquote>
| |
− |
| |
− | ====<br /> (!= e1 e2 [e3...]) ====
| |
− | <blockquote>Evaluates to TRUE if e1 != e1 [!= e3 ...], else FALSE.</blockquote>
| |
− |
| |
− | ====<br /> (and e1 e2 [e3...]) ====
| |
− | <blockquote>Evaluates to TRUE if all the expressions are non-zero, else FALSE.</blockquote>
| |
− |
| |
− | ====<br /> (or e1 e2 [e3...]) ====
| |
− | <blockquote>Evaluates to TRUE if any of the expressions are non-zero, else FALSE.</blockquote>
| |
− |
| |
− | ====<br /> (not e) ====
| |
− | <blockquote>Evaluates to TRUE if the expression is zero, else FALSE.</blockquote>
| |
− | | |
− | ===<br /> Assignment primitives: ===
| |
− | | |
− | All assignment procedures store a value in a variable and return that value as the result of the assignment. In the following, v is a variable and e an expression.
| |
− | | |
− | ====<br /> (= v e) ====
| |
− | <blockquote>v = e</blockquote>
| |
− | | |
− | ====<br /> (+= v e) ====
| |
− | <blockquote>v = v + e</blockquote>
| |
− | | |
− | ====<br /> (-= v e) ====
| |
− | <blockquote>v = v - e</blockquote>
| |
− | | |
− | ====<br /> (*= v e) ====
| |
− | <blockquote>v = v * e</blockquote>
| |
− | | |
− | ====<br /> (/= v e) ====
| |
− | <blockquote>v = v / e</blockquote>
| |
− | | |
− | ====<br /> (|= v e) ====
| |
− | <blockquote>v = v | e</blockquote>
| |
− | | |
− | ====<br /> (&= v e) ====
| |
− | <blockquote>v = v & e</blockquote>
| |
− | | |
− | ====<br /> (^= v e) ====
| |
− | <blockquote>v = v ^ e</blockquote>
| |
− | | |
− | ====<br /> (>>= v e) ====
| |
− | <blockquote>v = v >> e</blockquote>
| |
− | | |
− | ====<br /> (<<= v e) ====
| |
− | <blockquote>v = v << e</blockquote>
| |
− | | |
− | ====<br /> (++ v) ====
| |
− | <blockquote>v = v + 1</blockquote>
| |
− | | |
− | ====<br /> (-- v) ====
| |
− | <blockquote>v = v - 1</blockquote>
| |
− | | |
− | ==<br /> Control Flow ==
| |
− | | |
− | In the following, code1, ..., codeN are arbitrary sequences of expressions. There are no BEGIN ... END blocks as in Pascal or progn forms as in Lisp.
| |
− | | |
− | The value of a control flow expression is the value of the last expression in the control body which was evaluated. Thus, if we execute the following code:
| |
− | | |
− | <blockquote>
| |
− | <div class="CodeBlockHeader">Code:</div>
| |
− | <syntaxhighlight lang="sci">
| |
− | (= x 3)
| |
− | (= y 2)
| |
− | (= y (if (> x y)
| |
− | (- x y)
| |
− | else
| |
− | (+ x y)
| |
− | )
| |
− | )
| |
− | </syntaxhighlight>
| |
− | </blockquote>
| |
− | | |
− | y will have the value 1.
| |
− | | |
− | ===<br /> Return: ===
| |
− | | |
− | <blockquote>
| |
− | <div class="CodeBlockHeader">Code:</div>
| |
− | <syntaxhighlight lang="sci">
| |
− | (return [expression])
| |
− | </syntaxhighlight>
| |
− | </blockquote>
| |
− | | |
− | The return statement returns control to the procedure which called the currently executing procedure. If the optional expression is present, that value is returned as the value of the current procedure. There is an implicit return at the end of all procedures, and the value returned in that case is the value of the last expression evaluated. A return from the main procedure of script 0 returns to the operating system.
| |
− | | |
− | ===<br /> Conditionals: ===
| |
− | | |
− | <blockquote>
| |
− | <div class="CodeBlockHeader">Code:</div>
| |
− | <syntaxhighlight lang="sci">
| |
− | (if expression code1 [else code2])
| |
− | </syntaxhighlight>
| |
− | </blockquote>
| |
− | | |
− | If expression is not FALSE, execute code1, else execute code2. (The else clause is optional).
| |
− | | |
− | <blockquote>
| |
− | <div class="CodeBlockHeader">Code:</div>
| |
− | <syntaxhighlight lang="sci">
| |
− | (cond (e1 code1) (e2 code2) ... [(else codeN)])
| |
− | </syntaxhighlight>
| |
− | </blockquote>
| |
− | | |
− | Evaluate e1. If it is not FALSE, execute code1 and exit the cond clause. If it is FALSE, evaluate e2 and continue. If all of the expressions are FALSE and the optional else clause is present, execute codeN.
| |
− | | |
− | <blockquote>
| |
− | <div class="CodeBlockHeader">Code:</div>
| |
− | <syntaxhighlight lang="sci">
| |
− | (switch expression (exp1 code1) (exp2 code2) ... [(else codeN)])
| |
− | </syntaxhighlight>
| |
− | </blockquote>
| |
− | | |
− | Evaluate expression. If it is equal to exp1, execute code1 and exit the switch. If it is equal to exp2, execute code2 and exit. If it doesn't equal any of the expressions and the optional else clause is present, execute codeN.
| |
− | | |
− | ===<br /> Iteration: ===
| |
− | | |
− | <blockquote>
| |
− | <div class="CodeBlockHeader">Code:</div>
| |
− | <syntaxhighlight lang="sci">
| |
− | (for (initialization) condition (re-initialization) code)
| |
− | </syntaxhighlight>
| |
− | </blockquote>
| |
− | | |
− | Evaluate the expressions comprising initialization. Then evaluate condition. If the result is FALSE, exit the loop. Otherwise, execute code, then the expressions comprising re-initialization, and loop back to condition.
| |
− | | |
− | <blockquote>
| |
− | <div class="CodeBlockHeader">Code:</div>
| |
− | <syntaxhighlight lang="sci">
| |
− | (while condition code)
| |
− | </syntaxhighlight>
| |
− | </blockquote>
| |
− | | |
− | Evaluate condition. If not FALSE, execute code and loop back to evaluate condition again. Exit the loop when condition is FALSE. (Note that this means that the value of a while condition is always FALSE.) This is equivalent to
| |
− | | |
− | <blockquote>
| |
− | <div class="CodeBlockHeader">Code:</div>
| |
− | <syntaxhighlight lang="sci">
| |
− | (for () condition () code)
| |
− | </syntaxhighlight>
| |
− | </blockquote>
| |
− | | |
− | <blockquote>
| |
− | <div class="CodeBlockHeader">Code:</div>
| |
− | <syntaxhighlight lang="sci">
| |
− | (repeat code)
| |
− | </syntaxhighlight>
| |
− | </blockquote>
| |
− |
| |
− | Continually execute the code until some condition in the code (a break) causes the loop to be exited. This is equivalent to
| |
− | | |
− | <blockquote>
| |
− | <div class="CodeBlockHeader">Code:</div>
| |
− | <syntaxhighlight lang="sci">
| |
− | (while TRUE code)
| |
− | </syntaxhighlight>
| |
− | </blockquote>
| |
− | | |
− | or
| |
− | | |
− | <blockquote>
| |
− | <div class="CodeBlockHeader">Code:</div>
| |
− | <syntaxhighlight lang="sci">
| |
− | (for () TRUE () code)
| |
− | </syntaxhighlight>
| |
− | </blockquote>
| |
− | | |
− | ===<br /> Supporting constructs for iteration: ===
| |
− | | |
− | <blockquote>
| |
− | <div class="CodeBlockHeader">Code:</div>
| |
− | <syntaxhighlight lang="sci">
| |
− | (break [n])
| |
− | </syntaxhighlight>
| |
− | </blockquote>
| |
− |
| |
− | Break out of n levels of loops. If n is not specified break out of the innermost loop.
| |
− | | |
− | <blockquote>
| |
− | <div class="CodeBlockHeader">Code:</div>
| |
− | <syntaxhighlight lang="sci">
| |
− | (breakif expression [n])
| |
− | </syntaxhighlight>
| |
− | </blockquote>
| |
− | | |
− | If expression is not FALSE, break out of n levels of loops. If n is not specified, break out of the innermost loop.
| |
− | | |
− | <blockquote>
| |
− | <div class="CodeBlockHeader">Code:</div>
| |
− | <syntaxhighlight lang="sci">
| |
− | (continue [n])
| |
− | </syntaxhighlight>
| |
− | </blockquote>
| |
− | | |
− | Loop back to the beginning of the nth level loop. If n is not specified, loop to the beginning of the innermost loop.
| |
− | | |
− | <blockquote>
| |
− | <div class="CodeBlockHeader">Code:</div>
| |
− | <syntaxhighlight lang="sci">
| |
− | (contif expression [n])
| |
− | </syntaxhighlight>
| |
− | </blockquote>
| |
− | | |
− | If expression is not FALSE, loop back to the beginning of the nth level loop. If n is not specified, loop to the beginning of the innermost loop.
| |
− | | |
− | ==<br /> Procedures ==
| |
− | | |
− | Procedures are created with the procedure construct:
| |
− | | |
− | <blockquote>
| |
− | <div class="CodeBlockHeader">Code:</div>
| |
− | <syntaxhighlight lang="sci">
| |
− | (procedure (proc-name [p1 p2 ...] [&tmp t1 t2...])
| |
− | code
| |
− | )
| |
− | </syntaxhighlight>
| |
− | </blockquote>
| |
− | | |
− | This defines the procedure with the name proc-name. This procedure takes parameters p1, p2, ... and allocates temporary variables (which disappear on exit from the procedure) t1, t2, .... Note that the procedure may take no parameters and have no automatic variables. In this case, the definition would be
| |
− | | |
− | <blockquote>
| |
− | <div class="CodeBlockHeader">Code:</div>
| |
− | <syntaxhighlight lang="sci">
| |
− | (procedure (proc-name)
| |
− | code
| |
− | )
| |
− | </syntaxhighlight>
| |
− | </blockquote>
| |
− | | |
− | You can define temporary arrays in the same way as you would local arrays:
| |
− | | |
− | <blockquote>
| |
− | <div class="CodeBlockHeader">Code:</div>
| |
− | <syntaxhighlight lang="sci">
| |
− | (procedure (proc-name &tmp [array n])
| |
− | code
| |
− | )
| |
− | </syntaxhighlight>
| |
− | </blockquote>
| |
− | | |
− | Code in these examples is any list of valid expressions.
| |
− | | |
− | All procedures have at least one parameter, the compiler defined variable argc (argument count), which gives the number of parameters passed to the procedure.
| |
− | | |
− | For example, you might define the procedure square, to square a number, as follows:
| |
− | | |
− | <blockquote>
| |
− | <div class="CodeBlockHeader">Code:</div>
| |
− | <syntaxhighlight lang="sci">
| |
− | (procedure (square n)
| |
− | (* n n)
| |
− | )
| |
− | </syntaxhighlight>
| |
− | </blockquote>
| |
− | | |
− | or the procedure max to find the maximum of an arbitrary number of numbers passed to the procedure:
| |
− | | |
− | <blockquote>
| |
− | <div class="CodeBlockHeader">Code:</div>
| |
− | <syntaxhighlight lang="sci">
| |
− | (procedure
| |
− | (max
| |
− | p ;parameters (will be accessed as an array)
| |
− | &tmp
| |
− | biggest ;temporary variable containing maximum
| |
− | i ;index into parameter array
| |
− | )
| |
− | | |
− | (for ((= i 0) (= biggest 0))
| |
− | (< i argc) ;compare to number of parameters passed.
| |
− | ((++ i)) ;note that this is a LIST of expressions,
| |
− | ;not a single expression.
| |
− | | |
− | (if (> [p i] biggest)
| |
− | (= biggest [p i])
| |
− | )
| |
− | | |
− | )
| |
− | | |
− | (return biggest)
| |
− | )
| |
− | </syntaxhighlight>
| |
− | </blockquote>
| |
− | | |
− | | |
− | The call
| |
− | | |
− | <blockquote>
| |
− | <div class="CodeBlockHeader">Code:</div>
| |
− | <syntaxhighlight lang="sci">
| |
− | (max 3 -4 -9 0 -2 7 12 4 3 5)
| |
− | </syntaxhighlight>
| |
− | </blockquote>
| |
− | | |
− | will return the value 12.
| |
− | | |
− | In order to use a procedure before it has been defined in a source file (for example making a call to max before the actual definition of max), the compiler must be told that the procedure's name corresponds to a procedure, not an object. This is done with another form of the procedure statement:
| |
− | | |
− | <blockquote>
| |
− | <div class="CodeBlockHeader">Code:</div>
| |
− | <syntaxhighlight lang="sci">
| |
− | (procedure
| |
− | procedure-name
| |
− | procedure-name
| |
− | ...
| |
− | )
| |
− | </syntaxhighlight>
| |
− | </blockquote>
| |
− | | |
− | Tells the compiler to compile code for procedure calls when it encounters procedure-name, rather than code for send messages to an object.
| |
− | | |
− | ===<br > &rest: ===
| |
− | | |
− | Argc, as discussed above, makes it easy to write procedures (or methods, discussed in Object Oriented Programming in Script) which handle a variable number of arguments. If a procedure or method has received a variable number of arguments and wants to pass them on to another procedure or method, things get messy. The only way to do this given only argc is to build a switch statement on argc which looks like
| |
− | | |
− | <blockquote>
| |
− | <div class="CodeBlockHeader">Code:</div>
| |
− | <syntaxhighlight lang="sci">
| |
− | (procedure (foo arg)
| |
− | (switch argc
| |
− | (0 (mumble))
| |
− | (1 (mumble arg))
| |
− | (2 (mumble arg [arg 1]))
| |
− | (3 (mumble arg [arg 1] [arg 2]))
| |
− | ...
| |
− | )
| |
− | )
| |
− | </syntaxhighlight>
| |
− | </blockquote>
| |
− | | |
− | This not only involves a lot of typing and generates a lot of code, it limits the number of arguments which can be passed to the next function (you can only type a finite number of clauses in the switch statement).
| |
− | | |
− | &rest exists to solve this problem -- it stands for the rest of the parameters not specified in the procedure or method definition. The above procedure could then be written simply as
| |
− | | |
− | <blockquote>
| |
− | <div class="CodeBlockHeader">Code:</div>
| |
− | <syntaxhighlight lang="sci">
| |
− | (procedure (foo)
| |
− | (mumble &rest)
| |
− | )
| |
− | </syntaxhighlight>
| |
− | </blockquote>
| |
− | | |
− | which is not only easier to type and read but also produces smaller, faster object code.
| |
− | | |
− | A variant of &rest allows you to specify all parameters starting at any point in a parameter list of a procedure or method definition:
| |
− | | |
− | <blockquote>
| |
− | <div class="CodeBlockHeader">Code:</div>
| |
− | <syntaxhighlight lang="sci">
| |
− | (procedure (foo arg1 arg2 arg3 arg4)
| |
− | (mumble (&rest arg3))
| |
− | )
| |
− | </syntaxhighlight>
| |
− | </blockquote>
| |
− | | |
− | passes all arguments starting with arg3 to procedure mumble.
| |
− | | |
− | ===<br > Extern: ===
| |
− | | |
− | Calling a procedure in another script is another matter. Since there is no link phase in the development cycle, one procedure cannot know the address of a procedure in a different script. The extern statement allows a script to know where the external procedure is:
| |
− | | |
− | <blockquote>
| |
− | <div class="CodeBlockHeader">Code:</div>
| |
− | <syntaxhighlight lang="sci">
| |
− | (extern
| |
− | procedure-name script-number entry-number
| |
− | ...
| |
− | )
| |
− | </syntaxhighlight>
| |
− | </blockquote>
| |
− | | |
− | This says that the procedure referred to by the symbol procedure-name in this script is to be found in script number script-number at entry number entry-number in the script's dispatch table. kernel.sh and base.sh both use the extern statement to let all other scripts know where their public procedures are.
| |
− | | |
− | The dispatch table for a script is defined by the public statement:
| |
− | | |
− | ===<br > Public: ===
| |
− | | |
− | All procedures within a script which are to be accessed from outside the script must be entered in the dispatch table for the script with the public statement:
| |
− | | |
− | <blockquote>
| |
− | <div class="CodeBlockHeader">Code:</div>
| |
− | <syntaxhighlight lang="sci">
| |
− | (public
| |
− | procedure-name entry-number
| |
− | ...
| |
− | )
| |
− | </syntaxhighlight>
| |
− | </blockquote>
| |
− | | |
− | puts the procedure procedure-name in the dispatch table at entry number entry-number. The entries need not be in numeric order, nor do the numbers need to be continuous (though if they're not continuous the table will be larger than it needs to be).
| |
− | | |
− | ==<br /> Using SC ==
| |
− | | |
− | The sc compiler is invoked with the command
| |
− | | |
− | <blockquote>
| |
− | <div class="CodeBlockHeader">Code:</div>
| |
− | <syntaxhighlight lang="sci">
| |
− | sc file_spec [file_spec] [options]
| |
− | </syntaxhighlight>
| |
− | </blockquote>
| |
− | | |
− | Any number of file specifications may be entered on the command line, and a file specification may include wild-card names.
| |
− | | |
− | ===<br /> Options: ===
| |
− |
| |
− | ====<br /> -l ====
| |
− | <blockquote>Generate an assembly language code listing for the file. This is useful when using the built-in debugger of sci, which lists only the assembly language code, not the source. When compiling filename.sc, the list file is named filename.sl</blockquote>
| |
− | | |
− | ====<br /> -n ====
| |
− | <blockquote>Turns off 'auto-naming' of objects. As described in Script Classes for Adventure Games, each object has a name, or 'print-string' property, which is how to represent the object textually. Unless the property is explicitly set, the compiler will generate the value for this property automatically, using the object's symbol string for the name. The object names, however, take up space in the heap. While they are useful (almost vital) for debugging, if you're running out of heap in a room, it might help to compile with the -n option to leave the names out.</blockquote>
| |
− |
| |
− | ====<br /> -oout-dir ====
| |
− | <blockquote>Set the directory for the output file (script.nnn) to out-dir.</blockquote>
| |
− |
| |
− | ====<br /> -v ====
| |
− | <blockquote>Turns on verbose mode, which prints the number of bytes occupied by various parts of the output file (code, objects, text, etc.).</blockquote>
| |
− |
| |
− | ====<br /> -z ====
| |
− | <blockquote>Turn off optimization. Not a particularly useful option except for those of us who must maintain the compiler.</blockquote>
| |
− | | |
− | == <br />Index ==
| |
| | | |
− | ! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13<br />
| + | [[Category:SCI Documentation]] |
− | != . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14<br />
| + | [[Category:Scripting]] |
− | + . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13<br />
| |
− | ++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15<br />
| |
− | += . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15<br />
| |
− | - . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13<br />
| |
− | -- . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15<br />
| |
− | -= . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15<br />
| |
− | <nowiki>*</nowiki> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13<br />
| |
− | <nowiki>*=</nowiki> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15<br />
| |
− | / . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13<br />
| |
− | /= . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15<br />
| |
− | ^ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13<br />
| |
− | ^= . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15<br />
| |
− | < . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14<br />
| |
− | << . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13<br />
| |
− | <<= . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15<br />
| |
− | <= . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14<br />
| |
− | = . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15<br />
| |
− | == . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14<br />
| |
− | > . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14<br />
| |
− | >= . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14<br />
| |
− | >> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13<br />
| |
− | >>= . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15<br />
| |
− | & . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13<br />
| |
− | &= . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15<br />
| |
− | &rest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20<br />
| |
− | | . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13<br />
| |
− | |= . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15<br />
| |
− | ~ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13<br />
| |
− | and . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14<br />
| |
− | arithmetic primitives . . . . . . . . . . . . . . . . . . . . . . . . . 13<br />
| |
− | array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9<br />
| |
− | arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9<br />
| |
− | assignment primitives . . . . . . . . . . . . . . . . . . . . . . . . . 15<br />
| |
− | base.sh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4<br />
| |
− | boolean primitives . . . . . . . . . . . . . . . . . . . . . . . . . . . 14<br />
| |
− | break . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17<br />
| |
− | breakif . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17<br />
| |
− | characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12<br />
| |
− | classdef . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4<br />
| |
− | classtbl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4<br />
| |
− | cond . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16<br />
| |
− | conditionals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16<br />
| |
− | contif . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18<br />
| |
− | continue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18<br />
| |
− | define . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6<br />
| |
− | enum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6<br />
| |
− | extern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21<br />
| |
− | for . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17<br />
| |
− | global . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8<br />
| |
− | if . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16<br />
| |
− | include . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5<br />
| |
− | iteration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17<br />
| |
− | kernal.sh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4<br />
| |
− | local . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8<br />
| |
− | mod . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13<br />
| |
− | not . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14<br />
| |
− | numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8<br />
| |
− | options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23<br />
| |
− | or . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14<br />
| |
− | pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10<br />
| |
− | procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19, 20<br />
| |
− | public . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22<br />
| |
− | repeat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17<br />
| |
− | return . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16<br />
| |
− | sc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23<br />
| |
− | script# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5<br />
| |
− | selector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4<br />
| |
− | <nowiki> literal</nowiki> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12<br />
| |
− | SINCLUDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5<br />
| |
− | switch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17<br />
| |
− | synonyms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7<br />
| |
− | text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10<br />
| |
− | variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8<br />
| |
− | <nowiki> global</nowiki> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8<br />
| |
− | <nowiki> local</nowiki> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8<br />
| |
− | <nowiki> temporary</nowiki> . . . . . . . . . . . . . . . . . . . . . . . . . . . 8, 19<br />
| |
− | vocab.000 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4<br />
| |
− | while . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17<br />
| |
− | word strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11<br />
| |