basic.doc
上传用户:upcnvip
上传日期:2007-01-06
资源大小:474k
文件大小:11k
源码类别:

编译器/解释器

开发平台:

C/C++

  1.                              Chipmunk BASIC 1.0
  2.                                David Gillespie
  3.        --------------------------------------------------------------
  4.    COMMANDS
  5.       LIST line(s)
  6.          List the specified program lines.  For example,
  7.                LIST 10, 100-200
  8.          lists line 10, and lines 100 through 200, inclusive.
  9.       RUN [line]
  10.          Begin execution of the program at the first line, or at the
  11.          specified line.  All variables are cleared.
  12.       RUN file[,line]
  13.          Load and run a program.  For example,
  14.                RUN "FOO", 30
  15.          loads a program from the file FOO.TEXT and begins execution at
  16.          line 30.
  17.       NEW
  18.          Erase the program in memory.
  19.       LOAD file
  20.          Load a program into memory.  The program previously in memory is
  21.          erased.  The file name should be in quotes; a .TEXT extension is
  22.          automatically added.  Files contain ASCII listings of the programs.
  23.          All lines in the file must begin with a line number, but line
  24.          numbers do not need to be in increasing order.
  25.       MERGE file
  26.          Load a program into memory.  The previous program remains in
  27.          memory; if a line exists in both programs, the newly loaded
  28.          line is kept.
  29.       SAVE file
  30.          Save the program in memory to a file.
  31.       BYE
  32.          Return to the operating system.
  33.       DEL line(s)
  34.          Delete the specified program lines.  Line numbers may be
  35.          separated by commas and dashes as in LIST.  If used inside
  36.          a program, DEL will terminate execution only if it deletes
  37.          the line on which it appears.
  38.       RENUM [start[,inc]]
  39.          Renumber program lines.  By default, the new sequence is 10,20,30,...
  40.          The first argument is a new initial line number; the second argument
  41.          is the increment between line numbers.
  42.    STATEMENTS
  43.       REM comment
  44.          A remark; ignored.  Comments may contain any characters except
  45.          that REM can not be immediately followed by an alphanumeric
  46.          character.
  47.       [LET] var = expr
  48.          Assign a value to a variable.  Variable names contain up to 20
  49.          significant characters, consisting of upper- and lower-case
  50.          letters, digits, underscores, and dollar signs.  Variable names
  51.          are case-sensitive.  Variables hold real numbers normally, or
  52.          strings of up to 255 characters if their names end with $.
  53.          Examples:
  54.                LET X=20
  55.                X$="FOO"
  56.                X$=X$+"BAR"
  57.       DIM var(dimensions), ...
  58.          Allocate memory for arrays.  Arrays may have up to 4 dimensions,
  59.          ranging from 0 to the value specified in the DIM statement.
  60.          The same name must not be used for both a simple variable and
  61.          an array.
  62.          If an array is used before it is dimensioned, each dimension
  63.          is set to 10.
  64.          Example:
  65.                INPUT "How many elements? "; x
  66.                DIM array(x,1)
  67.                FOR i=1 TO x : INPUT array(i,0), array(i,1) : NEXT
  68.       PRINT items
  69.          Print the items on the screen.  Items may be either numeric
  70.          or string expressions, and may be separated by commas, semicolons,
  71.          or nothing.
  72.          Numbers are normally terminated by spaces.  To avoid this space,
  73.          convert the number to a string with STR$.
  74.          The line is terminated by a CR/LF, unless the item list ends 
  75.          with a comma or semicolon.
  76.          The word PRINT may be abbreviated as a question mark.
  77.          Examples:
  78.                PRINT "1+2=", 1+2
  79.                PRINT X$ "=" Z$;
  80.                ? x; y+z
  81.       INPUT [prompt;] vars
  82.          If a prompt string is given, it is printed.  Otherwise, a
  83.          question mark is printed.  The computer then waits for values 
  84.          for each variable to be entered.  If several variables are
  85.          listed, their names must be separated by commas.
  86.          If the variables are numeric, their values may be entered
  87.          on separate lines, or combined with commas.  Any numeric expression
  88.          is a valid response.
  89.          If the variables are strings, each string is typed on a separate
  90.          line.  The characters typed are copied verbatim into the string.
  91.          String and numeric variables may be not mixed in a single
  92.          INPUT statement.
  93.          Examples:
  94.             INPUT X$
  95.             INPUT "Type 3 numbers: "; X, Y, Z
  96.       GOTO line
  97.          Begin executing statements at the specified line.  The line
  98.          number may be any numeric expression.
  99.          The word GO TO may be used instead of GOTO if preferable.
  100.       IF condition THEN line/statements ELSE line/statements
  101.          If the condition is true (i.e., the numeric expression has a
  102.          non-zero value), the statements following the word THEN are
  103.          executed.  Otherwise, the statements following ELSE are
  104.          executed.  If there is no ELSE clause, execution proceeds
  105.          to the next line in the program.
  106.          A line number may be used after either THEN or ELSE, for an
  107.          implied GOTO statement.
  108.       END
  109.          Terminate the program.  An END statement is not required.
  110.       STOP
  111.          Terminate the program with an identifying "Break" message.
  112.       FOR var = first TO last [STEP inc]
  113.       {statements}
  114.       NEXT [var]
  115.          Execute {statements} repeatedly while the variable counts from
  116.          "first" to "last," incrementing by 1, or by the STEP value if
  117.          given.  If the STEP value is negative, the variable counts
  118.          downward.
  119.          If "first" is greater than "last" (or less than if STEP is
  120.          negative), execution proceeds directly to the NEXT statement,
  121.          without executing the body of the loop at all.
  122.          The variable name is optional on the NEXT statement.
  123.       WHILE [condition]
  124.       {statements}
  125.       WEND [condition]
  126.          Execute {statements} repeatedly until the WHILE condition (if
  127.          given) becomes false, or until the WEND condition becomes true.
  128.          This structure can emulate Pascal's WHILE-DO and REPEAT-UNTIL,
  129.          or even both at once.  If no conditions are given, the loop will
  130.          never terminate unless the Evil GOTO is used.
  131.       GOSUB line
  132.       RETURN
  133.          Execute the statements beginning at the specified line, then
  134.          when RETURN is reached, return to the statement following the 
  135.          GOSUB.
  136.       READ vars
  137.       DATA values
  138.       RESTORE line
  139.          Read numeric or string values from the DATA statements.  Reading
  140.          begins at the first DATA statement in the program and proceeds
  141.          to the last.  Reading past the end the last DATA statement
  142.          generates an error.
  143.          The DATA values must be either numeric or string expressions,
  144.          according to the type of variable being read.  Reading the wrong
  145.          kind of expression produces a Syntax Error.
  146.          The RESTORE statement causes the next READ to re-use the first
  147.          DATA statement in the program, or the first DATA statement on
  148.          or after a particular line.
  149.       GOTOXY across, down
  150.          Move the cursor to the specified screen position, between
  151.          0,0 and 79,23.
  152.       ON expr GOTO line, line, ...
  153.       ON expr GOSUB line, line, ...
  154.          If the expression's value, rounded to an integer, is N, go to
  155.          the Nth line number in the list.  If N is less than one or is
  156.          too large, execution continues at the next statement after
  157.          the ON-GOTO or ON-GOSUB.
  158.       POKE addr, data
  159.          Store a byte at the specified address.
  160.    NUMERIC EXPRESSIONS
  161.       x AND y
  162.          Logical AND of two integers.
  163.       x OR y
  164.          Logical OR of two integers.
  165.       x XOR y
  166.          Logical XOR of two integers.
  167.       NOT x
  168.          Logical complement of an integer.
  169.       x+y, x-y, x*y, x/y, x^y, -x
  170.          Typical floating-point arithmetic operations.
  171.       x=y, x<y, x>y, x<=y, x>=y, x<>y
  172.          Comparisons; result is 1 if true, 0 if false.
  173.       x MOD y
  174.          Modulo of two integers.
  175.       SQR x
  176.          Square of X.  Note that parentheses are not required if a function's
  177.          argument is a single entitity; for example, SQR SIN X needs no
  178.          parentheses, but SQR(1+X) does.
  179.       SQRT x
  180.          Square root of X.
  181.       SIN x, COS x, TAN x, ARCTAN x
  182.          Typical trig functions, in radians.
  183.       LOG x, EXP x
  184.          Natural logarithm, and e the power X.
  185.       ABS x
  186.          Absolute value of X.
  187.       SGN x
  188.          Sign of X:  1 if X is positive, 0 if zero, -1 if negative.
  189.       VAL x$
  190.          Value of the expression contained in the string X$.  For example,
  191.          VAL "1+2" yields 3.  X$ may be a single string literal, variable,
  192.          or function, or a string expression in parentheses.
  193.       ASC x$
  194.          ASCII code of the first character in X$, or 0 if X$ is null.
  195.       LEN x$
  196.          Number of characters in X$.
  197.       Precedence:      Parentheses
  198.                         Functions  (incl. NOT and unary minus)
  199.                             ^
  200.                         *, /, MOD
  201.                           +, -
  202.                    =, <, >, <=, >=, <>
  203.                            AND
  204.                          OR, XOR
  205.    STRING EXPRESSIONS
  206.       "string" or 'string'
  207.          String literal.  Single quotes are converted to double quotes
  208.          internally.
  209.       x$+y$
  210.          Concatenation.  Result must be 255 characters or less.
  211.       x$=y$, x$<y$, x$>y$, x$<=y$, x$>=y$, x$<>y$
  212.          String comparisons; result is 1 if true, 0 if false.
  213.       STR$(x)
  214.          The number X expressed as a string of digits.  No leading or
  215.          trailing spaces are included; scientific notation is used
  216.          if the absolute values is greater than 1E12 or less than 1E-2.
  217.       CHR$(x)
  218.          The character whose ASCII code is X.
  219.       MID$(x$, y)
  220.       MID$(x$, y, z)
  221.          (Parentheses required.)  The substring consisting of the first
  222.          Z characters starting at position Y of string X$.  Position 1
  223.          is the first character of the string.  If Z is omitted, 255
  224.          is used, i.e., the entire right part of the string.
  225.    CONVENTIONS
  226.       Multiple statements may be written on a line, separated by colons:
  227.             10 INPUT X : PRINT X : STOP
  228.       There is actually no difference between commands and statements;
  229.       both can be used in or out of programs at will.  Certain commands,
  230.       such as NEW, will, of course, halt program execution.
  231.       Line numbers may be any integer from 1 to MAXINT.
  232.       To delete a line use DEL, or type its line number alone:
  233.             10
  234.       Press CLR I/O to halt program execution.  [This is not supported
  235.       by p2c's translation!]  To leave BASIC, use the BYE command.
  236.       Keywords must be written in all upper- or all lower-case; they are
  237.       always converted to upper-case internally.  Spaces are ignored in
  238.       the input except between quotes.  Square brackets are converted to
  239.       parentheses.  Missing closing quotes at the end of the line are
  240.       added, as in the command:
  241.             SAVE "PROGRAM