3/15/72                                                   BAS (I)





NAME            bas -- basic



SYNOPSIS        bas [ file ]



DESCRIPTION     bas is a dialect of basic [1].  If a file argu-

                ment is provided, the file is used for input be-

                fore the console is read.



                bas accepts lines of the form:



                   statement

                   integer statement



                Integer numbered statements (known as internal

                statements) are stored for later execution.  They

                are stored in sorted ascending order.  Non-

                numbered statements are immediately executed.

                The result of an immediate expression statement

                (that does not have '=' as its highest operator)

                is printed.



                Statements have the following syntax: (expr is

                short for expression)



                   expr

                      The expression is executed for its side ef-

                      fects (assignment or function call) or for

                      printing as described above.



                   done

                      Return to system level.



                   for name = expr expr statement

                   for name = expr expr

                      ...

                   next

                      The for statement repetitively executes a

                      statement (first form) or a group of state-

                      ments (second form) under control of a

                      named variable.  The variable takes on the

                      value of the first expression, then is in-

                      cremented by one on each loop, not to ex-

                      ceed the value of the second expression.



                   goto expr

                      The expression is evaluated, truncated to

                      an integer and execution goes to the corre-

                      sponding integer numbered statment.  If ex-

                      ecuted from immediate mode, the internal

                      statements are compiled first.



                   if expr statement

                      The statement is executed if the expression

                      evaluates to non-zero.



                   list [expr [expr]]

                      list is used to print out the stored inter-

                      nal statements.  If no arguments are given,

                      all internal statements are printed.  If

                      one argument is given, only that internal

                      statement is listed.  If two arguments are

                      given, all internal statements inclusively

                      between the arguments are printed.



                   print expr

                      The expression is evaluated and printed.



                   return [expr]

                      The expression is evaluated and the result

                      is passed back as the value of a function

                      call.



                   run

                      The internal statements are compiled.  The

                      symbol table is re-initialized.  The random

                      number generator is re-set.  Control is

                      passed to the lowest numbered internal

                      statement.



                Expressions have the following syntax:



                   name

                      A name is used to specify a variable.

                      Names are composed of a letter ('a' - 'z')

                      followed by letters and digits.  The first

                      four characters of a name are significant.



                   number

                      A number is used to represent a constant

                      value.  A number is composed of digits, at

                      most one decimal point ('.')  and possibly

                      a scale factor of the form e digits or e-

                      digits.



                   ( expr )

                      Parentheses are used to alter normal order

                      of evaluation.



                   expr op expr

                      Common functions of two arguments are ab-

                      breviated by the two arguments separated by

                      an operator denoting the function.  A com-

                      plete list of operators is given below.



                   expr ( [expr [, expr ...]] )

                      Functions of an arbitrary number of argu-

                      ments can be called by an expression fol-

                      lowed by the arguments in parentheses sepa-

                      rated by commas.  The expression evaluates

                      to the line number of the entry of the

                      function in the internally stored state-

                      ments.  This causes the internal statements

                      to be compiled.  If the expression evalu-

                      ates negative, a builtin function is

                      called.  The list of builtin functions ap-

                      pears below.



                   name [ expr [, expr ...] ]

                      Arrays are not yet implemented.



                The following is the list of operators:



                   =

                      = is the assignment operator.  The left

                      operand must be a name or an array element.

                      The result is the right operand.  Assign-

                      ment binds right to left, all other opera-

                      tors bind left to right.



                   & |

                      & (logical and) has result zero if either

                      of its arguments are zero.  It has result

                      one if both its arguments are non-zero.  |

                      (logical or) has result zero if both of its

                      arguments are zero.  It has result one if

                      either of its arguments are non-zero.



                   < <= > >= == <>

                      The relational operators (< less than, <=

                      less than or equal, > greater than, >=

                      greater than or equal, == equal to, <> not

                      equal to) return one if their arguments are

                      in the specified relation.  They return

                      zero otherwise.  Relational operators at

                      the same level extend as follows: a>b>c is

                      the same as a>b&b>c.



                   + -

                      Add and subtract.



                   * /

                      Multiply and divide.



                   ^

                      Exponentiation.



                The following is a list of builtin functions:



                   arg

                      Arg(i) is the value of the ith actual pa-

                      rameter on the current level of function

                      call.



                   exp

                      Exp(x) is the exponential function of x.



                   log

                      Log(x) is the logarithm base e of x.



                   sin

                      Sin(x) is the sine of x (radians).



                   cos

                      Cos(x) is the cosine of x (radians).



                   atn

                      Atn(x) is the arctangent of x.  (Not imple-

                      mented.)



                   rnd

                      Rnd() is a uniformly distributed random

                      number between zero and one.



                   expr

                      Expr() is the only form of program input.

                      A line is read from the input and evaluated

                      as an expression.  The resultant value is

                      returned.



                   int

                      Int(x) returns x truncated to an integer.



FILES           /tmp/btm?       temporary



SEE ALSO        [1] DEC-11-AJPB-D



DIAGNOSTICS     Syntax errors cause the incorrect line to be

                typed with an underscore where the parse failed.

                All other diagnostics are self explanatory.



BUGS            Arrays [] are not yet implemented.  In general,

                program sizes, recursion, etc are not checked,

                and cause trouble.



OWNER           ken