home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / compiler / small_c / scinter / usr.man < prev    next >
Encoding:
Text File  |  1986-03-15  |  109.6 KB  |  3,180 lines

  1.           
  2.           
  3.           
  4.           
  5.           
  6.           
  7.           
  8.           
  9.           
  10.           
  11.           
  12.           
  13.                                                      ii
  14.                                                     iiii
  15.                                                      ii
  16.                          sss           cccc             
  17.                        ssssssss      cccccccc      iiiii
  18.                       sss    sss    ccc    ccc     iiiii
  19.                       sssss        ccc               iii
  20.                        sssss       ccc               iii
  21.                           sssss    ccc               iii
  22.                       sss    sss    ccc    ccc       iii
  23.                        ssssssss      cccccccc     iiiiiiiii
  24.                          ssss          cccc       iiiiiiiii
  25.           
  26.           
  27.                              Small C Interpreter
  28.                            Version 1.3 for MS-DOS
  29.                         Copyright (C) 1986 Bob Brodt
  30.           
  31.           
  32.                                 User's Manual
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.      Small C Interpreter                                      User's Manual
  62.  
  63.  
  64.      1. Introduction 
  65.  
  66.  
  67.                SCI is a "C" language interpreter loosely based on the 
  68.           language subset described in James Hendrix' "Small C" (see 
  69.           the Appendix "Differences From Small C").  It is a fully 
  70.           interactive interpreter (no compilation!) that includes a 
  71.           powerful full screen editor and a program trace facility.  
  72.           SCI was meant to be a stepping stone for the experienced 
  73.           BASIC programmer who is ready to move up to the exciting 
  74.           world of "C"!  
  75.  
  76.                SCI will run on any MS-DOS or PC-DOS computer that has 
  77.           a minimum of 64Kbytes of RAM, although 128Kbytes is 
  78.           recommended.  The available free memory (that portion of 
  79.           memory not used by the interpreter's code and data storage) 
  80.           is automatically divided among "user progam code", "variable 
  81.           table", "function table" and "stack" memory segments.  If 
  82.           necessary, the sizes of these segments may be changed at 
  83.           program startup, however their total may not exceed 
  84.           64Kbytes.  
  85.  
  86.                The integrated full-screen editor does require that the 
  87.           terminal emulation firmware in your computer be capable of 
  88.           recognizing certain terminal control character sequences 
  89.           (also known as "escape sequences") that perform cursor 
  90.           positioning and erasing of portions of the screen.  See the 
  91.           installation instructions in the "Editor" section of this 
  92.           manual.  
  93.  
  94.                The SCI interpreter is very similar to BASIC 
  95.           internally.  Each line of input is first scanned and 
  96.           "tokenized", a process in which language elements (numbers, 
  97.           variables, keywords, etc.) are converted to one-, two- or 
  98.           three-byte "tokens". These tokens are easier to handle by a 
  99.           computer than arbitrarily long character sequences.  Unlike 
  100.           BASIC however, SCI programs do not require line numbers - 
  101.           the program flow is directed by SCI purely through the 
  102.           structured programming constructs inherent in the "C" 
  103.           language.  This tokenization process allows SCI to run much 
  104.           faster than other interpreters that deal with the raw 
  105.           program text.  However, the "C" language was never designed 
  106.           to be an interpreted programming language like BASIC was, 
  107.           and the price that must be paid for this advantage is in the 
  108.           form of incompatibilities with standard "C" as defined by 
  109.           Kernighan and Ritchie.  
  110.  
  111.  
  112.      1.1. This Manual 
  113.  
  114.  
  115.                The documentation for SCI is found in the files 
  116.  
  117.  
  118.                                      - 1 -
  119.  
  120.  
  121.      Small C Interpreter                                      User's Manual
  122.  
  123.  
  124.           "USER.MAN" and "PROG.MAN" on the distribution disk.  It is 
  125.           divided into two sections: this, the "User's Manual" and the 
  126.           "Programmer's Manual".  
  127.  
  128.                If you already have a working knowledge of the C 
  129.           language, the User's Manual is all you need to help you get 
  130.           started quickly with SCI.  It contains a brief overview of 
  131.           SCI's features, a thorough description of the built-in 
  132.           editor with installation instructions, a list of "Library 
  133.           Functions" available to your program and a summary 
  134.           description of SCI's language subset.  The User's Manual 
  135.           also contains a brief description of the SCI symbolic 
  136.           debuger.  In the Appendix you will find quick reference 
  137.           sections that include a complete and terse definition of the 
  138.           language subset supported by SCI, a command summary for the 
  139.           SCI editor and program debuger, and an explanation of SCI 
  140.           error messages.  
  141.  
  142.                If you are just starting out in learning C, you will 
  143.           most likely want to read the overview section in the User's 
  144.           Manual and then go directly to the Programmer's Manual. The 
  145.           Programmer's Manual is a very introductory tutorial on the C 
  146.           language.  It is designed to be used along with SCI so that 
  147.           you can learn C by experimentation.  If you have a working 
  148.           knowledge of another programming language such as BASIC, you 
  149.           should have no trouble getting through the tutorial.  The 
  150.           Programmer's Manual also contains an introduction to program 
  151.           debuging techniques and full treatment of SCI's built-in 
  152.           debuger.  
  153.  
  154.  
  155.      1.2. Starting Out 
  156.  
  157.  
  158.                The files on the distribution diskette are: 
  159.  
  160.  
  161.                SCI.COM      - the interpreter program
  162.                SHELL.SCI    - the command shell, written in C
  163.                CALC.SCI     - a sample calculator program
  164.                USER.MAN     - User's Manual
  165.                PROG.MAN     - Programmer's Manual
  166.  
  167.  
  168.                As always, it is a good idea to make a working copy, 
  169.           and then store your distribution diskette in a safe place.  
  170.  
  171.                To start up SCI, make sure that SHELL.SCI resides on 
  172.           the current drive and then execute SCI.COM. The interpreter 
  173.           will then read and execute the C program it finds in 
  174.           SHELL.SCI. The program provided for  you in this file 
  175.           contains several items of information needed by the built in 
  176.  
  177.  
  178.                                      - 2 -
  179.  
  180.  
  181.      Small C Interpreter                                      User's Manual
  182.  
  183.  
  184.           editor, as well as some other useful functions.  The program 
  185.           in SHELL.SCI that gets executed by the interpreter is simply 
  186.           an endless loop that prompts you for a line of input from 
  187.           the console and hands it off to the interpreter for 
  188.           execution.  Actually this function could have been performed 
  189.           by the SCI program itself, but by placing this routine 
  190.           outside of the interpreter, you have the option of 
  191.           customizing the interpreter to suit your tastes.  See the 
  192.           section on The Shell in the Programmer's Manual for a 
  193.           detailed discussion of shell functions and customization.  
  194.  
  195.                You may also specify a different program file for SCI 
  196.           to execute on startup.  By typing the following operating 
  197.           system command line, for example: 
  198.  
  199.  
  200.                A>SCI B:STARTUP
  201.  
  202.           
  203.           the interpreter will search disk B: for a file called 
  204.           STARTUP and execute it in lieu of the default SHELL.SCI 
  205.           file.  Be aware, however, that the standard SHELL.SCI file 
  206.           contains many often-used operating system interface 
  207.           functions that must be copied over to your customized 
  208.           startup program if they are going to be used by that 
  209.           program.  See the section on Library Functions for a list of 
  210.           these functions.  
  211.  
  212.  
  213.      1.3. Memory Allocation 
  214.  
  215.  
  216.                The interpreter automatically divides up whatever free 
  217.           memory is available (after SCI is loaded) among four 
  218.           segments for use by your programs and data.  These segments 
  219.           are: the Program Code, Variable Table, Function Table and 
  220.           Stack. The Program Code segment contains the tokenized 
  221.           version of your program code.  The Variable Table contains 
  222.           information about all "active" variables.  Each function 
  223.           takes up exactly one entry in the Function Table. Finally, 
  224.           memory requirement for the Stack segment will grow and 
  225.           shrink as your program executes.  The stack is used only for 
  226.           temporary storage when expressions are evaluated.  
  227.  
  228.                If the interpreter complains about "out of memory", 
  229.           "too many variables", "too many functions" or "stack 
  230.           overflow", you may be able to circumvent the problem by 
  231.           telling SCI how much memory to assign to each of these four 
  232.           segments using the following MS-DOS command line options: 
  233.  
  234.  
  235.                -P nnnn - assign "nnnn" decimal bytes for program storage.
  236.  
  237.  
  238.                                      - 3 -
  239.  
  240.  
  241.      Small C Interpreter                                      User's Manual
  242.  
  243.  
  244.                -V nn   - allow space for a maximum of "nn" variables.
  245.                -F nn   - allow space for a maximum of "nn" functions.
  246.                -S nn   - set the stack size to "nn".
  247.  
  248.           
  249.           Thus, the command line: 
  250.  
  251.  
  252.                A>SCI -P 8000 -V 30 -F 80 -S 40
  253.  
  254.           
  255.           will set aside 8000 bytes for program storage, allow a 
  256.           maximum of 30 variables to be active at one time, allow a 
  257.           maximum of 80 function declarations and leave 40 stack 
  258.           entries.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298.                                      - 4 -
  299.  
  300.  
  301.      Small C Interpreter                                      User's Manual
  302.  
  303.  
  304.      2. Using the Shell Program 
  305.  
  306.  
  307.                The stock version of the "shell program", found in the 
  308.           file SHELL.SCI on your distribution disk, simply displays a 
  309.           prompt on the console, reads a line of input, and attempts 
  310.           to execute the input line.  
  311.  
  312.                The shell maintains your program in its "program 
  313.           buffer" in memory.  When SCI first starts up, this buffer is 
  314.           empty so you must either create a program using SCI's editor 
  315.           or retrieve a previously created program from disk.  Before 
  316.           you exit from the shell, be sure to save your program on 
  317.           disk or the contents of the program buffer will be lost.  
  318.  
  319.                The standard shell recognizes four basic (pardon the 
  320.           pun) commands: "edit", "list", "load", "save" and "exit".  
  321.           These are functionally similar to the BASIC commands: 
  322.           "EDIT", "LIST", "LOAD", "SAVE" and "SYSTEM" respectively.  
  323.           Later as you become more familiar with the C language, you 
  324.           may wish to modify the shell program and add your own 
  325.           commands.  
  326.  
  327.                Anything else typed at the shell prompt is assumed to 
  328.           be a valid C statement and is handed off to the interpreter 
  329.           to be executed.  
  330.  
  331.  
  332.      2.1. Shell Commands 
  333.  
  334.  
  335.                Listed below are the shell commands.  In the 
  336.           descriptions below, anything enclosed in square brackets ([ 
  337.           and ]) is optional and anything enclosed in angle brackets 
  338.           (< and >) is a verbose description of the item required by 
  339.           the command.  
  340.  
  341.  
  342.                edit [<line#>]
  343.  
  344.  
  345.                The "edit" command invokes SCI's built-in screen editor 
  346.           (see the Editor section in the User's Manual for more 
  347.           details).  If the word "edit" is followed with a line number 
  348.           (in decimal), the editor will start up by displaying the 
  349.           page of the program that contains the line number, and move 
  350.           the cursor to that line.  If the requested line number is 
  351.           greater than the number of lines in the program buffer, the 
  352.           last page of the program is displayed.  
  353.  
  354.  
  355.                list [<from_line#>] [<to_line#>]
  356.  
  357.  
  358.                                      - 5 -
  359.  
  360.  
  361.      Small C Interpreter                                      User's Manual
  362.  
  363.  
  364.                This command lists the program currently in the program 
  365.           buffer on the screen in its entirety.  The listing may be 
  366.           stoped by pressing any key.  If the word "list" is followed 
  367.           by one number, the listing starts at that line number in the 
  368.           program.  If two numbers seperated by one or more spaces 
  369.           follow "list", the program listing will start with the first 
  370.           and end with the second line number in the program.  
  371.  
  372.  
  373.                load <filename>
  374.  
  375.  
  376.                The "load" command will load the program buffer from 
  377.           the given disk file name.  This command will destroy the 
  378.           current contents of the program buffer.  If the file name is 
  379.           omitted or the file is not found, SCI will display a "file 
  380.           I/O error" message and erase the program buffer.  
  381.  
  382.  
  383.                save <filename>
  384.  
  385.  
  386.                This will write the contents of the program buffer out 
  387.           to the disk file name.  If the file name is omitted or the 
  388.           file can't be created, SCI displays the "file I/O error" 
  389.           message.  This command does not alter the program buffer in 
  390.           memory.  
  391.  
  392.                Programs that are "save"d by SCI are ordinary text 
  393.           files, suitable for editing with your favourite text 
  394.           editor.  
  395.  
  396.  
  397.                exit
  398.  
  399.  
  400.                This command returns you to the MS-DOS command level.  
  401.           If anything was left in the shell's program buffer, it will 
  402.           be lost unless you have previously "save"ed it in a disk 
  403.           file.  
  404.  
  405.  
  406.      2.2. Running Your Program 
  407.  
  408.  
  409.                A C program is simply a collection of "functions" which 
  410.           (hopefully) all participate to successfully perform a single 
  411.                                                 ____                     
  412.           task.  In "standard" C, every program must have one and only 
  413.           one function called "main".  This is where the program will 
  414.           start executing from.  In SCI's C, you need not have a 
  415.                                                         ___            
  416.           "main" function because SCI allows you to run any function 
  417.           in the program buffer by simply typing its name at the SCI 
  418.  
  419.  
  420.                                      - 6 -
  421.  
  422.  
  423.      Small C Interpreter                                      User's Manual
  424.  
  425.  
  426.           input prompt.  Suppose for example that our program buffer 
  427.           contained the following three functions: 
  428.  
  429.  
  430.                hex(n)
  431.                {
  432.                     putx(n);
  433.                }
  434.                oct(n)
  435.                {
  436.                     puto(n);
  437.                }
  438.                dec(n)
  439.                {
  440.                     putd(n);
  441.                }
  442.  
  443.  
  444.                We could execute any of these functions from the shell 
  445.           by simply typing, for example: 
  446.  
  447.  
  448.                > hex(256)
  449.  
  450.  
  451.                Note that we showed the shell's greater-than prompt (>) 
  452.           above for demonstration purposes only.  An SCI program is 
  453.           simply a collection of (not necessarily related) functions 
  454.           that can be run and debuged individually or in combination 
  455.           with other functions in the program buffer.  Thus if you 
  456.           plan to transport your program to a compiler, be sure to 
  457.           include a "main" function in the final product.  
  458.  
  459.  
  460.      2.3. Program Variables 
  461.  
  462.  
  463.                                ______                              
  464.                The interpreter always clears to zero all program 
  465.           variables before each shell statement is executed.  So if 
  466.           you initialize a variable from the shell, the same variable 
  467.           will be set to zero again before the very next C statement 
  468.           entered from the shell.  
  469.  
  470.                To illustrate, assume we have the following program in 
  471.           the program buffer: 
  472.  
  473.  
  474.  
  475.  
  476.  
  477.  
  478.  
  479.  
  480.  
  481.                                      - 7 -
  482.  
  483.  
  484.      Small C Interpreter                                      User's Manual
  485.  
  486.  
  487.                int sum;
  488.                
  489.                total(n)
  490.                {
  491.                     sum = sum + n;
  492.                }
  493.  
  494.  
  495.                This program uses the variable "sum" to keep a running 
  496.           total of numbers.  However, repeated calls to "total()" from 
  497.           the shell would be futile since the interpreter would always 
  498.           set "sum" to zero before each call.  
  499.  
  500.  
  501.  
  502.  
  503.  
  504.  
  505.  
  506.  
  507.  
  508.  
  509.  
  510.  
  511.  
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.  
  535.  
  536.  
  537.  
  538.  
  539.  
  540.  
  541.                                      - 8 -
  542.  
  543.  
  544.      Small C Interpreter                                      User's Manual
  545.  
  546.  
  547.      3. The Editor 
  548.  
  549.           
  550.  
  551.  
  552.      3.1. Introduction 
  553.  
  554.  
  555.                SCI's built in editor is screen oriented and is similar 
  556.           to the "standard" set by the popular WORDSTAR word 
  557.           processor.  The editor can be modified to work with almost 
  558.           any personal computer, by simply changing some variables in 
  559.           the shell file (SHELL.SCI).  This section will describe the 
  560.           installation procedure and give needed information for some 
  561.           of the more common personal computers.  
  562.  
  563.  
  564.      3.2. Keys 
  565.  
  566.  
  567.                The alphabetic character keys on your PC's keyboard are 
  568.           probably arranged in a typewriter keyboard pattern as shown 
  569.           below.  All editing commands (cursor motion, deleting, 
  570.           inserting, etc.) are control-key combinations (i.e. press 
  571.           and hold the CONTROL key and then press a letter key).  In 
  572.           this manual, we will use an up arrow, or circumflex (^) 
  573.           followed by a letter to indicate that the keystroke is a 
  574.           control-key combination.  In the keyboard diagram below, 
  575.           only the letter keys marked with an asterisk (*) are valid 
  576.           editing command control-keys.  What each of these 
  577.           control-keys does will be explained in detail in a later 
  578.           section.  
  579.  
  580.  
  581.                ----------------------------------------------
  582.                |                                            |
  583.                | -----------------------------------------  |
  584.                | | Q*| W*| E*| R*| T | Y*| U | I | O | P |  |
  585.                | -----------------------------------------  |
  586.                |   | A*| S*| D*| F*| G*| H*| J | K*| L*|    |
  587.                |   -------------------------------------    |
  588.                |      | Z*| X*| C*| V*| B*| N | M |         |
  589.                |      -----------------------------         |
  590.                |                                            |
  591.                ----------------------------------------------
  592.  
  593.  
  594.  
  595.      3.3. Screen Layout 
  596.  
  597.  
  598.                The editor uses all of the screen, except for the last 
  599.  
  600.  
  601.                                      - 9 -
  602.  
  603.  
  604.      Small C Interpreter                                      User's Manual
  605.  
  606.  
  607.           line, as a window into your program.  The last screen line 
  608.           is reserved for status and prompts.  The status line is 
  609.           divided into several fields as shown below: 
  610.  
  611.  
  612.                     L:nnnn C:nn  Insert  Mark:nnnn:nnnn
  613.                               |      |     |          |
  614.                               |      |     |     line numbers of start and
  615.                               |      |     |     end of a marked block
  616.                               |      |     |
  617.                               |      |   insert/replace mode indicator
  618.                               |      |
  619.                               |    current column number
  620.                               |
  621.                     current line number
  622.  
  623.  
  624.                The current line and column numbers are updated only if 
  625.           you haven't pressed a key within the last two seconds or 
  626.           so.  This lets you enter text or commands at typamatic 
  627.           speeds without slowing you down.  
  628.  
  629.                If an error should occur while you are editing your 
  630.           program, the status line will be erased and the error 
  631.           message displayed in its place.  You must then hit the 
  632.           <ESCAPE> key to acknowledge that you have seen the error 
  633.           message before you may continue editing.  Also, if the 
  634.           editor needs information from you (such as search strings, 
  635.           etc.) the appropriate prompts will appear in the status 
  636.           line.  
  637.  
  638.  
  639.      3.4. Configuration 
  640.  
  641.           
  642.  
  643.  
  644.      3.4.1. Screen Customization 
  645.  
  646.  
  647.                Modern computer terminals allow a programmer to 
  648.           manipulate the cursor and text displayed on the screen by 
  649.           means of specific character sequences sent to the terminal.  
  650.           These character sequences are known interchangably as 
  651.           "control codes" or "escape sequences".  
  652.  
  653.                Most personal computers have a program in ROM that 
  654.           emulates a specific terminal's control codes.  In the case 
  655.           of the IBM PC, this emulation program is a "device driver" 
  656.           program on disk (ANSI.SYS) and must be loaded into RAM when 
  657.           PC-DOS is first booted up (see your IBM PC-DOS manual for 
  658.           installation procedures of this device driver).  
  659.  
  660.  
  661.                                      - 10 -
  662.  
  663.  
  664.      Small C Interpreter                                      User's Manual
  665.  
  666.  
  667.                Your personal computer must have as a minimum, control 
  668.           codes to directly position the cursor anywhere on the 
  669.           screen, and either an "erase to end of line" or "erase to 
  670.           end of screen" control code.  The "erase to end of line" 
  671.           code must clear to spaces all character locations to the 
  672.           right of and including the cursor postion.  The "erase to 
  673.           end of screen" control code performs an "erase to end of 
  674.           line" function and then erases all lines below the current 
  675.           line to spaces.  If your terminal recognizes both of these 
  676.           erase control codes, use "erase to end of screen" in 
  677.           preference of "erase to end of line" because it is slightly 
  678.           faster.  
  679.  
  680.                If your computer does not provide these minimal control 
  681.           codes, SCI's built in editor can not be used.  In this case, 
  682.           you must resort to using your own text editor to write and 
  683.           modify your programs.  
  684.  
  685.                Your PC may also have control codes that perform more 
  686.           complicated functions such as inserting and deleting 
  687.           characters and lines.  These are not really necessary, 
  688.           however the editor is designed to take advantage of them if 
  689.           they exist.  You may need to do some experimenting with 
  690.           different combinations of escape sequence to achieve optimum 
  691.           speed performance from the editor.  
  692.  
  693.                A Terminal's control codes are made known to the SCI 
  694.           editor by way of system global program variables.  These 
  695.           program variables must be declared in your shell program 
  696.                                     ______                           
  697.           file (normally SHELL.SCI) before the "entry" keyword and 
  698.           must be assigned values in the mainline shell program (the 
  699.           function "main" in SHELL.SCI).  There is one variable for 
  700.           each control code.  If your PC does not have a particular 
  701.                                                            ___      
  702.           control code, that corresponding variable should not be 
  703.           declared.  All variables must be declared as character 
  704.           pointers (i.e. char *) with the exception of "_nr", "_nc", 
  705.           "_ro", "_co" and _mhz, which are all char's.  The variable 
  706.           names and their corresponding control code function are 
  707.           listed below: 
  708.  
  709.  
  710.                 cp                      
  711.                _cp - cursor postion.  
  712.  
  713.                 el                            
  714.                _el - erase to end of line.  
  715.  
  716.                 es                              
  717.                _es - erase to end of screen.  
  718.  
  719.                 dc                                                    
  720.                _dc - delete the character under the cursor and move 
  721.                     left all characters to the right of the cursor.  
  722.  
  723.                 dl                                                      
  724.                _dl - delete the line the cursor is on and move up all 
  725.                     lines below it.  
  726.  
  727.  
  728.                                      - 11 -
  729.  
  730.  
  731.      Small C Interpreter                                      User's Manual
  732.  
  733.  
  734.                 ic                                                 
  735.                _ic - insert a character before the one under the 
  736.                     cursor and move all characters to the right.  The 
  737.                            ____                                        
  738.                     cursor must remain at the same position (i.e. at 
  739.                     the inserted character).  
  740.  
  741.                 il                                                       
  742.                _il - insert a line before the one the cursor is on and 
  743.                                                               ____   
  744.                     move all lines below it down.  The cursor must 
  745.                     remain at the same position (i.e. on the newly 
  746.                     created blank line).  
  747.  
  748.                 bl                                                  
  749.                _bl - rings the console bell.  If this variable is 
  750.                     omitted, the standard ASCII BEL character will be 
  751.                     used (octal 007). You may also wish to flash the 
  752.                     screen momentarily to a different color if your PC 
  753.                     has color or reverse video capabilities.  
  754.  
  755.                 nr                                                       
  756.                _nr - number of rows (lines) on the screen.  Typically, 
  757.                     this is set to 24 (25 for the IBM PC).  
  758.  
  759.                 nc                                                     
  760.                _nc - number of columns, usually 80 but may be set to 
  761.                     40 on the IBM PC if you are in 40 column mode.  
  762.  
  763.                 ro                                                   
  764.                _ro - row offset.  The cursor position control code 
  765.                     assumes that the screen "home" position (top left 
  766.                     corner) starts at 0,0.  If this is not the case 
  767.                     for your PC you can add this offset, otherwise 
  768.                     omit this variable.  
  769.  
  770.                 co                                    
  771.                _co - column offset, same as above.  
  772.  
  773.                 mhz                                               
  774.                _mhz - CPU speed (in Megahertz) of your PC. This 
  775.                     variable controls the frequency at which the 
  776.                     editor's status line is updated.  
  777.  
  778.  
  779.                As mentioned earlier, the above variables are pointers 
  780.           to characters which should be assigned in your shell 
  781.           mainline program.  The assigned character strings may 
  782.           contain any of the data conversion codes recognized by the 
  783.           Library Function "printf()".  See the section on Sample 
  784.           Configurations (below) for examples.  
  785.  
  786.  
  787.      3.4.2. Keyboard Customization 
  788.  
  789.  
  790.                In addition, if any of the character pointer variables 
  791.           "_ka", "_kb", ... "_kz" are declared, the string pointed at 
  792.           by these variables is assumed to be the character sequence 
  793.           sent by a function key on your keyboard and will be 
  794.           recognized as an alias of the corresponding control-letter 
  795.           key combination.  
  796.  
  797.  
  798.                                      - 12 -
  799.  
  800.  
  801.      Small C Interpreter                                      User's Manual
  802.  
  803.  
  804.                For example, The VT-100 terminals send the character 
  805.           sequence: "ESCAPE [ A", "ESCAPE [ B", "ESCAPE [ C" and 
  806.           "ESCAPE [ D" for the up, down right and left arrow keys 
  807.           respectively.  So, instead of typing ^E, ^X, ^D and ^S to 
  808.           move the cursor around, we could declare the following 
  809.           variables: 
  810.  
  811.  
  812.                char *_ke, *_kx, *_kd, *_ks;
  813.                
  814.                _ke="\033[A";  # alias for ^E
  815.                _kx="\033[B";  # alias for ^X
  816.                _kd="\033[C";  # alias for ^D
  817.                _ks="\033[D";  # alias for ^S
  818.  
  819.           
  820.           and then use the VT-100's arrow function keys instead.  
  821.           Similarly, other keyboard function keys that transmit 
  822.           multiple characters or single control characters can be used 
  823.           to perform other editor functions.  
  824.  
  825.  
  826.      3.5. Sample Configurations 
  827.  
  828.  
  829.                This section contains the data declarations and 
  830.           assignments required by some of the more common PC's. The 
  831.           data declarations must be made before the "entry" keyword in 
  832.           SHELL.SCI, and the variable assignments must be done within 
  833.           the function immediately following the "entry" keyword.  For 
  834.           example, look at the configuration for the IBM PC in the 
  835.           distribution version of the SHELL.SCI file: 
  836.  
  837.  
  838.  
  839.  
  840.  
  841.  
  842.  
  843.  
  844.  
  845.  
  846.  
  847.  
  848.  
  849.  
  850.  
  851.  
  852.  
  853.  
  854.  
  855.  
  856.  
  857.  
  858.                                      - 13 -
  859.  
  860.  
  861.      Small C Interpreter                                      User's Manual
  862.  
  863.  
  864.                #
  865.                # Small C Interpreter standard shell
  866.                #
  867.                char _nr, _nc, _ro, _co, *_cp, *_el;
  868.                     .
  869.                     .
  870.                     .
  871.                <Library Function declarations>
  872.                     .
  873.                     .
  874.                     .
  875.                entry
  876.                
  877.                char ln[80];
  878.                char pr[20000];
  879.                
  880.                main()
  881.                {
  882.                     .
  883.                     .
  884.                     .
  885.                     _nr=25;
  886.                     _nc=80;
  887.                     _ro=1;
  888.                     _co=1;
  889.                     _cp="\033[%d;%dH";
  890.                     _el="\033I";
  891.                
  892.                     while ( gets(ln) ) {
  893.                          .
  894.                          .
  895.                          .
  896.                     <main program loop>
  897.                          .
  898.                          .
  899.                          .
  900.                     }
  901.                }
  902.  
  903.  
  904.                Only a skeleton of the file is shown here so that you 
  905.           can see the relative locations of the editor variables' 
  906.           declarations and assignments.  Note that the declarations 
  907.                                 ______                                
  908.           must appear somewhere before the "entry" keyword, and the 
  909.           control character strings must be assignmed to these 
  910.                               ______                                 
  911.           variables somewhere before the start of the main program 
  912.           loop.  
  913.  
  914.                In the sample configuration listings below, only the 
  915.           control character strings assignments are shown for 
  916.           brevity.  
  917.  
  918.  
  919.  
  920.                                      - 14 -
  921.  
  922.  
  923.      Small C Interpreter                                      User's Manual
  924.  
  925.  
  926.      3.5.1. IBM PC 
  927.  
  928.  
  929.                The IBM PC is probably the most common.  Note that the 
  930.           ANSI.SYS device driver must be installed for the SCI editor 
  931.           to work.  
  932.  
  933.  
  934.                _nr=25;            # the PC has 25 lines
  935.                _nc=80;            # of 80 columns each
  936.                _ro=_co=1;         # row/column numbering starts at 1
  937.                _cp="\033[%d;%dH"; # esc. seq. to position cursor
  938.                _el="\033I";       # esc. seq. to erase to end of line
  939.  
  940.  
  941.  
  942.      3.5.2. DEC Rainbow 100 
  943.  
  944.  
  945.                Digital Equipment Corp.s' Rainbow 100 recognizes a 
  946.           subset of the American National Standards Institute (ANSI) 
  947.           Control Sequences for Video Terminals (X3.64).  
  948.  
  949.  
  950.                _nr=24;
  951.                _nc=80;
  952.                _ro=1;
  953.                _co=1;
  954.                _cp="\033[%d;%dH"; # position cursor
  955.                _es="\033[J";   # erase to end of screen
  956.                _il="\033[M";   # insert a line
  957.                _ic="\033[4h%c\033[4l"; # insert a character
  958.                _dc="\033[P";   # delete a character
  959.                _bl="\033[?5h\033[?5l"; # bell flashes screen momentarily
  960.                _ke="\033[A";   # up-arrow key
  961.                _kx="\033[B";   # down-arrow key
  962.                _kd="\033[C";   # right-arrow key
  963.                _ks="\033[D";   # left-arrow key
  964.  
  965.  
  966.  
  967.      3.5.3. Heath H19 
  968.  
  969.  
  970.  
  971.                _nr=24;
  972.                _nc=80;
  973.                _ro=' ';
  974.                _co=' ';
  975.                _cp="\033Y%c%c"; # position cursor
  976.                _es="\033E";     # erase to end of screen
  977.  
  978.  
  979.  
  980.                                      - 15 -
  981.  
  982.  
  983.      Small C Interpreter                                      User's Manual
  984.  
  985.  
  986.      3.5.4. Zenith PC 
  987.  
  988.  
  989.  
  990.                _nr=24;
  991.                _nc=80;
  992.                _ro=' ';
  993.                _co=' ';
  994.                _cp="\033Y%c%c"; # position cursor
  995.                _es="\033E";     # erase to end of screen
  996.                _il="\033L";     # insert line
  997.                _dl="\033M";     # delete line
  998.  
  999.  
  1000.  
  1001.      3.5.5. Televideo 910 
  1002.  
  1003.  
  1004.  
  1005.                _nr=24;
  1006.                _nc=80;
  1007.                _ro=' ';
  1008.                _co=' ';
  1009.                _cp="\033=%c%c"; # position cursor
  1010.                _el="\033T";     # erase to end of line
  1011.  
  1012.  
  1013.  
  1014.      3.6. Editor Commands 
  1015.  
  1016.  
  1017.                Now that you have modified the file SHELL.SCI for your 
  1018.           particular terminal, you are ready to use the editor.  This 
  1019.           section describes all of the editor's commands in detail.  
  1020.  
  1021.                All of the editor commands are control-key combinations 
  1022.           (press and hold the CONTROL key while pressing a letter 
  1023.           key).  We will use an up arrow, or circumflex (^) followed 
  1024.           by a letter to indicate that the keystroke is a control-key 
  1025.           combination.  All other non-printing keys, such as the 
  1026.           <RETURN> and <BACKSPACE> keys, will be in UPPERCASE.  
  1027.  
  1028.  
  1029.      3.6.1. Exiting from the Editor 
  1030.  
  1031.  
  1032.                To exit the editor and return to the SCI shell, type a 
  1033.           ^Z.  
  1034.  
  1035.  
  1036.  
  1037.  
  1038.  
  1039.  
  1040.                                      - 16 -
  1041.  
  1042.  
  1043.      Small C Interpreter                                      User's Manual
  1044.  
  1045.  
  1046.      3.6.2. Cursor Movement 
  1047.  
  1048.  
  1049.  
  1050.                 E                                                      
  1051.                ^E - move cursor up to previous line.  Screen scrolls 
  1052.                     down if cursor is at the top of the screen.  
  1053.  
  1054.                 X                                                       
  1055.                ^X - move cursor down to next line.  Screen scrolls up 
  1056.                     if cursor is at the bottom of the screen.  
  1057.  
  1058.                 S                                                      
  1059.                ^S - move cursor left one character position.  Cursor 
  1060.                     stops at left margin.  
  1061.  
  1062.                 D                                                       
  1063.                ^D - move cursor right one character position.  Cursor 
  1064.                     stops at right margin.  
  1065.  
  1066.                 A                                                    
  1067.                ^A - move cursor to beginning of previous "word". A 
  1068.                     "word" is defined as a continuous sequence of 
  1069.                     alphanumeric characters (i.e. letters and numbers 
  1070.                     - no punctuation).  
  1071.  
  1072.                 F                                             
  1073.                ^F - move cursor to beginning of next word.  
  1074.  
  1075.                 R                                                      
  1076.                ^R - move cursor one page (the height of the display) 
  1077.                     up towards the beginning of the program.  
  1078.  
  1079.                 C                                                       
  1080.                ^C - move cursor one page down, towards the end of the 
  1081.                     program.  
  1082.  
  1083.                 RETURN  or  LINEFEED                               
  1084.                <RETURN> or <LINEFEED> - if the status line shows 
  1085.                     "Replace" mode instead of "Insert", these keys 
  1086.                     will move the cursor down to the beginning of the 
  1087.                     next line.  
  1088.  
  1089.  
  1090.  
  1091.      3.6.3. Inserting and Deleting 
  1092.  
  1093.  
  1094.  
  1095.                 V                                                      
  1096.                ^V - toggles Insert/Replace mode.  The status line at 
  1097.                     the bottom of the screen will indicate the current 
  1098.                     mode.  In Insert mode, any characters you type 
  1099.                     will be inserted before the current cursor 
  1100.                     position.  In Replace mode, old characters on a 
  1101.                     line are simply overwritten as you enter text.  
  1102.  
  1103.                 G                                                        
  1104.                ^G - delete the character under the cursor.  The cursor 
  1105.                     stays in the same position.  
  1106.  
  1107.                 H                                                        
  1108.                ^H - delete the character to the left of the cursor and 
  1109.                     move the cursor left one character.  
  1110.  
  1111.  
  1112.                                      - 17 -
  1113.  
  1114.  
  1115.      Small C Interpreter                                      User's Manual
  1116.  
  1117.  
  1118.                 Y                                                       
  1119.                ^Y - delete the current line.  The cursor stays at the 
  1120.                     same line.  Note that the <EOF> mark at the end of 
  1121.                     the program can not be deleted.  
  1122.  
  1123.                 L                                                     
  1124.                ^L - restore the original line if the cursor has not 
  1125.                     been moved off the line.  
  1126.  
  1127.                 RETURN  or  LINEFEED                               
  1128.                <RETURN> or <LINEFEED> - if the status line shows 
  1129.                     "Insert" mode, these keys will insert a new blank 
  1130.                     line as follows: If the cursor is at line one, 
  1131.                     column one (top, left-most column) when a <RETURN> 
  1132.                     or <LINEFEED> is pressed, a new blank line is 
  1133.                              _____                                      
  1134.                     inserted above the current line; everywhere else, 
  1135.                                              _____                      
  1136.                     the new line is inserted below the current line.  
  1137.                     The cursor will rest on the newly inserted line 
  1138.                     and directly below the first non-space character 
  1139.                     in the previous line.  
  1140.  
  1141.  
  1142.  
  1143.      3.6.4. Extended Movement 
  1144.  
  1145.  
  1146.                The extended cursor motion commands require two 
  1147.           control-key keystrokes.  The first is always a ^Q (mnemonic 
  1148.           for Quickly move somewhere), and the second can be one of 
  1149.           the following: 
  1150.  
  1151.  
  1152.                 F                                                      
  1153.                ^F - find a character sequence.  The cursor will move 
  1154.                     to the status line's prompt/error message field 
  1155.                     and you will be prompted for the character 
  1156.                     sequence to be searched for.  The search starts at 
  1157.                     the next character position to the right of the 
  1158.                     cursor on the current line.  When the character 
  1159.                     sequence is found, the cursor will rest on the 
  1160.                     first character of the sequence.  
  1161.  
  1162.                 A                                                   
  1163.                ^A - find and replace character sequence.  You are 
  1164.                     prompted for the character sequence to be searched 
  1165.                     for, as above.  Next you are prompted for the 
  1166.                     character sequence that will replace the search 
  1167.                     string.  Finally, you have the option of 
  1168.                     performing the search/replace "globally" that is 
  1169.                     for every occurance in the program.  
  1170.  
  1171.                 L                                                 
  1172.                ^L - find next occurence of previously specified 
  1173.                     character sequence.  You will not be prompted for 
  1174.                     the sequence to be searched for.  
  1175.  
  1176.                 G                                                       
  1177.                ^G - go to a specified line.  You are prompted for the 
  1178.                     line number to be displayed.  The cursor will rest 
  1179.  
  1180.  
  1181.                                      - 18 -
  1182.  
  1183.  
  1184.      Small C Interpreter                                      User's Manual
  1185.  
  1186.  
  1187.                     on the requested line usually in the center of the 
  1188.                     screen.  
  1189.  
  1190.                 S                                                
  1191.                ^S - move cursor to beginning of current line.  
  1192.  
  1193.                 D                                          
  1194.                ^D - move cursor to end of current line.  
  1195.  
  1196.                 E                                    
  1197.                ^E - move cursor to top of screen.  
  1198.  
  1199.                 X                                       
  1200.                ^X - move cursor to bottom of screen.  
  1201.  
  1202.                 R                                            
  1203.                ^R - move cursor to first line of program.  
  1204.  
  1205.                 C                                                      
  1206.                ^C - move cursor so that the last page of the program 
  1207.                     is displayed.  
  1208.  
  1209.                 B                                                      
  1210.                ^B - move cursor to the beginning of a marked block.  
  1211.  
  1212.                 K                                                
  1213.                ^K - move cursor to the end of a marked block.  
  1214.  
  1215.  
  1216.  
  1217.      3.6.5. Block and Miscellaneous Commands 
  1218.  
  1219.  
  1220.                These commands also require two control-key keystrokes 
  1221.           and include block marking, inserting/deleting and some "too 
  1222.           late to classify" commands.  
  1223.  
  1224.                Unlike the popular WORDSTAR word processor, SCI's 
  1225.           editor treats blocks as groups of lines instead of groups of 
  1226.           characters.  That is, a block starts at the beginning of a 
  1227.           line and includes all characters up to the end of a line.  
  1228.  
  1229.                The first of these two-keystroke block commands must be 
  1230.           a ^K (mnemonic for blocK (?)) and the second may be one of: 
  1231.  
  1232.  
  1233.                 B                                                      
  1234.                ^B - mark beginning of a block.  The status line will 
  1235.                     show the line number of the beginning of the 
  1236.                     block.  
  1237.  
  1238.                 K                                                      
  1239.                ^K - mark end of a block.  The status line is updated 
  1240.                     to show the end of the block.  
  1241.  
  1242.                 V                                                        
  1243.                ^V - make a copy of a marked block and insert it before 
  1244.                     the current line.  You may not copy a block to 
  1245.                     itself: for example if the block starts at line 3 
  1246.                     and ends at line 10 and the cursor is currently 
  1247.                     resting on line 5, you will be severely beeped at 
  1248.                     by the editor.  
  1249.  
  1250.  
  1251.  
  1252.                                      - 19 -
  1253.  
  1254.  
  1255.      Small C Interpreter                                      User's Manual
  1256.  
  1257.  
  1258.                 Y                               
  1259.                ^Y - delete the marked block.  
  1260.  
  1261.                 U                                                     
  1262.                ^U - "unmark" the block.  The block markers (if any) 
  1263.                     are removed from the status line display.  
  1264.  
  1265.                 R                                                   
  1266.                ^R - read a file from disk and insert its contents 
  1267.                     before the current line in the program.  You will 
  1268.                     be prompted for the file name.  
  1269.  
  1270.                 W                                                      
  1271.                ^W - write the marked block to a disk file.  You will 
  1272.                     be prompted for the file name.  
  1273.  
  1274.  
  1275.  
  1276.      3.6.6. Tabs 
  1277.  
  1278.  
  1279.                Tabs are set at every 3 columns.  A ^I (or the <TAB> 
  1280.           key on your keyboard if you have one) will either insert 
  1281.           spaces or replace with spaces, depending on the current 
  1282.           Insert/Replace mode parameter, up to the next tab stop.  
  1283.  
  1284.  
  1285.  
  1286.  
  1287.  
  1288.  
  1289.  
  1290.  
  1291.  
  1292.  
  1293.  
  1294.  
  1295.  
  1296.  
  1297.  
  1298.  
  1299.  
  1300.  
  1301.  
  1302.  
  1303.  
  1304.  
  1305.  
  1306.  
  1307.  
  1308.  
  1309.  
  1310.  
  1311.  
  1312.  
  1313.  
  1314.  
  1315.  
  1316.                                      - 20 -
  1317.  
  1318.  
  1319.      Small C Interpreter                                      User's Manual
  1320.  
  1321.  
  1322.      4. Language Summary 
  1323.  
  1324.  
  1325.                Although SCI implements only a subset of the C 
  1326.           language, it is powerful enough to teach you the major 
  1327.           principles of C.  This section is meant as a reference for 
  1328.           the experienced C programmer that wants to get started with 
  1329.           SCI immediately.  
  1330.  
  1331.  
  1332.      4.1. Line Terminators 
  1333.  
  1334.  
  1335.                In standard C, a statement is typically terminated with 
  1336.           a semicolon (;). In SCI, all statements are terminated by 
  1337.           either the end of the line or by a semicolon, although the 
  1338.           semicolon is optional.  This means that an expression MUST 
  1339.           be completely contained on one line.  
  1340.  
  1341.  
  1342.      4.2. Comments 
  1343.  
  1344.  
  1345.                Comments start with a number symbol (#) and end at the 
  1346.           end of the current program line.  The standard C comment 
  1347.           delimiters, /* and */ are not recognized and will cause a 
  1348.           "syntax error" message.  
  1349.  
  1350.  
  1351.      4.3. Identifiers 
  1352.  
  1353.  
  1354.                Identifiers may be a maximum of 8 characters long, the 
  1355.           first character must be an uppercase or lowercase letter 
  1356.           ("a-z", "A-Z") or an underscore ("_"). The remaining 7 
  1357.           characters may include digits ("0-9").  
  1358.  
  1359.                The following are all examples of valid identifiers: 
  1360.  
  1361.  
  1362.                this_is_an_identifier
  1363.                _0123
  1364.                XYZ
  1365.  
  1366.  
  1367.  
  1368.      4.4. Keywords 
  1369.  
  1370.  
  1371.                The following words are reserved by SCI and may not be 
  1372.           used as variable names: 
  1373.  
  1374.  
  1375.  
  1376.                                      - 21 -
  1377.  
  1378.  
  1379.      Small C Interpreter                                      User's Manual
  1380.  
  1381.  
  1382.                break           entry           return
  1383.                char            for             switch
  1384.                case            if              sys
  1385.                else            int             while
  1386.  
  1387.  
  1388.                Most of these keywords are the standard language 
  1389.           elements and are described in any C text book.  
  1390.  
  1391.                The "entry" keyword is used to tell the interpreter 
  1392.           which function in the startup program (normally in the file 
  1393.           SHELL.SCI) is to be executed first after the program has 
  1394.           been loaded.  There may be only one "entry" within a 
  1395.           program.  Any functions or variables that were declared 
  1396.           before the "entry" keyword are considered "system globals" 
  1397.           and are globally known to all functions.  Among the system 
  1398.           globals in the standard shell file are the Library Functions 
  1399.           and the editor's control variables.  See the Programmer's 
  1400.           Manual for more information on system globals.  
  1401.  
  1402.                Functions and variables declared after the "entry" 
  1403.           keyword are hidden from user-written functions.  These 
  1404.           include the standard shell's control program (main) and its 
  1405.           associated variables.  
  1406.  
  1407.                The keyword "sys" is a user program interface to some 
  1408.           useful interpreter functions, such as the program editor.  
  1409.           These are described in the Library Functions section.  
  1410.  
  1411.  
  1412.      4.5. Constants 
  1413.  
  1414.           
  1415.  
  1416.  
  1417.      4.5.1. Numeric Constants 
  1418.  
  1419.  
  1420.                SCI supports decimal integer constants in the range 
  1421.           -32768 to 32767.  SCI also supports the standard C notation 
  1422.           for integer hexadecimal and octal notation.  
  1423.  
  1424.  
  1425.      4.5.2. Character Constants 
  1426.  
  1427.  
  1428.                A character constant must be surrounded by apostrophes 
  1429.           (') and may be one of the following: 
  1430.  
  1431.  
  1432.                1) a single ASCII alphanumeric or punctuation (i.e. 
  1433.                     printable) character 
  1434.  
  1435.  
  1436.                                      - 22 -
  1437.  
  1438.  
  1439.      Small C Interpreter                                      User's Manual
  1440.  
  1441.  
  1442.                2) a backslash (\) character followed by 3 octal digits 
  1443.                     which may be used to represent any 1 byte value 
  1444.  
  1445.                3) a backslash followed by one of the characters n, r, 
  1446.                     b or t which represent the <LINEFEED> (a.k.a. 
  1447.                     "newline"), <RETURN> (carriage return), 
  1448.                     <BACKSPACE> and <TAB> characters respectively 
  1449.  
  1450.  
  1451.                The following are examples of valid character 
  1452.           constants: 
  1453.  
  1454.  
  1455.                'A'     the ASCII character "A"
  1456.                '\177'  octal character
  1457.                '\n'    newline
  1458.                '\r'    carriage return
  1459.                '\b'    backspace
  1460.                '\t'    horizontal tab
  1461.                '\\'    the backslash character
  1462.                '\''    the apostrophe character
  1463.  
  1464.  
  1465.  
  1466.      4.5.3. String Constants 
  1467.  
  1468.  
  1469.                Strings may include any of the character constants 
  1470.           mentioned above, as for example: 
  1471.  
  1472.  
  1473.                "this is a string\007\n"
  1474.  
  1475.  
  1476.                Strings always include a null (zero) byte, marking the 
  1477.           end of the string.  A zero-length string may be written as 
  1478.           two consecutive quotes, thus: "" 
  1479.  
  1480.  
  1481.      4.6. Data Types 
  1482.  
  1483.  
  1484.                Only the "char" and "int" data types are supported.  
  1485.           Characters (char's) are 1 byte and integers (int's) 2 bytes 
  1486.           in length.  Both are treated as signed quantities.  Chars 
  1487.           may range in value from -128 to +127, ints range from -32768 
  1488.           to 32767.  
  1489.  
  1490.                SCI also supports pointers and arrays of both char and 
  1491.           int.  Pointers require 2 bytes of storage.  
  1492.  
  1493.  
  1494.  
  1495.  
  1496.                                      - 23 -
  1497.  
  1498.  
  1499.      Small C Interpreter                                      User's Manual
  1500.  
  1501.  
  1502.      4.7. Operators 
  1503.  
  1504.           
  1505.  
  1506.  
  1507.      4.7.1. Unary Operators 
  1508.  
  1509.  
  1510.                The following unary operators are supported, all are 
  1511.           evaluated from right to left: 
  1512.  
  1513.  
  1514.                +--------------------------------+
  1515.                | *     pointer                  |
  1516.                | &     address                  |
  1517.                | -     negation                 |
  1518.                | !     logical NOT              |
  1519.                | ~     one's complement         |
  1520.                | ++    pre- and post-increment  |
  1521.                | --    pre- and post-decrement  |
  1522.                +--------------------------------+
  1523.  
  1524.  
  1525.  
  1526.      4.7.2. Binary Operators 
  1527.  
  1528.  
  1529.                The following binary operators are supported, all are 
  1530.           evaluated from left to right.  The operators are listed from 
  1531.           highest to lowest precedence, by groups (enclosed in 
  1532.           boxes).  Each group of operators has the same precedence: 
  1533.  
  1534.  
  1535.                +--------------------------------+
  1536.                | *     multiplication           |
  1537.                | /     division                 |
  1538.                | %     modulo (remainder)       |
  1539.                +--------------------------------+
  1540.                +--------------------------------+
  1541.                | +     addition                 |
  1542.                | -     subtraction              |
  1543.                +--------------------------------+
  1544.                +--------------------------------+
  1545.                | <<    shift left               |
  1546.                | >>    shift right              |
  1547.                +--------------------------------+
  1548.  
  1549.  
  1550.  
  1551.  
  1552.  
  1553.  
  1554.  
  1555.  
  1556.                                      - 24 -
  1557.  
  1558.  
  1559.      Small C Interpreter                                      User's Manual
  1560.  
  1561.  
  1562.                +--------------------------------+
  1563.                | <     less than                |
  1564.                | >     greater than             |
  1565.                | <=    less than or equal to    |
  1566.                | >=    greater than or equal to |
  1567.                +--------------------------------+
  1568.                +--------------------------------+
  1569.                | ==    equal                    |
  1570.                | !=    not equal                |
  1571.                +--------------------------------+
  1572.                +--------------------------------+
  1573.                | &     bitwise AND              |
  1574.                +--------------------------------+
  1575.                +--------------------------------+
  1576.                | ^     bitwise exclusive OR     |
  1577.                +--------------------------------+
  1578.                +--------------------------------+
  1579.                | |     bitwise OR               |
  1580.                +--------------------------------+
  1581.                +--------------------------------+
  1582.                | &&    logical AND              |
  1583.                +--------------------------------+
  1584.                +--------------------------------+
  1585.                | ||    logical OR               |
  1586.                +--------------------------------+
  1587.  
  1588.  
  1589.  
  1590.      4.7.3. Assignment Operator 
  1591.  
  1592.  
  1593.                The assignment operator, "=", is evaluated from from 
  1594.           right to left and has lowest precedence of all operators.  
  1595.  
  1596.  
  1597.      4.7.4. Comma Operator 
  1598.  
  1599.  
  1600.                The Comma Operator (,) as used by SCI is not an 
  1601.           operator in the strict sense, but rather a function argument 
  1602.           and variable seperator.  Trying to use a comma anywhere 
  1603.           other than in function calls, or data declarations will 
  1604.           cause a "syntax error".  
  1605.  
  1606.  
  1607.      4.8. Program Control Flow Constructs 
  1608.  
  1609.  
  1610.                SCI supports the following programming constructs: 
  1611.  
  1612.  
  1613.                if ( <expression> ) <statement>
  1614.  
  1615.  
  1616.                                      - 25 -
  1617.  
  1618.  
  1619.      Small C Interpreter                                      User's Manual
  1620.  
  1621.  
  1622.                
  1623.                
  1624.                if ( <expression> ) <statement> else <statement>
  1625.                
  1626.                
  1627.                while ( <expression> ) <statement>
  1628.                
  1629.                
  1630.                for ( <expression> ; <expression> ; <expression> ) <statement>
  1631.                
  1632.                
  1633.                switch ( <expression> )
  1634.                {
  1635.                case <constant expression> : <statement>
  1636.                case <constant expression> : <statement>
  1637.                case <constant expression> : <statement>
  1638.                     .
  1639.                     .
  1640.                     .
  1641.                default : <statement>
  1642.                }
  1643.  
  1644.  
  1645.                All of these constructs require that the keyword ("if", 
  1646.           "while", etc.) and its associated ( <expression> ) all 
  1647.           appear on the same line of text.  The <statement> portion 
  1648.           may appear on the same or on a seperate line of text.  
  1649.  
  1650.                If a "default" statement is encountered inside a 
  1651.           "switch" before any <constant expression>'s (reading from 
  1652.           top to bottom) are found that match the switch <expression>, 
  1653.           then execution continues with the <statement> following the 
  1654.           "default" keyword.  This is in contrast to standard C that 
  1655.                                                       ___         
  1656.           only executes the "default" statement after all "case 
  1657.           <constant expressions>" have been tested.  
  1658.  
  1659.  
  1660.  
  1661.  
  1662.  
  1663.  
  1664.  
  1665.  
  1666.  
  1667.  
  1668.  
  1669.  
  1670.  
  1671.  
  1672.  
  1673.  
  1674.  
  1675.  
  1676.  
  1677.                                      - 26 -
  1678.  
  1679.  
  1680.      Small C Interpreter                                      User's Manual
  1681.  
  1682.  
  1683.      5. The Library Functions 
  1684.  
  1685.  
  1686.                The "sys" keyword has been reserved by SCI as a means 
  1687.           of communicating between a user's program and the 
  1688.           interpreter.  It is treated exactly as a (pre-defined) 
  1689.           function that may be referenced by a user program.  
  1690.  
  1691.                A "sys" call may have several arguments, the number and 
  1692.           type of which depends upon the integer value of the last 
  1693.           (right-most) argument.  This right-most argument is called 
  1694.           the "sys number" and defines the actual function performed 
  1695.           by a "sys" call.  To make life easier and to provide a more 
  1696.           or less "standard" programming environment, higher- level 
  1697.           functions have been wrapped around these "sys" calls - these 
  1698.           are known as the "Library Functions" and may be found in the 
  1699.           standard command shell included in the distribution disk.  
  1700.           The "sys numbers" and their corresponding mnemonic name are 
  1701.           listed below.  
  1702.  
  1703.  
  1704.                0       version
  1705.                1       fputc
  1706.                2       fgetc
  1707.                3       fputs
  1708.                4       fgets
  1709.                5       sprintf
  1710.                6       sscanf
  1711.                7       fopen
  1712.                8       fread
  1713.                9       fwrite
  1714.                10      fclose
  1715.                11      fseek
  1716.                12      ftell
  1717.                13      bdos
  1718.                14      system
  1719.                15      exit
  1720.                16      stmt
  1721.                17      totok
  1722.                18      untok
  1723.                19      edit
  1724.                20      strcmp and strncmp
  1725.                21      strcpy and strncpy
  1726.                22      strlen
  1727.                23      malloc
  1728.                24      free
  1729.                25      load
  1730.                26      save
  1731.                27      list
  1732.                28      trace
  1733.                29      dirscan
  1734.  
  1735.  
  1736.  
  1737.                                      - 27 -
  1738.  
  1739.  
  1740.      Small C Interpreter                                      User's Manual
  1741.  
  1742.  
  1743.                The Library Functions are described below in more 
  1744.           detail.  Some of the "sys" functions do not have a 
  1745.           corresponding Library Function interface in SHELL.SCI, but 
  1746.           are described here anyway for completeness.  
  1747.  
  1748.  
  1749.      5.1. atoi 
  1750.  
  1751.           
  1752.           atoi( string ) 
  1753.           char *string; 
  1754.  
  1755.                Converts the string "str" containing the ASCII 
  1756.           representation of a decimal number to an integer.  The 
  1757.           string consits of optional leading spaces or tabs, an 
  1758.           optional plus or minus sign (+ or -) followed by one or more 
  1759.           decimal digits.  Returns the integer value of the ASCII 
  1760.           number string.  
  1761.  
  1762.                This function does not have a "sys" call number 
  1763.           equivalent but rather it uses the "sscanf" Library 
  1764.           Function.  
  1765.  
  1766.  
  1767.      5.2. bdos 
  1768.  
  1769.           
  1770.           bdos( cx, dx ) 
  1771.           int cx, dx; 
  1772.  
  1773.                Performs a call on the operating system's BDOS. The 
  1774.           arguments "cx" and "dx" will be copied to the machine's CX 
  1775.           and DX registers respectively before the BDOS call.  The 
  1776.           function returns the value of the CPU's AX register after 
  1777.           the call.  See your MS-DOS programmer's manual for more 
  1778.           details on BDOS calls.  
  1779.  
  1780.  
  1781.      5.3. dirscan 
  1782.  
  1783.           
  1784.           dirscan( afn, file ) 
  1785.           char *afn, file[20]; 
  1786.  
  1787.                This function will scan the disk directory for file 
  1788.           names that match the "ambiguous file name" given by the 
  1789.           string "afn". Ambiguous file names may contain "*" and "?"  
  1790.           wildcard characters as explained in your MS-DOS manual.  The 
  1791.           first file name found in the directory that matches will be 
  1792.           copied into the buffer at "file". To continue the directory 
  1793.           scan and search for the next matching file name, set "afn" 
  1794.           equal to zero.  Dirscan will return a 1 if a matching file 
  1795.  
  1796.  
  1797.                                      - 28 -
  1798.  
  1799.  
  1800.      Small C Interpreter                                      User's Manual
  1801.  
  1802.  
  1803.           name was found, zero if not.  
  1804.  
  1805.  
  1806.      5.4. edit 
  1807.  
  1808.           
  1809.           edit( line_num, program ) 
  1810.           int line_num 
  1811.           char *program 
  1812.  
  1813.                Invokes the built-in program editor, starting at the 
  1814.           line given by "line_num" on the tokenized program buffer 
  1815.           "program". Returns the new size of the program buffer after 
  1816.                                 ____ ________ __ ___ ________ __   
  1817.           the editing session.  This function is not included in 
  1818.           _____ ___   
  1819.           SHELL.SCI 
  1820.  
  1821.  
  1822.      5.5. exit 
  1823.  
  1824.           
  1825.           exit( value ) 
  1826.           int value 
  1827.  
  1828.                Causes the currently executing program to return 
  1829.           control to the operating system.  The number "value" is 
  1830.           returned to the operating system shell (usually COMMAND.COM 
  1831.           in MS-DOS).  
  1832.  
  1833.  
  1834.      5.6. fclose 
  1835.  
  1836.           
  1837.           fclose( channel ) 
  1838.           int channel; 
  1839.  
  1840.                Closes a disk file previously opened by the Library 
  1841.           Function "fopen". Returns zero if successful, -1 on error.  
  1842.  
  1843.  
  1844.      5.7. fgetc 
  1845.  
  1846.           
  1847.           fgetc( channel ) 
  1848.  
  1849.                Reads a single character from the given channel.  
  1850.           Returns the character read, or a -1 on error or end of 
  1851.           file.  
  1852.  
  1853.  
  1854.  
  1855.  
  1856.  
  1857.  
  1858.  
  1859.                                      - 29 -
  1860.  
  1861.  
  1862.      Small C Interpreter                                      User's Manual
  1863.  
  1864.  
  1865.      5.8. fgets 
  1866.  
  1867.           
  1868.           fgets( buffer, length, channel ) 
  1869.           char *buffer; 
  1870.           int length; 
  1871.           int channel; 
  1872.  
  1873.                Reads characters from the file associated with 
  1874.           "channel".  Characters are read from the file until either a 
  1875.           newline is encountered, length minus 1 characters have been 
  1876.           read, or an end of file is found.  Returns the address of 
  1877.           "buffer", or a zero on end of file.  
  1878.  
  1879.  
  1880.      5.9. fopen 
  1881.  
  1882.           
  1883.           fopen( file_name, mode ) 
  1884.           char *file_name, *mode; 
  1885.  
  1886.                Opens a disk file whose name is given by the string 
  1887.           "file_name".  The string "mode" determines how the file will 
  1888.           be opened: 
  1889.  
  1890.  
  1891.                 r                                                   
  1892.                "r" - open for ASCII read.  The file MUST exist or 
  1893.                     fopen returns an error code.  
  1894.  
  1895.                 rw                                                
  1896.                "rw" - open for ASCII read/write.  The file MUST 
  1897.                     exist.  
  1898.  
  1899.                 w                                                       
  1900.                "w" - open for ASCII write.  If the file exists, it is 
  1901.                     first deleted.  
  1902.  
  1903.                 wr                                                      
  1904.                "wr" - open for ASCII read/write.  If the file already 
  1905.                     exists, it is first deleted.  
  1906.  
  1907.                 a                                                     
  1908.                "a" - open for ASCII write append.  If the file does 
  1909.                     not exist, it is created.  If it does exist, the 
  1910.                     file position pointer is positioned to the end of 
  1911.                     the file.  
  1912.  
  1913.                 ar                                                     
  1914.                "ar" - open for ASCII read/write append.  If the file 
  1915.                     does not exist it is created.  If it DOES exist, 
  1916.                     it is opened and the file pointer positioned to 
  1917.                     the end of the file.  The file may then be read or 
  1918.                     written.  
  1919.  
  1920.  
  1921.                By appending a "b" to any of the modes above, the file 
  1922.           is opened in BINARY mode instead of ASCII.  
  1923.  
  1924.  
  1925.                                      - 30 -
  1926.  
  1927.  
  1928.      Small C Interpreter                                      User's Manual
  1929.  
  1930.  
  1931.                When a file is opened in ASCII mode, all <LINEFEED>s 
  1932.           ("\n") are converted to <RETURN> <LINEFEED> character pairs 
  1933.           when writing to the file.  Similarly, <RETURN> <LINEFEED> 
  1934.           pairs are converted to a single <LINEFEED> character on 
  1935.           input from the file.  
  1936.  
  1937.                In BINARY read/write mode, no such conversions are 
  1938.           performed.  
  1939.  
  1940.                Returns an integer value known as a "channel". The 
  1941.           special channels 0, 1 and 2 refer to the standard input, 
  1942.           standard output and standard error files, and are initially 
  1943.           set for I/O on the console.  The channel number must be used 
  1944.           in all Library calls that perform file I/O functions.  A 
  1945.           Minus one is returned if the file could not be opened.  
  1946.  
  1947.  
  1948.      5.10. fputc 
  1949.  
  1950.           
  1951.           fputc( c, channel ) 
  1952.           char c; 
  1953.           int channel; 
  1954.  
  1955.                Writes the character "c" to the specified file 
  1956.           channel.  Returns the character written, or a -1 on error.  
  1957.  
  1958.  
  1959.      5.11. fputs 
  1960.  
  1961.           
  1962.           fputs( string, channel ) 
  1963.           char *string; 
  1964.           int channel; 
  1965.  
  1966.                Writes the string to the specified file channel.  
  1967.           Returns zero, or a -1 on error.  
  1968.  
  1969.  
  1970.      5.12. fread 
  1971.  
  1972.           
  1973.           fread( buffer, length, channel ) 
  1974.           char *buffer; 
  1975.           int length; 
  1976.           int channel; 
  1977.  
  1978.                Reads a maximum of "length" bytes into memory at the 
  1979.           address pointed to by "buffer" from the open file, 
  1980.           "channel". If the file was opened in ASCII read or 
  1981.           read/write mode, "fread" only reads up to and including a 
  1982.           newline character.  If the file was opened in binary read 
  1983.  
  1984.  
  1985.                                      - 31 -
  1986.  
  1987.  
  1988.      Small C Interpreter                                      User's Manual
  1989.  
  1990.  
  1991.           mode, "length" number of characters are read if they are 
  1992.           available.  Note that "channel" must be the value returned 
  1993.           from a previous "fopen" Library Function call, and the file 
  1994.           must still be open.  Returns the number of characters that 
  1995.           were actually read, or 0 on EOF.  
  1996.  
  1997.  
  1998.      5.13. free 
  1999.  
  2000.           
  2001.           free( memory ) 
  2002.           char *memory 
  2003.  
  2004.                Returns to the memory pool the block of memory pointed 
  2005.           to by "memory" that was previously gotten from a "malloc" 
  2006.           Library Function call.  
  2007.  
  2008.  
  2009.      5.14. fseek and ftell 
  2010.  
  2011.           fseek( channel, offset, whence ) 
  2012.           int channel, offset, whence; 
  2013.           
  2014.           ftell( channel ) 
  2015.  
  2016.                These functions manipulate a file's position pointer.  
  2017.           The file position pointer determines where in the file the 
  2018.           next byte of data will be read from or written to.  The 
  2019.           argument "channel" is the file channel number; "offset" is a 
  2020.           byte position offset; "whence" determines how the "offset" 
  2021.           will be applied to the current file position pointer.  If 
  2022.           "whence" is zero, "fseek" will move the file position 
  2023.                                              _________                 
  2024.           pointer to "offset" bytes from the beginning of the file.  
  2025.           If "whence" is one, "fseek" will move the file position 
  2026.                                              _______ ________           
  2027.           pointer to "offset" bytes from its current location, either 
  2028.           forward ("offset" is positive) or backward ("offset" is 
  2029.           negative) in the file If "whence" is two, "fseek" will move 
  2030.                                                                ___      
  2031.           the file position pointer to "offset" bytes from the end of 
  2032.           the file.  In this case, "offset" must be negative to move 
  2033.           the file position pointer towards the beginning of the 
  2034.           file.  
  2035.  
  2036.                Ftell simply returns the current file position.  
  2037.  
  2038.  
  2039.  
  2040.                                         NOTE   
  2041.                                         NOTE:
  2042.  
  2043.                Because SCI supports only integer variables, these 
  2044.                functions  may  only  be  used  on  files that are
  2045.                smaller than 32767 characters.  Standard C  allows
  2046.                you to manipulate much larger files.  
  2047.  
  2048.  
  2049.                                      - 32 -
  2050.  
  2051.  
  2052.      Small C Interpreter                                      User's Manual
  2053.  
  2054.  
  2055.      5.15. fwrite 
  2056.  
  2057.           
  2058.           fwrite( buffer, length, channel ) 
  2059.           char *buffer; 
  2060.           int length; 
  2061.           int channel; 
  2062.  
  2063.                Writes "length" number of characters from memory at the 
  2064.           address pointed to by "buffer" to the file associated with 
  2065.           "channel".  Note that "channel" must be the value returned 
  2066.           from a previous "fopen" Library Function call, and the file 
  2067.           must still be open.  Returns the number of characters 
  2068.           actually written if successful, or a -1 on error.  
  2069.  
  2070.  
  2071.      5.16. load 
  2072.  
  2073.           
  2074.           load( file, program ) 
  2075.           char *file, *program 
  2076.  
  2077.                Loads a program from the file whose name is pointed at 
  2078.           by "file", tokenizes the statements therein and places the 
  2079.           tokenized program at "program". Returns the size of the 
  2080.           resulting tokenized program.  If the file could not be 
  2081.                                                               ____   
  2082.           found, an error message is printed on the console.  This 
  2083.           ________ __ ___ ________ __ _____ ___   
  2084.           function is not included in SHELL.SCI 
  2085.  
  2086.  
  2087.      5.17. malloc 
  2088.  
  2089.           
  2090.           malloc( size ) 
  2091.           int size 
  2092.  
  2093.                Main memory allocator.  This function is responsible 
  2094.           for handing out (to programs) chunks of free memory to be 
  2095.           used by the program as it sees fit.  
  2096.  
  2097.  
  2098.                                     WARNING   
  2099.                                     WARNING:
  2100.  
  2101.                wreckless programs that write data beyond the size 
  2102.                of  the  allocated  chunk of memory will cause the
  2103.                allocator to loose its mind and dole out  "rotten"
  2104.                chunks of  memory.   This will almost surely cause
  2105.                SCI to crash and burn.  Returns  a  pointer  to  a
  2106.                block of  memory  "size"  bytes  long.  Be sure to
  2107.                de-allocate the block using the  Library  Function
  2108.                "free"  when  you're  done  with it, or it will be
  2109.                lost forever...    Also,  do  not  use  malloc  to
  2110.  
  2111.  
  2112.                                      - 33 -
  2113.  
  2114.  
  2115.      Small C Interpreter                                      User's Manual
  2116.  
  2117.  
  2118.                allocate  memory  for  SCI program buffers, or you
  2119.                will surely crash the system.  
  2120.  
  2121.  
  2122.  
  2123.      5.18. printf 
  2124.  
  2125.           
  2126.           printf( format, arg1, arg2, ... arg8 ) 
  2127.           char *format; 
  2128.           int arg1, arg2, ... arg8; 
  2129.  
  2130.                Prints a formatted string to the standard output file.  
  2131.           The characters in the string "format" are copied to the 
  2132.           standard output file.  If a percent character ("%") is 
  2133.           encountered in the format string, it is assumed to be a 
  2134.           conversion specification.  Each conversion specification 
  2135.           converts exactly one argument in the list "arg1", "arg2", 
  2136.           ... "arg8". Once an argument has been converted and output, 
  2137.           it is skipped over the next time a conversion specification 
  2138.           is encountered.  Therefore, you need just as many arguments 
  2139.           as you have conversion specifications (%-somethings).  
  2140.  
  2141.                The character(s) that follow a conversion specification 
  2142.           may be one or more of the following: 
  2143.  
  2144.  
  2145.                minus sign                                              
  2146.                minus sign (-) - Indicates that output should be left 
  2147.                     justified instead of right justified.  
  2148.  
  2149.                zero fill character  0                                  
  2150.                zero fill character (0) - The field will be padded on 
  2151.                     the left with zeros.  
  2152.  
  2153.                field width  number other than 0                          
  2154.                field width (number other than 0) - This is the minimum 
  2155.                     # of characters output.  The field will be padded 
  2156.                     with zeros or blanks depending on the fill 
  2157.                     character (above).  
  2158.  
  2159.                precision    followed by a number                  
  2160.                precision (. followed by a number) - For numeric 
  2161.                     fields, this is the # of decimal places to the 
  2162.                     right of the decimal point.  For string fields, at 
  2163.                     most that many characters of the string will be 
  2164.                     output.  
  2165.  
  2166.                conversion code  the letter d  u  x  o  b  s or c        
  2167.                conversion code (the letter d, u, x, o, b, s or c) - A 
  2168.                     conversion code indicates the type of conversion 
  2169.                     that is to be done on the argument as follows: 
  2170.  
  2171.  
  2172.                          d - convert to a decimal (base 10) number
  2173.                          u - unsigned decimal number
  2174.                          x - hexadecimal (base 16) number
  2175.  
  2176.  
  2177.                                      - 34 -
  2178.  
  2179.  
  2180.      Small C Interpreter                                      User's Manual
  2181.  
  2182.  
  2183.                          o - octal (base 8) number
  2184.                          b - binary (base 2) number
  2185.                          s - string constant
  2186.                          c - single ASCII character
  2187.  
  2188.  
  2189.  
  2190.  
  2191.      5.19. save 
  2192.  
  2193.           
  2194.           save( file, program ) 
  2195.           char *file, *program 
  2196.  
  2197.                Saves a program in its tokenized form at "program" to 
  2198.           the file whose name is in the string "file". Returns the 
  2199.           number of bytes written to the file.  If the file could not 
  2200.           be created, an error message is printed on the console.  
  2201.           ____ ________ __ ___ ________ __ _____ ___   
  2202.           This function is not included in SHELL.SCI 
  2203.  
  2204.  
  2205.      5.20. scanf 
  2206.  
  2207.           
  2208.           scanf( format, arg1, arg2, ... arg8 ) 
  2209.           char *format 
  2210.           int arg1, arg2, ... arg8 
  2211.  
  2212.                Reads characters from the standard input file and 
  2213.           converts them using the conversion string "format" (same as 
  2214.           for Library Function "printf"). The arguments "arg1", 
  2215.                                      ________                           
  2216.           "arg2", ... "arg8" must be pointers to the appropriate data 
  2217.           types.  
  2218.  
  2219.  
  2220.      5.21. sprintf 
  2221.  
  2222.           
  2223.           sprintf( buffer, format, arg1, arg2, ... arg8 ) 
  2224.           char *buffer, *format 
  2225.           int arg1, arg2, ... arg8 
  2226.  
  2227.                Performs formated conversion of the arguments, exactly 
  2228.           like the Library Function "printf()", but writes its output 
  2229.           to the "buffer" instead of the standard output file.  
  2230.  
  2231.  
  2232.      5.22. sscanf 
  2233.  
  2234.           
  2235.           sscanf( buffer, format, arg1, arg2, ... arg8 ) 
  2236.           char *buffer, *format 
  2237.  
  2238.  
  2239.                                      - 35 -
  2240.  
  2241.  
  2242.      Small C Interpreter                                      User's Manual
  2243.  
  2244.  
  2245.           int arg1, arg2, ... arg8 
  2246.  
  2247.                Performs formated input conversion of the arguments, 
  2248.           exactly like the Library Function "scanf()" but reads its 
  2249.           input from the "buffer" instead of the standard input file.  
  2250.  
  2251.  
  2252.      5.23. stmt 
  2253.  
  2254.           
  2255.           stmt( line, program ) 
  2256.           char *line, *program 
  2257.  
  2258.                Hands a C statement off to the interpreter for 
  2259.           execution.  The statement is in its untokenized form at 
  2260.           "line". The program, also in tokenized form, at "program" is 
  2261.           used by the interpreter to satisfy any global variable or 
  2262.                                                       ____ ________ __   
  2263.           function references made by the statement.  This function is 
  2264.           ___ ________ __ _____ ___   
  2265.           not included in SHELL.SCI 
  2266.  
  2267.  
  2268.      5.24. strcmp, strncmp 
  2269.  
  2270.           
  2271.           strcmp( string_1, string_2 ) 
  2272.           char *string_1, *string_2 
  2273.           
  2274.                or 
  2275.           
  2276.           strncmp( string_1, string_2, limit ) 
  2277.           char *string_1, *string_2 
  2278.           int limit 
  2279.  
  2280.                Compares (character-by-character) the two strings.  The 
  2281.           comparison stops when a zero is encountered in either of the 
  2282.           two strings.  "strncmp" does the same thing, but at most 
  2283.           "limit" number of bytes are compared.  Returns a 0 if the 
  2284.           two strings are identical, non- zero if they differ.  
  2285.  
  2286.  
  2287.      5.25. strcpy, strncpy 
  2288.  
  2289.           
  2290.           strcpy( string_1, string_2 ) 
  2291.           char *string_1, *string_2 
  2292.           
  2293.                or 
  2294.           
  2295.           strncpy( string_1, string_2, limit ) 
  2296.           char *string_1, *string_2 
  2297.           int limit 
  2298.  
  2299.  
  2300.  
  2301.                                      - 36 -
  2302.  
  2303.  
  2304.      Small C Interpreter                                      User's Manual
  2305.  
  2306.  
  2307.                Copies (character-by-character) "string_2" into 
  2308.           "string_1".  The functions stops after the first null 
  2309.           character is encountered in "string_2".  "strncpy" does the 
  2310.           same thing, but at most "limit" number of bytes are copied.  
  2311.           Returns nothing interesting.  
  2312.  
  2313.  
  2314.      5.26. strlen 
  2315.  
  2316.           
  2317.           strlen( string ) 
  2318.           char *string; 
  2319.  
  2320.                Returns the number of characters in the given string, 
  2321.           excluding the string's trailing zero byte.  
  2322.  
  2323.  
  2324.      5.27. system 
  2325.  
  2326.           
  2327.           system( command_string ) 
  2328.           char *command_string; 
  2329.  
  2330.                Executes the MS-DOS command interpreter (usually the 
  2331.           program in COMMAND.COM) and passes it the MS-DOS command 
  2332.           found in "command_string".  SCI remains suspended in memory 
  2333.           in its current state and will continue execution when the 
  2334.           command has completed.  The return value from "system" is 
  2335.           the completion status of the MS-DOS program, which may be 
  2336.           used to test for success or failure.  
  2337.  
  2338.  
  2339.      5.28. totok 
  2340.  
  2341.           
  2342.           totok( sourcebuf, tokenbuf ) 
  2343.           char *sourcebuf, *tokenbuf 
  2344.  
  2345.                Converts the C statement at "sourcebuf" to its 
  2346.           tokenized equivalent and places the result at "tokenbuf". 
  2347.                                              ____ ________ __ ___   
  2348.           Returns the length of "tokenbuf".  This function is not 
  2349.           ________ __ _____ ___   
  2350.           included in SHELL.SCI 
  2351.  
  2352.  
  2353.      5.29. trace 
  2354.  
  2355.           
  2356.           trace( on_off ) 
  2357.           int on_off; 
  2358.  
  2359.                Allows a program to enable or disable the SCI debuger.  
  2360.           If "on_off" is zero, the debuger is disabled, anything else 
  2361.  
  2362.  
  2363.                                      - 37 -
  2364.  
  2365.  
  2366.      Small C Interpreter                                      User's Manual
  2367.  
  2368.  
  2369.           enables it.  
  2370.  
  2371.  
  2372.      5.30. untok 
  2373.  
  2374.           
  2375.           untok( tokenbuf, sourcebuf ) 
  2376.           char *tokenbuf, *sourcebuf 
  2377.  
  2378.                Converts the tokenized statement at "tokenbuf" to its 
  2379.           printable form at "sourcebuf". Returns the length of 
  2380.           "tokenbuf" (not "sourcebuf"!). This function is the opposite 
  2381.                                     ____ ________ __ ___ ________ __   
  2382.           of the "totok" function.  This function is not included in 
  2383.           _____ ___   
  2384.           SHELL.SCI 
  2385.  
  2386.  
  2387.      5.31. version 
  2388.  
  2389.           
  2390.           version() 
  2391.  
  2392.                Returns a character string that contains SCI's program 
  2393.           identification and copyright notice, and the program's 
  2394.           current version number, namely the string: 
  2395.          Small C Interpreter V1.3 15Mar86 Copyright (C) 1986 Bob Brodt
  2396.  
  2397.  
  2398.  
  2399.  
  2400.  
  2401.  
  2402.  
  2403.  
  2404.  
  2405.  
  2406.  
  2407.  
  2408.  
  2409.  
  2410.  
  2411.  
  2412.  
  2413.  
  2414.  
  2415.  
  2416.  
  2417.  
  2418.  
  2419.  
  2420.  
  2421.  
  2422.  
  2423.  
  2424.  
  2425.                                      - 38 -
  2426.  
  2427.  
  2428.      Small C Interpreter                                      User's Manual
  2429.  
  2430.  
  2431.      6. The Debuger 
  2432.  
  2433.  
  2434.                The Library Function "trace()" allows you to enable or 
  2435.           disable the SCI debuger.  When the debuger is enabled, you 
  2436.           can set and remove breakpoints, examine and modify program 
  2437.           variables and control the execution of your program.  
  2438.  
  2439.                When the debuger is enabled, it first displays each 
  2440.           line of the program on the console before it is executed, 
  2441.           followed by a question mark (?) prompt.  At this point, you 
  2442.           may either enter another valid C statement (to display the 
  2443.           contents of a variable for example), or enter one of the 
  2444.           following commands (NOTE: all of these commands must start 
  2445.           with a dot (.) immediately following the "?"  prompt to 
  2446.           distinguish them from a valid C statement): 
  2447.  
  2448.  
  2449.                b                                                
  2450.                b# - sets a breakpoint at a given line in your 
  2451.                     program.  The "#" symbol represents the line 
  2452.                     number at which the program will be halted.  
  2453.  
  2454.                B                                                   
  2455.                B - displays all breakpoints set in the program.  
  2456.  
  2457.                c                                                
  2458.                c - continues program execution until the next 
  2459.                     breakpoint is encountered.  
  2460.  
  2461.                d                                                     
  2462.                d# - deletes the breakpoint at line number "#". The 
  2463.                     breakpoint must have been previously set with a 
  2464.                     ".b" command.  
  2465.  
  2466.                D                               
  2467.                D - deletes all breakpoints.  
  2468.  
  2469.                e                                                    
  2470.                e# - lets you examine the program with the program 
  2471.                     editor.  Editor commands that would normally 
  2472.                     modify the program are disabled.  
  2473.  
  2474.                g                                                        
  2475.                g - displays all of the program's global variables and 
  2476.                     their values.  If the variable is an array, its 
  2477.                     address is printed followed by the first 10 
  2478.                     elements of the array.  
  2479.  
  2480.                G                                                      
  2481.                G - same as ".g" but also displays the first line of 
  2482.                     every function in the program along with its line 
  2483.                     number.  This is useful for locating a function in 
  2484.                     a long program.  
  2485.  
  2486.                q                                                      
  2487.                q - quits program execution and returns to the shell 
  2488.                     program.  
  2489.  
  2490.                s                                                        
  2491.                s# - steps through the program without displaying each 
  2492.                     line as it is executed.  The "#" is the number of 
  2493.  
  2494.  
  2495.                                      - 39 -
  2496.  
  2497.  
  2498.      Small C Interpreter                                      User's Manual
  2499.  
  2500.  
  2501.                     lines to be executed before control returns to the 
  2502.                     debuger.  
  2503.  
  2504.                t                                                    
  2505.                t - displays the list of active functions with the 
  2506.                     current one at the top of the list.  This is handy 
  2507.                     for finding out "how did I get here?".  
  2508.  
  2509.                T                                                    
  2510.                T - same as ".t" but also displays each function's 
  2511.                     local variables and their values.  
  2512.  
  2513.                 RETURN                        
  2514.                <RETURN> - same as a ".s1".  
  2515.  
  2516.                 ESCAPE                                                 
  2517.                <ESCAPE> - is used to interrupt a program while it is 
  2518.                     running and enable the debuger.  
  2519.  
  2520.  
  2521.                If the SCI interpreter finds an error in your program, 
  2522.           it will automatically enable the debuger and halt the 
  2523.           program at the line where the error occurred.  This can be a 
  2524.           little confusing if you are already in the debuger and you 
  2525.           happen to make a mistake while typing a statement for the 
  2526.           debuger to execute, because the resulting error message and 
  2527.           the "?"  prompt will refer to the statement you just 
  2528.           entered.  If this happens, just hit a <RETURN> and you will 
  2529.           be returned to the program debug session.  
  2530.  
  2531.  
  2532.  
  2533.  
  2534.  
  2535.  
  2536.  
  2537.  
  2538.  
  2539.  
  2540.  
  2541.  
  2542.  
  2543.  
  2544.  
  2545.  
  2546.  
  2547.  
  2548.  
  2549.  
  2550.  
  2551.  
  2552.  
  2553.  
  2554.  
  2555.  
  2556.  
  2557.  
  2558.  
  2559.                                      - 40 -
  2560.  
  2561.  
  2562.      Small C Interpreter                                      User's Manual
  2563.  
  2564.  
  2565.      7. APPENDIX A: SCI Language Syntax 
  2566.  
  2567.  
  2568.                This appendix contains what is known as the 
  2569.           "Backus-Naur Form", or "BNF" of the SCI language.  Named 
  2570.           after its inventors, BNF is a very precise description of a 
  2571.           language and is useful as a reference for proper syntax.  
  2572.           The BNF of a language may at first be a little confusing, 
  2573.           but with practice it can be a very natural way of expressing 
  2574.           the syntax structure of any language.  
  2575.  
  2576.                The following rules apply to the BNF notation in this 
  2577.           appendix: 
  2578.  
  2579.  
  2580.                1) words that appear in UPPER CASE represent key 
  2581.                     elements of the language like the "IF" and "WHILE" 
  2582.                     keywords, or like the symbol for multiplication 
  2583.                     (*). These types of words are known as "TERMINALS" 
  2584.                     and, like atoms, they can not be broken into 
  2585.                     smaller parts.  
  2586.  
  2587.                2) Words in "lower case" represent what are called 
  2588.                     "non-terminals" and, as their name implies, they 
  2589.                     may consist of other smaller elements; either 
  2590.                     TERMINALS or non-terminals.  
  2591.  
  2592.                3) the word to be defined will appear on a line by 
  2593.                     itself, followed by a colon (:) followed by its 
  2594.                     definitions indented below it.  
  2595.  
  2596.                4) within a definition, language elements are seperated 
  2597.                     by a space.  
  2598.  
  2599.                5) depending upon its context, a language element may 
  2600.                     not appear at all and its definition is the 
  2601.                     special "empty" definition.  
  2602.  
  2603.                6) the SCI-style comment mark (#) is used only to 
  2604.                     clarify a definition and is not part of the 
  2605.                     definition 
  2606.  
  2607.  
  2608.                We have always been taught never to use a word we are 
  2609.           defining in its definition, that "recursive definitions" are 
  2610.           blasphemous!  However when defining language syntax it is 
  2611.           often desirable, indeed necessary, to use recursive 
  2612.           definitions.  Take for example the BNF description of a word 
  2613.           in the english language: a word may be one or more letters 
  2614.           strung together.  More formally, 
  2615.  
  2616.  
  2617.  
  2618.  
  2619.           APPENDIX                   - 41 -
  2620.  
  2621.  
  2622.      Small C Interpreter                                      User's Manual
  2623.  
  2624.  
  2625.                a "word": may be either:
  2626.                     1. a "letter", or
  2627.                     2. a "word" followed by a "letter"
  2628.  
  2629.  
  2630.                Here we can deduce definition number 2 because the 
  2631.           first letter of a word qualifies as a word itself, according 
  2632.           to our definition 1.  Even more formally, 
  2633.  
  2634.  
  2635.                word:
  2636.                     LETTER       # for example the word "a"
  2637.                     word LETTER  # for example the word "as"
  2638.  
  2639.  
  2640.                We have written "LETTER" in upper case to indicate that 
  2641.           a letter can not be broken down any further, i.e.  it is a 
  2642.           "TERMINAL". Similarly, "word" appears in lower case because 
  2643.           it can be broken down into smaller parts; it is a 
  2644.           "non-terminal".  
  2645.  
  2646.                Here then, is the BNF of the SCI language.  Assume that 
  2647.           you already know what the terminals LETTER (one of: a b 
  2648.           c...z, or A B C...Z, or _), NUMBER (one of: 0 1 2...9), 
  2649.           HEXDIGITS (0 1 2...9 A B...F) and OCTALDIGITS (0 1 2...7) 
  2650.           are.  
  2651.  
  2652.  
  2653.                id-list:           # identifier (variable) list
  2654.                     empty         # may be non-existent
  2655.                     id            # or a single identifier
  2656.                     id-list , id  # or two or more id's seperated by a comma
  2657.                
  2658.                id:                # an identifier (variable)
  2659.                     LETTER
  2660.                     id LETTER
  2661.                     id NUMBER
  2662.                
  2663.                hex-constant:      # hexadecimal constant
  2664.                     0 X HEXDIGITS
  2665.                
  2666.                oct-constant:      # octal constant
  2667.                     0 OCTALDIGITS
  2668.                
  2669.                dec-constant:      # decimal constant
  2670.                     NUMBER
  2671.                     constant NUMBER
  2672.                
  2673.                chr-constant:      # character constant
  2674.                     ' CHARACTER '
  2675.                
  2676.                str-constant:      # string constant
  2677.  
  2678.  
  2679.           APPENDIX                   - 42 -
  2680.  
  2681.  
  2682.      Small C Interpreter                                      User's Manual
  2683.  
  2684.  
  2685.                     " CHARACTER-LIST "
  2686.                
  2687.                constant:          # constants 'R' all of the above
  2688.                     dec-constant
  2689.                     hex-constant
  2690.                     oct-constant
  2691.                     chr-constant
  2692.                     str-constant
  2693.                
  2694.                expression-list:
  2695.                     empty
  2696.                     expression
  2697.                     expression-list , expression
  2698.                
  2699.                expression:
  2700.                     primary
  2701.                     * expression
  2702.                     & lvalue
  2703.                     ++ lvalue
  2704.                     -- lvalue
  2705.                     lvalue ++
  2706.                     lvalue --
  2707.                     - primary
  2708.                     + primary
  2709.                     ! expression
  2710.                     ~ expression
  2711.                     expression binop expression
  2712.                     lvalue = expression
  2713.                
  2714.                primary:
  2715.                     id
  2716.                     constant
  2717.                     string
  2718.                     ( expression )          # a parenthesized expression
  2719.                     id ( expression-list )  # a function call
  2720.                     id [ expression ]       # an array element
  2721.                
  2722.                lvalue:
  2723.                     id                      # a simple variable
  2724.                     id [ expression ]       # an array element
  2725.                     * expression            # a pointer expression
  2726.                
  2727.                binop:             # the binary operators:
  2728.                     *
  2729.                     /
  2730.                     %
  2731.                     +
  2732.                     -
  2733.                     <<
  2734.                     >>
  2735.                     <
  2736.                     <=
  2737.  
  2738.  
  2739.           APPENDIX                   - 43 -
  2740.  
  2741.  
  2742.      Small C Interpreter                                      User's Manual
  2743.  
  2744.  
  2745.                     >
  2746.                     >=
  2747.                     ==
  2748.                     !=
  2749.                     &
  2750.                     ^
  2751.                     |
  2752.                     &&
  2753.                     ||
  2754.                
  2755.                declaration-list:
  2756.                     empty
  2757.                     declaration
  2758.                     declaration-list declaration
  2759.                
  2760.                declaration:
  2761.                     type-spec declarator-list ;
  2762.                
  2763.                type-spec:
  2764.                     CHAR
  2765.                     INT
  2766.                
  2767.                declarator-list:
  2768.                     declarator
  2769.                     declarator-list , declarator
  2770.                
  2771.                declarator:
  2772.                     id
  2773.                     id [ constant ]
  2774.                     * id
  2775.                
  2776.                statement-list:
  2777.                     statement
  2778.                     statement-list statement
  2779.                
  2780.                compound-statement:
  2781.                     { declaration-list statement-list }
  2782.                
  2783.                statement:
  2784.                     ;                  # a no-op statement
  2785.                     compound-statement
  2786.                     expression ;
  2787.                     IF ( expression ) statement
  2788.                     IF ( expression ) statement ELSE statement
  2789.                     SWITCH ( expression ) statement
  2790.                     CASE constant : statement
  2791.                     DEFAULT : statement
  2792.                     BREAK ;
  2793.                     WHILE ( expression ) statement
  2794.                     FOR ( expression ; expression ; expression ) statement ;
  2795.                     RETURN ;
  2796.                     RETURN expression ;
  2797.  
  2798.  
  2799.           APPENDIX                   - 44 -
  2800.  
  2801.  
  2802.      Small C Interpreter                                      User's Manual
  2803.  
  2804.  
  2805.                
  2806.                function:
  2807.                     id ( id-list ) declaration-list compound-statement
  2808.                
  2809.                function-list:
  2810.                     empty
  2811.                     function
  2812.                     function-list function
  2813.                
  2814.                program:
  2815.                     empty
  2816.                     declaration-list
  2817.                     function-list
  2818.                     program declaration-list
  2819.                     program function-list
  2820.  
  2821.  
  2822.  
  2823.  
  2824.  
  2825.  
  2826.  
  2827.  
  2828.  
  2829.  
  2830.  
  2831.  
  2832.  
  2833.  
  2834.  
  2835.  
  2836.  
  2837.  
  2838.  
  2839.  
  2840.  
  2841.  
  2842.  
  2843.  
  2844.  
  2845.  
  2846.  
  2847.  
  2848.  
  2849.  
  2850.  
  2851.  
  2852.  
  2853.  
  2854.  
  2855.  
  2856.  
  2857.  
  2858.  
  2859.           APPENDIX                   - 45 -
  2860.  
  2861.  
  2862.      Small C Interpreter                                      User's Manual
  2863.  
  2864.  
  2865.      8. APPENDIX B: Editor Command Summary 
  2866.  
  2867.  
  2868.  
  2869.                 Z          
  2870.                ^Z - exit 
  2871.  
  2872.                 E               
  2873.                ^E - cursor up 
  2874.  
  2875.                 X                 
  2876.                ^X - cursor down 
  2877.  
  2878.                 S                 
  2879.                ^S - cursor left 
  2880.  
  2881.                 D                  
  2882.                ^D - cursor right 
  2883.  
  2884.                 A                                    
  2885.                ^A - cursor to end of previous word 
  2886.  
  2887.                 F                                        
  2888.                ^F - cursor to beginning of next word.  
  2889.  
  2890.                 R             
  2891.                ^R - page up 
  2892.  
  2893.                 C               
  2894.                ^C - page down 
  2895.  
  2896.                 RETURN  or  LINEFEED                              
  2897.                <RETURN> or <LINEFEED> - Replace Mode: cursor to 
  2898.                     beginning of next line Insert Mode: append blank 
  2899.                     line after current line 
  2900.  
  2901.                 V                                
  2902.                ^V - toggle Insert/Replace Mode 
  2903.  
  2904.                 G                                   
  2905.                ^G - delete character under cursor 
  2906.  
  2907.                 H or  BACKSPACE                                         
  2908.                ^H or <BACKSPACE> - delete character to left of cursor 
  2909.  
  2910.                 Y                 
  2911.                ^Y - delete line 
  2912.  
  2913.                 L                  
  2914.                ^L - restore line 
  2915.  
  2916.                 Q F                 
  2917.                ^Q^F - find string 
  2918.  
  2919.                 Q A                             
  2920.                ^Q^A - find and replace string 
  2921.  
  2922.                 Q L                                   
  2923.                ^Q^L - find next occurance of string 
  2924.  
  2925.                 Q G                
  2926.                ^Q^G - go to line 
  2927.  
  2928.                 Q S                                 
  2929.                ^Q^S - cursor to beginning of line 
  2930.  
  2931.                 Q D                           
  2932.                ^Q^D - cursor to end of line 
  2933.  
  2934.                 Q E                             
  2935.                ^Q^E - cursor to top of screen 
  2936.  
  2937.                 Q X                                
  2938.                ^Q^X - cursor to bottom of screen 
  2939.  
  2940.  
  2941.  
  2942.           APPENDIX                   - 46 -
  2943.  
  2944.  
  2945.      Small C Interpreter                                      User's Manual
  2946.  
  2947.  
  2948.                 Q R                              
  2949.                ^Q^R - cursor to top of program 
  2950.  
  2951.                 Q C                              
  2952.                ^Q^C - cursor to end of program 
  2953.  
  2954.                 Q B                                  
  2955.                ^Q^B - cursor to beginning of block 
  2956.  
  2957.                 Q K                            
  2958.                ^Q^K - cursor to end of block 
  2959.  
  2960.                 K B                             
  2961.                ^K^B - mark beginning of block 
  2962.  
  2963.                 K K                       
  2964.                ^K^K - mark end of block 
  2965.  
  2966.                 K V                  
  2967.                ^K^V - insert block 
  2968.  
  2969.                 K Y                  
  2970.                ^K^Y - delete block 
  2971.  
  2972.                 K U                  
  2973.                ^K^U - unmark block 
  2974.  
  2975.                 K R                         
  2976.                ^K^R - read from disk file 
  2977.  
  2978.                 K W                              
  2979.                ^K^W - write block to disk file 
  2980.  
  2981.  
  2982.  
  2983.  
  2984.  
  2985.  
  2986.  
  2987.  
  2988.  
  2989.  
  2990.  
  2991.  
  2992.  
  2993.  
  2994.  
  2995.  
  2996.  
  2997.  
  2998.  
  2999.  
  3000.  
  3001.  
  3002.  
  3003.  
  3004.  
  3005.  
  3006.  
  3007.  
  3008.  
  3009.  
  3010.  
  3011.  
  3012.  
  3013.           APPENDIX                   - 47 -
  3014.  
  3015.  
  3016.      Small C Interpreter                                      User's Manual
  3017.  
  3018.  
  3019.      9. APPENDIX C: Debuger Command Summary 
  3020.  
  3021.           All debuger commands start with a dot (.) as the first 
  3022.           character in the command to distinguish them from valid C 
  3023.           statements.  
  3024.  
  3025.  
  3026.                b                                            
  3027.                b# - set a breakpoint at line number "#".  
  3028.  
  3029.                B                                   
  3030.                B - display all breakpoints set.  
  3031.  
  3032.                c                                                     
  3033.                c - continue program execution to next breakpoint.  
  3034.  
  3035.                d                                             
  3036.                d# - delete breakpoint at line number "#".  
  3037.  
  3038.                D                              
  3039.                D - delete all breakpoints.  
  3040.  
  3041.                e                                            
  3042.                e# - examine program with the SCI editor.  
  3043.  
  3044.                g                                                   
  3045.                g - display global variables and their contents.  
  3046.  
  3047.                G                                                     
  3048.                G - same as ".g" but also display the first line of 
  3049.                     every function in the program.  
  3050.  
  3051.                q                                
  3052.                q - quit and return to shell.  
  3053.  
  3054.                s                                                    
  3055.                s# - step "#" lines without displaying each line.  
  3056.  
  3057.                t                                        
  3058.                t - display function call back trace.  
  3059.  
  3060.                T                                                    
  3061.                T - same as ".t" but also displays each function's 
  3062.                     local variables and contents.  
  3063.  
  3064.                 RETURN                       
  3065.                <RETURN> - same as ".s 1".  
  3066.  
  3067.                 ESCAPE                                                  
  3068.                <ESCAPE> - interrupts an executing program and enables 
  3069.                     debuger.  
  3070.  
  3071.  
  3072.  
  3073.  
  3074.  
  3075.  
  3076.  
  3077.  
  3078.  
  3079.  
  3080.  
  3081.  
  3082.  
  3083.  
  3084.  
  3085.  
  3086.  
  3087.           APPENDIX                   - 48 -
  3088.  
  3089.  
  3090.      Small C Interpreter                                      User's Manual
  3091.  
  3092.  
  3093.      10. APPENDIX D: Differences From Small C 
  3094.  
  3095.  
  3096.                SCI supports the subset of the C language defined by J. 
  3097.           Hendrix' public domain "Small C" compiler, available for 
  3098.           many CP/M and MS-DOS machines.  There are, however, some 
  3099.           minor differences that have been dictated in part by the 
  3100.           fact that this is an interpreter.  These are: 
  3101.  
  3102.  
  3103.                1) Program source lines are limited to 80 characters, 
  3104.                     just to keep things simple.  The editor will 
  3105.                     complain if you try to create a line longer than 
  3106.                     80 characters.  
  3107.  
  3108.                2) There are no #define or #include statements, simply 
  3109.                     because there is no pre-processor!  
  3110.  
  3111.                3) Comments are introduced by the number symbol (#) and 
  3112.                     are terminated by the end of the line.  The "/*" 
  3113.                     and "*/" combinations will only be barfed at by 
  3114.                     SCI.  
  3115.  
  3116.                4) Statements in general are terminated by the end of a 
  3117.                     line - the semicolon required by the C language at 
  3118.                     the end of a statement is superfluous.  This 
  3119.                     restriction imposes that an expression be 
  3120.                     completely on one line (boooo, hissss!), however 
  3121.                     you no longer get penalized for forgeting a 
  3122.                     semicolon (hurray, yay!).  This also implies that 
  3123.                     string and character constants are terminated by 
  3124.                     the end of the line.  In fact, if you forget to 
  3125.                     add the terminating quote or apostrophe delimiter, 
  3126.                     SCI will append one for you.  
  3127.  
  3128.                5) Data variable initialization is not supported by 
  3129.                     SCI.  
  3130.  
  3131.                6) Local data variables declared inside a compound 
  3132.                     statement within a function may not have the same 
  3133.                     name as a previously declared local variable.  A 
  3134.                     "variable already declared" error will result.  
  3135.                     All other scope rules apply.  
  3136.  
  3137.                7) Pointer arithmetic is not smart enough to recognize 
  3138.                     data types so that pointers to integers are 
  3139.                     advanced to the next BYTE, not the next integer.  
  3140.                     For example, *(ip+1) will point to the least 
  3141.                     significant byte of the next integer (on an 8086 
  3142.                     machine), not the next word (booo, hisss!).  But, 
  3143.                     ip[1] and ++ip still point to the next integer 
  3144.                     (whew!).  Also, SCI allows does not restrict 
  3145.  
  3146.  
  3147.           APPENDIX                   - 49 -
  3148.  
  3149.  
  3150.      Small C Interpreter                                      User's Manual
  3151.  
  3152.  
  3153.                     pointer arithmetic to just addition and 
  3154.                     subtraction, like standard C does.  
  3155.  
  3156.                8) The logical AND and OR operators (&& and ||) 
  3157.                     evaluate both of their operands, unlike standard C 
  3158.                     which stops evaluation once the truth or falsehood 
  3159.                     of an expression is known.  
  3160.  
  3161.                9) The comma operator is recognized only when used in 
  3162.                     function calls and data declarations.  For 
  3163.                     instance, it would be illegal to say: while ( 
  3164.                     argv++, argc-- ); 
  3165.  
  3166.                10) The "default" statement inside a "switch" is 
  3167.                     executed as soon as it is encountered (when 
  3168.                     scanning from the top to the bottom of the 
  3169.                     "switch"). SCI is too lazy to do an exhaustive 
  3170.                     test of all "case"s before executing the 
  3171.                     "default", so be sure to place all "default"s as 
  3172.                     the last statement in the "switch".  
  3173.  
  3174.  
  3175.  
  3176.  
  3177.  
  3178.  
  3179.  
  3180.  
  3181.  
  3182.  
  3183.  
  3184.  
  3185.  
  3186.  
  3187.  
  3188.  
  3189.  
  3190.  
  3191.  
  3192.  
  3193.  
  3194.  
  3195.  
  3196.  
  3197.  
  3198.  
  3199.  
  3200.  
  3201.  
  3202.  
  3203.  
  3204.  
  3205.  
  3206.  
  3207.           APPENDIX                   - 50 -
  3208.  
  3209.  
  3210.      Small C Interpreter                                      User's Manual
  3211.  
  3212.  
  3213.      11. APPENDIX E: Error Messages 
  3214.  
  3215.  
  3216.                When SCI detects an error in your program, it will stop 
  3217.           execution, display an error message and then the line number 
  3218.           and program text of the offending line.  The SCI debuger is 
  3219.           then automatically enabled.  The possible error messages are 
  3220.           listed below: 
  3221.  
  3222.  
  3223.                no entry point                                    
  3224.                no entry point - You forgot to specify an entry 
  3225.                     function with the "entry" keyword.  
  3226.  
  3227.                not enough table space                                 
  3228.                not enough table space - There was insufficient free 
  3229.                     memory available for the shell program, variable, 
  3230.                     function and stack segments.  Specify a smaller 
  3231.                     -P, -V, -F or -S value.  
  3232.  
  3233.                file I O error                                          
  3234.                file I/O error - The specified program file could not 
  3235.                     be loaded, or SHELL.SCI does not exist on the 
  3236.                     default disk drive.  Or, the specified file could 
  3237.                     not be save on disk because of an operating system 
  3238.                     error.  
  3239.  
  3240.                missing                                                  
  3241.                missing '}' - The interpreter wandered off the edge of 
  3242.                     your program because you forgot a closing brace.  
  3243.  
  3244.                missing operator                               
  3245.                missing operator - The interpreter found two 
  3246.                     consecutive operands as for example the statement: 
  3247.                     var 3; 
  3248.  
  3249.                missing     or                                   
  3250.                missing ')' or ']' - Mismatched left and right 
  3251.                     parentheses or brackets were detected.  
  3252.  
  3253.                not a pointer                                           
  3254.                not a pointer - A simple "char" or "int" variable was 
  3255.                     used as an array or pointer.  
  3256.  
  3257.                syntax error                                            
  3258.                syntax error - An error was detected in the structure 
  3259.                     of a statement or function.  
  3260.  
  3261.                lexical error                                         
  3262.                lexical error - An illegal character was found in a 
  3263.                     statement.  
  3264.  
  3265.                need an lvalue                                           
  3266.                need an lvalue - An attempt was made to assign a value 
  3267.                     to a constant or an array variable.  
  3268.  
  3269.                stack underflow                                      
  3270.                stack underflow - Something is wrong!  Contact the 
  3271.                     author.  
  3272.  
  3273.                stack overflow                                      
  3274.                stack overflow - The expression is too complex or 
  3275.                     function calls are nested too deeply.  Try 
  3276.                     specifying a larger -S value when starting up 
  3277.  
  3278.  
  3279.           APPENDIX                   - 51 -
  3280.  
  3281.  
  3282.      Small C Interpreter                                      User's Manual
  3283.  
  3284.  
  3285.                     SCI.  
  3286.  
  3287.                too many functions                                
  3288.                too many functions - The interpreter ran out of 
  3289.                     Function Table space.  Try specifying a larger -F 
  3290.                     value when starting up SCI.  
  3291.  
  3292.                too many variables                                
  3293.                too many variables - The interpreter ran out of 
  3294.                     Variable Table space.  Try specifying a larger -V 
  3295.                     value when starting up SCI.  
  3296.  
  3297.                out of memory                                        
  3298.                out of memory - The interpreter ran out of Program 
  3299.                     space.  Try specifying a larger -P value when 
  3300.                     starting up SCI.  
  3301.  
  3302.                stmt outside of function                              
  3303.                stmt outside of function - There is something wrong 
  3304.                     with the structure of your program.  Typically 
  3305.                     this results from a statement appearing outside of 
  3306.                     any function body.  
  3307.  
  3308.                missing                                                   
  3309.                missing '{' - The left brace that introduces a function 
  3310.                     body was missing.  
  3311.  
  3312.                wrong   of arguments in sys call                   
  3313.                wrong # of arguments in sys call - The number of 
  3314.                     arguments passed to a "sys" call is incorrect for 
  3315.                     the specified "sys" number.  
  3316.  
  3317.                undefined variable                                      
  3318.                undefined variable - A variable has been used without 
  3319.                     ever having been declared.  
  3320.  
  3321.                variable already declared                            
  3322.                variable already declared - An attempt was made to 
  3323.                     re-declare a variable name within the program or 
  3324.                     function.  
  3325.  
  3326.                interrupt                                                 
  3327.                interrupt - The program was interrupted by pressing the 
  3328.                     <ESCAPE> key.  
  3329.  
  3330.  
  3331.  
  3332.  
  3333.  
  3334.  
  3335.  
  3336.  
  3337.  
  3338.  
  3339.  
  3340.  
  3341.  
  3342.  
  3343.  
  3344.  
  3345.  
  3346.  
  3347.  
  3348.           APPENDIX                   - 52 -
  3349.  
  3350.