home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 379b.lha / p2c_v1.13a / examples / basic.doc < prev    next >
Text File  |  1990-06-03  |  11KB  |  449 lines

  1.  
  2.                              Chipmunk BASIC 1.0
  3.                                David Gillespie
  4.  
  5.  
  6.        --------------------------------------------------------------
  7.  
  8.  
  9.  
  10.  
  11.    COMMANDS
  12.  
  13.  
  14.       LIST line(s)
  15.  
  16.          List the specified program lines.  For example,
  17.  
  18.                LIST 10, 100-200
  19.  
  20.          lists line 10, and lines 100 through 200, inclusive.
  21.  
  22.  
  23.       RUN [line]
  24.  
  25.          Begin execution of the program at the first line, or at the
  26.          specified line.  All variables are cleared.
  27.  
  28.  
  29.       RUN file[,line]
  30.  
  31.          Load and run a program.  For example,
  32.  
  33.                RUN "FOO", 30
  34.  
  35.          loads a program from the file FOO.TEXT and begins execution at
  36.          line 30.
  37.  
  38.  
  39.       NEW
  40.  
  41.          Erase the program in memory.
  42.  
  43.  
  44.       LOAD file
  45.  
  46.          Load a program into memory.  The program previously in memory is
  47.          erased.  The file name should be in quotes; a .TEXT extension is
  48.          automatically added.  Files contain ASCII listings of the programs.
  49.          All lines in the file must begin with a line number, but line
  50.          numbers do not need to be in increasing order.
  51.  
  52.  
  53.       MERGE file
  54.  
  55.          Load a program into memory.  The previous program remains in
  56.          memory; if a line exists in both programs, the newly loaded
  57.          line is kept.
  58.  
  59.  
  60.       SAVE file
  61.  
  62.          Save the program in memory to a file.
  63.  
  64.  
  65.       BYE
  66.  
  67.          Return to the operating system.
  68.  
  69.  
  70.       DEL line(s)
  71.  
  72.          Delete the specified program lines.  Line numbers may be
  73.          separated by commas and dashes as in LIST.  If used inside
  74.          a program, DEL will terminate execution only if it deletes
  75.          the line on which it appears.
  76.  
  77.  
  78.       RENUM [start[,inc]]
  79.  
  80.          Renumber program lines.  By default, the new sequence is 10,20,30,...
  81.          The first argument is a new initial line number; the second argument
  82.          is the increment between line numbers.
  83.  
  84.  
  85.  
  86.  
  87.    STATEMENTS
  88.  
  89.       REM comment
  90.  
  91.          A remark; ignored.  Comments may contain any characters except
  92.          that REM can not be immediately followed by an alphanumeric
  93.          character.
  94.  
  95.  
  96.       [LET] var = expr
  97.  
  98.          Assign a value to a variable.  Variable names contain up to 20
  99.          significant characters, consisting of upper- and lower-case
  100.          letters, digits, underscores, and dollar signs.  Variable names
  101.          are case-sensitive.  Variables hold real numbers normally, or
  102.          strings of up to 255 characters if their names end with $.
  103.  
  104.          Examples:
  105.  
  106.                LET X=20
  107.                X$="FOO"
  108.                X$=X$+"BAR"
  109.  
  110.  
  111.       DIM var(dimensions), ...
  112.  
  113.          Allocate memory for arrays.  Arrays may have up to 4 dimensions,
  114.          ranging from 0 to the value specified in the DIM statement.
  115.          The same name must not be used for both a simple variable and
  116.          an array.
  117.  
  118.          If an array is used before it is dimensioned, each dimension
  119.          is set to 10.
  120.  
  121.          Example:
  122.  
  123.                INPUT "How many elements? "; x
  124.                DIM array(x,1)
  125.                FOR i=1 TO x : INPUT array(i,0), array(i,1) : NEXT
  126.  
  127.  
  128.       PRINT items
  129.  
  130.          Print the items on the screen.  Items may be either numeric
  131.          or string expressions, and may be separated by commas, semicolons,
  132.          or nothing.
  133.  
  134.          Numbers are normally terminated by spaces.  To avoid this space,
  135.          convert the number to a string with STR$.
  136.  
  137.          The line is terminated by a CR/LF, unless the item list ends 
  138.          with a comma or semicolon.
  139.  
  140.          The word PRINT may be abbreviated as a question mark.
  141.  
  142.          Examples:
  143.  
  144.                PRINT "1+2=", 1+2
  145.                PRINT X$ "=" Z$;
  146.                ? x; y+z
  147.  
  148.  
  149.       INPUT [prompt;] vars
  150.  
  151.          If a prompt string is given, it is printed.  Otherwise, a
  152.          question mark is printed.  The computer then waits for values 
  153.          for each variable to be entered.  If several variables are
  154.          listed, their names must be separated by commas.
  155.  
  156.          If the variables are numeric, their values may be entered
  157.          on separate lines, or combined with commas.  Any numeric expression
  158.          is a valid response.
  159.  
  160.          If the variables are strings, each string is typed on a separate
  161.          line.  The characters typed are copied verbatim into the string.
  162.  
  163.          String and numeric variables may be not mixed in a single
  164.          INPUT statement.
  165.  
  166.          Examples:
  167.  
  168.             INPUT X$
  169.             INPUT "Type 3 numbers: "; X, Y, Z
  170.  
  171.  
  172.       GOTO line
  173.  
  174.          Begin executing statements at the specified line.  The line
  175.          number may be any numeric expression.
  176.  
  177.          The word GO TO may be used instead of GOTO if preferable.
  178.  
  179.  
  180.       IF condition THEN line/statements ELSE line/statements
  181.  
  182.          If the condition is true (i.e., the numeric expression has a
  183.          non-zero value), the statements following the word THEN are
  184.          executed.  Otherwise, the statements following ELSE are
  185.          executed.  If there is no ELSE clause, execution proceeds
  186.          to the next line in the program.
  187.  
  188.          A line number may be used after either THEN or ELSE, for an
  189.          implied GOTO statement.
  190.  
  191.  
  192.       END
  193.  
  194.          Terminate the program.  An END statement is not required.
  195.  
  196.  
  197.       STOP
  198.  
  199.          Terminate the program with an identifying "Break" message.
  200.  
  201.  
  202.       FOR var = first TO last [STEP inc]
  203.       {statements}
  204.       NEXT [var]
  205.  
  206.          Execute {statements} repeatedly while the variable counts from
  207.          "first" to "last," incrementing by 1, or by the STEP value if
  208.          given.  If the STEP value is negative, the variable counts
  209.          downward.
  210.  
  211.          If "first" is greater than "last" (or less than if STEP is
  212.          negative), execution proceeds directly to the NEXT statement,
  213.          without executing the body of the loop at all.
  214.  
  215.          The variable name is optional on the NEXT statement.
  216.  
  217.  
  218.       WHILE [condition]
  219.       {statements}
  220.       WEND [condition]
  221.  
  222.          Execute {statements} repeatedly until the WHILE condition (if
  223.          given) becomes false, or until the WEND condition becomes true.
  224.          This structure can emulate Pascal's WHILE-DO and REPEAT-UNTIL,
  225.          or even both at once.  If no conditions are given, the loop will
  226.          never terminate unless the Evil GOTO is used.
  227.  
  228.  
  229.       GOSUB line
  230.       RETURN
  231.  
  232.          Execute the statements beginning at the specified line, then
  233.          when RETURN is reached, return to the statement following the 
  234.          GOSUB.
  235.  
  236.  
  237.       READ vars
  238.       DATA values
  239.       RESTORE line
  240.  
  241.          Read numeric or string values from the DATA statements.  Reading
  242.          begins at the first DATA statement in the program and proceeds
  243.          to the last.  Reading past the end the last DATA statement
  244.          generates an error.
  245.  
  246.          The DATA values must be either numeric or string expressions,
  247.          according to the type of variable being read.  Reading the wrong
  248.          kind of expression produces a Syntax Error.
  249.  
  250.          The RESTORE statement causes the next READ to re-use the first
  251.          DATA statement in the program, or the first DATA statement on
  252.          or after a particular line.
  253.  
  254.  
  255.       GOTOXY across, down
  256.  
  257.          Move the cursor to the specified screen position, between
  258.          0,0 and 79,23.
  259.  
  260.  
  261.       ON expr GOTO line, line, ...
  262.       ON expr GOSUB line, line, ...
  263.  
  264.          If the expression's value, rounded to an integer, is N, go to
  265.          the Nth line number in the list.  If N is less than one or is
  266.          too large, execution continues at the next statement after
  267.          the ON-GOTO or ON-GOSUB.
  268.  
  269.  
  270.       POKE addr, data
  271.  
  272.          Store a byte at the specified address.
  273.  
  274.  
  275.  
  276.  
  277.    NUMERIC EXPRESSIONS
  278.  
  279.       x AND y
  280.  
  281.          Logical AND of two integers.
  282.  
  283.  
  284.       x OR y
  285.  
  286.          Logical OR of two integers.
  287.  
  288.  
  289.       x XOR y
  290.  
  291.          Logical XOR of two integers.
  292.  
  293.  
  294.       NOT x
  295.  
  296.          Logical complement of an integer.
  297.  
  298.  
  299.       x+y, x-y, x*y, x/y, x^y, -x
  300.  
  301.          Typical floating-point arithmetic operations.
  302.  
  303.  
  304.       x=y, x<y, x>y, x<=y, x>=y, x<>y
  305.  
  306.          Comparisons; result is 1 if true, 0 if false.
  307.  
  308.  
  309.       x MOD y
  310.  
  311.          Modulo of two integers.
  312.  
  313.  
  314.       SQR x
  315.  
  316.          Square of X.  Note that parentheses are not required if a function's
  317.          argument is a single entitity; for example, SQR SIN X needs no
  318.          parentheses, but SQR(1+X) does.
  319.  
  320.  
  321.       SQRT x
  322.  
  323.          Square root of X.
  324.  
  325.  
  326.       SIN x, COS x, TAN x, ARCTAN x
  327.  
  328.          Typical trig functions, in radians.
  329.  
  330.  
  331.       LOG x, EXP x
  332.  
  333.          Natural logarithm, and e the power X.
  334.  
  335.  
  336.       ABS x
  337.  
  338.          Absolute value of X.
  339.  
  340.  
  341.       SGN x
  342.  
  343.          Sign of X:  1 if X is positive, 0 if zero, -1 if negative.
  344.  
  345.  
  346.       VAL x$
  347.  
  348.          Value of the expression contained in the string X$.  For example,
  349.          VAL "1+2" yields 3.  X$ may be a single string literal, variable,
  350.          or function, or a string expression in parentheses.
  351.  
  352.  
  353.       ASC x$
  354.  
  355.          ASCII code of the first character in X$, or 0 if X$ is null.
  356.  
  357.  
  358.       LEN x$
  359.  
  360.          Number of characters in X$.
  361.  
  362.  
  363.       Precedence:      Parentheses
  364.                         Functions  (incl. NOT and unary minus)
  365.                             ^
  366.                         *, /, MOD
  367.                           +, -
  368.                    =, <, >, <=, >=, <>
  369.                            AND
  370.                          OR, XOR
  371.  
  372.  
  373.  
  374.    STRING EXPRESSIONS
  375.  
  376.       "string" or 'string'
  377.  
  378.          String literal.  Single quotes are converted to double quotes
  379.          internally.
  380.  
  381.  
  382.       x$+y$
  383.  
  384.          Concatenation.  Result must be 255 characters or less.
  385.  
  386.  
  387.       x$=y$, x$<y$, x$>y$, x$<=y$, x$>=y$, x$<>y$
  388.  
  389.          String comparisons; result is 1 if true, 0 if false.
  390.  
  391.  
  392.       STR$(x)
  393.  
  394.          The number X expressed as a string of digits.  No leading or
  395.          trailing spaces are included; scientific notation is used
  396.          if the absolute values is greater than 1E12 or less than 1E-2.
  397.  
  398.  
  399.       CHR$(x)
  400.  
  401.          The character whose ASCII code is X.
  402.  
  403.  
  404.       MID$(x$, y)
  405.       MID$(x$, y, z)
  406.  
  407.          (Parentheses required.)  The substring consisting of the first
  408.          Z characters starting at position Y of string X$.  Position 1
  409.          is the first character of the string.  If Z is omitted, 255
  410.          is used, i.e., the entire right part of the string.
  411.  
  412.  
  413.  
  414.    CONVENTIONS
  415.  
  416.       Multiple statements may be written on a line, separated by colons:
  417.  
  418.             10 INPUT X : PRINT X : STOP
  419.  
  420.  
  421.       There is actually no difference between commands and statements;
  422.       both can be used in or out of programs at will.  Certain commands,
  423.       such as NEW, will, of course, halt program execution.
  424.  
  425.  
  426.       Line numbers may be any integer from 1 to MAXINT.
  427.  
  428.  
  429.       To delete a line use DEL, or type its line number alone:
  430.  
  431.             10
  432.  
  433.  
  434.       Press CLR I/O to halt program execution.  [This is not supported
  435.       by p2c's translation!]  To leave BASIC, use the BYE command.
  436.  
  437.  
  438.       Keywords must be written in all upper- or all lower-case; they are
  439.       always converted to upper-case internally.  Spaces are ignored in
  440.       the input except between quotes.  Square brackets are converted to
  441.       parentheses.  Missing closing quotes at the end of the line are
  442.       added, as in the command:
  443.  
  444.             SAVE "PROGRAM
  445.  
  446.  
  447.  
  448.  
  449.