|
|
(67 intermediate revisions by the same user not shown) |
Line 1: |
Line 1: |
− | The Script Programming Language
| + | [[Official SCI Documentation]]<br /> |
| | | |
− | | + | <div align="center"><span style="font-size: 22pt">The Script Programming Language</span><br /> |
− | Author: Jeff Stephenson<br />
| + | ''Author: [[Jeff Stephenson]]''<br /> |
− | Date: 4 April 1988
| + | Date: 4 April 1988</div> |
− | | |
− | | |
− | ==<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>
| |
− | | |
− | The parameters to a procedure may themselves be expressions to be evaluated, and may be nested until you lose track of the parentheses.
| |
− | | |
− | Unlike Lisp, the procedure itself may NOT be the result of an evaluation. An example of an expression is
| |
− | | |
− | <blockquote>
| |
− | <div class="CodeBlockHeader">Code:</div>
| |
− | <syntaxhighlight lang="sci">
| |
− | (+ (- y 2) (/ x 3))
| |
− | </syntaxhighlight>
| |
− | </blockquote>
| |
− | | |
− | which would be written in infix notation as
| |
− | | |
− | <blockquote>
| |
− | <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 ==
| |
− | | |
− | Source files for the script compiler have the extension .sc, header (include) files have the extension .sh. Source files may have any filename -- banner.sc and castle.sc are two examples. The output file from the compilation will have the name script.nnn where nnn is determined from the script# command (covered below) which is present in the file.
| |
− | | |
− | There are six files besides the source file and any user-defined header files which are involved in a compilation.
| |
− | | |
− | '''classdef''' | |
− | <blockquote>This file contains the information about the structure of the classes which have been defined in the application. It is read automatically by the compiler and is rewritten by the compiler after a successful compilation in order to keep it up to date. The user need not be concerned with it.</blockquote>
| |
− | | |
− | '''selector'''
| |
− | <blockquote>This contains definitions of selectors which are used in object-oriented programming. It is automatically included in a compile and, like classdef, is rewritten after a successful compile. Any symbol in a properties or methods statement or in the selector position in a send to an object is assumed to be a selector and is assigned a selector number in included in selector.</blockquote>
| |
− | | |
− | '''kernel.sh'''
| |
− | <blockquote>This contains the definitions for interfacing with the kernel (the machine language interpreter). It is maintained by the kernel programmers and is automatically included in system.sh.</blockquote>
| |
− | | |
− | '''system.sh'''
| |
− | <blockquote>This contains the definitions for interfacing with the various system classes. It is initially provided by the kernel programmers. If you wish to tweak the system scripts yourself, you will also be responsible for maintaining your copy of system.sh. It should be included in all compiles.</blockquote>
| |
− | | |
− | '''vocab.000'''
| |
− | <blockquote>This is the compiled output of vocab.txt, generated by the vocabulary compiler vc. It is automatically included in a compile.</blockquote>
| |
− | | |
− | '''classtbl'''
| |
− | <blockquote>This is an output file of the compiler which is used by the kernel to determine which script a given class is defined in. You needn't do anything to it other than not delete it.</blockquote>
| |
− | | |
− | There are two sc commands for dealing with source code organization:
| |
− | | |
− | '''script#:'''
| |
− | | |
− | The script# command sets the script number of the output file:
| |
− | <div class="CodeBlockHeader">Code:</div>
| |
| | | |
| <blockquote> | | <blockquote> |
− | <syntaxhighlight lang="sci">
| + | *[[The Script Programming Language/Introduction | Introduction]] |
− | (script# 4)
| + | *[[The Script Programming Language/Files | Files]] |
− | </syntaxhighlight>
| + | *[[The Script Programming Language/Definitions | Definitions]] |
| + | *[[The Script Programming Language/Data Types and Variables | Data Types and Variables]] |
| + | *[[The Script Programming Language/Primitive Procedures | Primitive Procedures]] |
| + | **[[The Script Programming Language/Primitive Procedures#Arithmetic primitives | Arithmetic primitives]] |
| + | **[[The Script Programming Language/Primitive Procedures#Boolean primitives | Boolean primitives]] |
| + | **[[The Script Programming Language/Primitive Procedures#Assignment primitives | Assignment primitives]] |
| + | *[[The Script Programming Language/Control Flow | Control Flow]] |
| + | **[[The Script Programming Language/Control Flow#Conditionals | Conditionals]] |
| + | **[[The Script Programming Language/Control Flow#Iteration | Iteration]] |
| + | *[[The Script Programming Language/Procedures | Procedures]] |
| + | *[[The Script Programming Language/Using SC | Using SC]] |
| + | *[[The Script Programming Language/Index | Index]] |
| </blockquote> | | </blockquote> |
| | | |
− | sets the output file name to script.004, regardless of the actual name of
| + | <div align="center"> |
− | the source file.
| + | Chapter: |
− |
| + | [[The Script Programming Language/Introduction|1]] | |
− | '''include:'''
| + | [[The Script Programming Language/Files|2]] | |
− |
| + | [[The Script Programming Language/Definitions|3]] | |
− | This includes a header file in the current source file at the current position.
| + | [[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 /> |
| | | |
− | <blockquote>
| + | * [[Media:SCRIPT.pdf|Download The Script Programming Language in PDF Form]]<br /> |
− | <div class="CodeBlockHeader">Code:</div>
| |
− | <syntaxhighlight lang="sci">
| |
− | (include "/sc/foo.sh")
| |
− | </syntaxhighlight>
| |
− | </blockquote> | |
| | | |
− | or
| |
| | | |
− | <blockquote>
| + | |
− | <div class="CodeBlockHeader">Code:</div>
| |
− | <syntaxhighlight lang="sci">
| |
− | (include /sc/foo.sh)
| |
− | </syntaxhighlight>
| |
− | </blockquote>
| |
| | | |
− | include the file /sc/foo.sh. Include files may be nested as deeply as desired.
| + | <span style="float: left"><span class="Inactive">< Previous: </span></span><span style="float: right">[[The Script Programming Language/Introduction|Next: Introduction >]]</span> |
| | | |
− | When including a file, the compiler first looks for the file in the current directory. If it fails to find it there, it then looks for it in the directories specified in the environment variable SINCLUDE. This variable is just like the DOS PATH variable -- the directories to search are separated by semi-colons. Thus, if you want the compiler to look for include files in f:/games/sci/system and c:/include if it doesn't find them in the current directory, you put the line
| + | |
− |
| |
− | <blockquote>
| |
− | <div class="CodeBlockHeader">Code:</div>
| |
− | <syntaxhighlight lang="sci">
| |
− | set sinclude=f:/games/sci/system;c:/include
| |
− | </syntaxhighlight>
| |
− | </blockquote>
| |
− | | |
− | in your autoexec.bat file.
| |
− | | |
− | == <br /> Definitions ==
| |
− | | |
− | ===<br /> define: ===
| |
− | | |
− | The define statement allows you to define a symbol which will stand for a
| |
− | string of text:
| |
− | | |
− | <blockquote>
| |
− | <div class="CodeBlockHeader">Code:</div>
| |
− | <syntaxhighlight lang="sci">
| |
− | (define symbol lots of text)
| |
− | </syntaxhighlight>
| |
− | </blockquote>
| |
− | | |
− | will replace symbol, wherever it is encountered as a token, with lots of
| |
− | text and then continue scanning at the beginning of the replacement text.
| |
− | Thus, if we write
| |
− | | |
− | <blockquote>
| |
− | <div class="CodeBlockHeader">Code:</div>
| |
− | <syntaxhighlight lang="sci">
| |
− | (define symbol some text)
| |
− | (define some even more)
| |
− | </syntaxhighlight>
| |
− | </blockquote>
| |
− | | |
− | then
| |
− | | |
− | <blockquote>
| |
− | <div class="CodeBlockHeader">Code:</div>
| |
− | <syntaxhighlight lang="sci">
| |
− | (symbol)
| |
− | </syntaxhighlight>
| |
− | </blockquote>
| |
− | | |
− | will become
| |
− | | |
− | <blockquote>
| |
− | <div class="CodeBlockHeader">Code:</div>
| |
− | <syntaxhighlight lang="sci">
| |
− | (some text)
| |
− | </syntaxhighlight>
| |
− | </blockquote>
| |
− | | |
− | which then becomes
| |
− | | |
− | <blockquote>
| |
− | <div class="CodeBlockHeader">Code:</div>
| |
− | <syntaxhighlight lang="sci">
| |
− | (even more text)
| |
− | </syntaxhighlight>
| |
− | </blockquote>
| |
| | | |
− | ===<br /> enum: ===
| + | [[Category:SCI Documentation]] |
| + | [[Category:Scripting]] |