Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ bs(1) — AIX PS/2 1.2.1

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

ed, red

sh, Rsh

access

printf subroutine

the plot



BS(1,C)                     AIX Commands Reference                      BS(1,C)



-------------------------------------------------------------------------------
bs



PURPOSE

Compiles and interprets modest-size programs.

SYNTAX


      +-----------------------+
bs ---|        +------------+ |---|
      +- file -|            |-+
               +--- flag ---+
                 ^        |
                 +--------+


Note:  This command does not have MBCS support.

DESCRIPTION

This compiler/interpreter provides interactive program development and
debugging.  To simplify program testing, it minimizes formal data declaration
and file manipulation, allows line-at-a-time debugging, and provides trace and
dump facilities and run-time error messages.

The optional command line parameter file specifies a file of program statements
that the compiler reads before it reads from the standard input.  By default,
statements read from this file are compiled for later execution.  Likewise,
statements entered from the standard input are normally executed immediately
(see the compile keyword on page         2 and the execute keyword on page
        2).  Unless the final operation is assignment, the result of an
immediate expression statement is displayed.

Additional command line flags can be passed to the program using the built-in
functions arg and narg (explained in more detail on page         7).

Program lines must conform to one of the following formats:

    statement
    label statement

The bs interpreter accepts labeled statements only when it is compiling
statements.  A label is a name immediately followed by a colon.  A label and a
variable can have the same name.  If the last character of a line is a \
(backslash), the statement continues on the following physical line.

A statement consists of either an expression or a keyword followed by zero or
more expressions.



Processed November 8, 1990          BS(1,C)                                   1





BS(1,C)                     AIX Commands Reference                      BS(1,C)




Statement Syntax

break          Exits the innermost for or while loop.

clear          Clears the symbol table and removes compiled statements from
               memory.  A clear statement is always executed immediately.

compile  [expr]
               Causes succeeding statements to be compiled (overrides the
               immediate execution default).  The optional expression is
               evaluated and used as a file name for further input.  In this
               latter case, the symbol table and memory are cleared first.  A
               compile statement is always executed immediately.

continue       Transfers control to the loop-continuation test of the current
               for or while loop.

dump [name]    Displays the name and current value of every global variable or,
               optionally, of the named variable.  After an error or interrupt,
               a dump statement displays the number of the last statement and
               (possibly) the user-function trace.

exit  [expr]   Returns to the system level.  The expression is returned as
               process status.

execute        Changes to immediate execution mode (pressing the INTERRUPT
               [Ctrl-C] key has the same effect).  This statement does not
               cause stored statements to execute (see run on page         4).

for name=expr expr statement


for name=expr expr


   statement...


next

for expr, expr, expr statement


for expr, expr, expr


   statement...







Processed November 8, 1990          BS(1,C)                                   2





BS(1,C)                     AIX Commands Reference                      BS(1,C)



next           Repetitively performs, under the control of a named variable, a
               statement (first format) or a group of statements (second
               format).  The variable takes on the value of the first
               expression, and is then increased by one on each loop until its
               value exceeds the value of the second expression.  The third and
               fourth formats require three expressions separated by commas.
               The first of these is the initialization, the second is the test
               (true to continue), and the third is the loop-continuation
               action.

fun f ([a,...]) [v,...]


  statement...

nuf            Defines the function name (f), parameters (a), and local
               variables (v) for a user-written function.  Up to 10 parameters
               and local variables are allowed.  Such names cannot be arrays,
               nor can they be I/O associated.  Function definitions can not be
               nested.

freturn        Signals the failure of a user-written function.  Without
               interrogation, the freturn statement returns zero.  (See the
               unary interrogation operator ? discussed on page         6.)
               With interrogation, the freturn statement transfers to the
               interrogated expression, possibly bypassing intermediate
               function returns.

goto  name     Passes control to the compiled statement with the matching
               label.

ibase  n       Sets the input base to n.  The only supported values for n are
               8, 10 (the default), and 16.  Hexadecimal values 10-15 are
               printed as alphabetic characters a-f.  An ibase statement is
               always executed immediately.

if expr statement


if  expr

   statement...


[else

   statement...]


fi             Performs a statement (first format) or group of statements
               (second format) if the expression evaluates to nonzero.  The
               strings 0 and "" (null) evaluate as zero.  In the second format,



Processed November 8, 1990          BS(1,C)                                   3





BS(1,C)                     AIX Commands Reference                      BS(1,C)



               an optional else statement allows a group of statements to be
               performed when the first group is not.  The only statement
               permitted on the same line with an else statement is an if
               statement; only other fi statements can be on the same line with
               an fi statement.  You can combine an else and an if statement
               into an elif statement.  Only a single fi statement is required
               to close an if...elif...[else...] sequence.

include  expr  The expression must evaluate to the name of a file containing
               program statements.  Such statements become part of the program
               being compiled.  An include statement may not be nested, and is
               always executed immediately.

obase  n       Sets the output base to n.  The only supported values for n are
               8, 10 (the default), and 16.  Hexadecimal values 10-15 are
               entered as alphabetic characters a-f.  A leading digit is
               required when a hexadecimal number begins with an alphabetic
               character (that is, "f0a" must be entered as "0f0a").  Like an
               ibase statement, an obase statement is always executed
               immediately.

onintr  label

onintr         Provides program control of interrupts.  In the first format,
               control passes to the label given, just as if a goto had been
               performed when the onintr statement was executed.  The effect of
               the onintr statement is cleared after each interrupt.  In the
               second format, pressing the INTERRUPT (Ctrl-C) key ends the bs
               command.

return  [expr] Evaluates the expression and passes the result back as the value
               of a function call.  If you do not provide an expression, the
               function returns zero.

run            Passes control to the first compiled statement.  The random
               number generator is reset.  If a file contains a run statement,
               it should be the last statement; a run statement is always
               executed immediately.

stop           Stops execution of compiled statements and returns to immediate
               mode.

trace  [expr]  Controls function tracing.  If you do not provide an expression
               or if it evaluates to zero, tracing is turned off.  Otherwise, a
               record of user-function calls/returns is written.  Each return
               decreases by one the trace statement expression value.

while  expr statement


while  expr




Processed November 8, 1990          BS(1,C)                                   4





BS(1,C)                     AIX Commands Reference                      BS(1,C)



   statement...


next           A while statement is similar to a for statement except that only
               the conditional expression for loop continuation is given.

!  AIXcmd      Runs an AIX command, then returns control to the bs command.

#comment       Inserts a comment line.

Expression Syntax

name                  Specifies a variable or, when followed immediately by a
                      colon, a label.  Names are composed of a letter
                      (uppercase or lowercase) optionally followed by letters
                      and digits.  Only the first six characters of a name are
                      significant.  Except for names declared locally in fun
                      statements, all names are global.  Names can take on
                      numeric (double float) values or string values or be
                      associated with input/output (see the built-in function
                      open on page         10).

name([expr[, expr]...)
                      Calls function name and passes to it the parameters in
                      parentheses.  Except for built-in functions (listed in
                      the following text), name must be defined in a fun
                      statement.  Function parameters are passed by value.

name[expr[, expr]...] References either arrays or tables (see built-in function
                      table on page         10).  For arrays, each expression
                      is truncated to an integer and used as a specifier for
                      the name.  The resulting array reference is syntactically
                      identical to a name; "a[1,2]" is the same as "a[1][2]".
                      The truncated expressions must be values between 0 and
                      32767.

number                Represents a constant numerical value.  This number can
                      be expressed in integer, decimal, or scientific notation
                      (it can contain digits, an optional decimal point, and an
                      optional e followed by a possibly signed exponent).

string                Character string delimited by " " (double quotation
                      marks).  The \ (backslash) is an escape character that
                      allows the double quotation mark (\"), new-line character
                      (\n), carriage return (\r), backspace (\b), and tab (\t)
                      characters to appear in a string.  When not immediately
                      followed by these special characters, \ stands for
                      itself.

(expr)                Parentheses alter the normal order of evaluation.





Processed November 8, 1990          BS(1,C)                                   5





BS(1,C)                     AIX Commands Reference                      BS(1,C)



(expr, expr[,  expr]...) [expr]
                      The bracketed expression outside the parentheses
                      functions as a subscript to the list of expressions
                      within the parentheses.  List elements are numbered from
                      the left, starting at zero.  The expression:

                        (False, True) [ a == b ]

                      has the value True if the comparison is true.

expr  op  expr        Except for the assignment, concatenation, and relational
                      operators, both operands are converted to numeric form
                      before the operator is applied.

Unary Operators

?expr                 The interrogation operator ("?") tests for the success of
                      the expression rather than its value.  It is useful for
                      testing end of file, for testing the result of the eval
                      built-in function, and for checking the return from
                      user-written functions (see freturn on page         3).
                      An interrogation trap ( end of file, for example), causes
                      an immediate transfer to the most recent interrogation,
                      possibly skipping assignment statements or intervening
                      function levels.

-expr                 Negates the expression.

++name                Increases by one the value of the variable (or array
                      reference).

--name                Decreases by one the value of the variable.

!expr                 The logical negation of the expression.

Binary Operators (in increasing precedence)

=                     The assignment operator.  The left operand must be a name
                      or an array element.  It acquires the value of the right
                      operand.  The assignment operator binds right to left;
                      all other operators bind left to right.

_                     The concatenation operator (the underline character).

&  |                  Logical AND operator and logical OR operator.  The result
                      of the following:

                         expr & expr

                      is 1 (true) only if both of its parameters are nonzero
                      (true); the result is 0 (false) if one or both of its
                      parameters are 0 (false).



Processed November 8, 1990          BS(1,C)                                   6





BS(1,C)                     AIX Commands Reference                      BS(1,C)




                      The result of this:

                         expr | expr

                      is 1 (true) if one or both of its expressions are nonzero
                      (true); the result is 0 (false) only if both of its
                      expressions are 0 (false).  Both operators treat a null
                      string as a zero.

<  <=  >  >=  ==  !=  The relational operators (< less than; <= less than or
                      equal to; > greater than; >= greater than or equal to; ==
                      equal to, != not equal to) return 1 if the specified
                      relation is true.  They return 0 (false) otherwise.
                      Relational operators at the same level extend as follows:
                      a>b>c is the same as a>b & b>c.  A string comparison is
                      made if both operands are strings.  The comparison is
                      based on the collating sequence specified in the
                      environment variables LANG and LC_COLLATE.

+  -                  Addition and subtraction operators.

*  /  %               Multiplication, division, and remainder operators.

^                     Exponentiation operator.

Functions Dealing With Arguments

arg(i)                Returns the value of the i-th actual argument at the
                      current function call level.  At level zero, arg returns
                      the i-th command-line argument.  For example, arg(0)
                      returns "bs".

narg( )               Returns the number of arguments passed.  At level zero,
                      it returns the command line argument count.

Mathematical Functions

abs(x)                Returns the absolute value of x.

atan(x)               Returns the arctangent of x.

ceil(x)               Returns the smallest integer not less than x.

cos(x)                Returns the cosine of x.

exp(x)                Returns e raised to the power x.

floor(x)              Returns the largest integer not greater than x.

log(x)                Returns the natural logarithm of x.




Processed November 8, 1990          BS(1,C)                                   7





BS(1,C)                     AIX Commands Reference                      BS(1,C)



rand( )               Returns a uniformly distributed random number between
                      zero and one.

sin(x)                Returns the sine of x.

sqrt(x)               Returns the square root of x.

String Functions

size(s)               Returns the size (length in bytes) of s.

format(f, a)          Returns the formatted value of a, f being a format
                      specification string in the style of the printf
                      subroutine.  Use only the %...f, %...e, and %...s
                      formats.

index(x, y)           Returns a number that is the first position in x
                      containing a character that any of the characters in y
                      matches.  If there is no match, the index function yields
                      zero.  For two-byte extended characters, the index
                      function returns the location of the first byte.

trans(s, f, t)        Translates characters in the source string s which match
                      characters in f with characters having the same position
                      in t.  Source characters that do not appear in f are
                      copied unchanged into the translated string.  If string f
                      is longer than t, source characters that match characters
                      found in the excess portion of f do not appear in the
                      translated string.

subst(s, start, length)
                      Returns the substring of s defined by starting position
                      and length.

match(string, pattern)


mstring(n)            This function returns the number of characters in string
                      that match pattern.  The characters ., "*", "?" [, ], ^
                      (when inside square brackets), \( and \) have the
                      following special meanings (see "ed, red" for a more
                      detailed discussion of this special notation):

                      .      Matches any character except the new-line
                             character.

                      *      Matches zero or more occurrences of the pattern
                             element that it follows (for example, ".*" matches
                             zero or more occurrences of any character except
                             the new-line character).

                      $      Specifies the end of the line.



Processed November 8, 1990          BS(1,C)                                   8





BS(1,C)                     AIX Commands Reference                      BS(1,C)




                      [.-.]

                      [...]  Matches any one character in the specified range
                             ([.-.]) or list ([...]), including the first and
                             last characters.

                      [^.-.]

                      [^...] Matches any character except the new-line
                             character and the remaining characters in the
                             range or list.  A circumflex (^) has this special
                             meaning only when it immediately follows the left
                             bracket.

                      [].-.]

                      []...] Matches ] or any character in the list.  The right
                             square bracket does not terminate such a list when
                             it is the first character within the list (after
                             an initial ^, if any).

                      \(...\)
                             Marks a substring and matches it exactly.

                      To succeed, a pattern must match from the beginning of
                      the string.  It also matches the longest possible string.
                      Consider, for example:

                        match('a123ab123',".*\([a-z]\)") == 6

                      In this instance, ".*" matches "a123a" (the longest
                      string that precedes a character in the range a-z);
                      "\([a-z]\)" matches "b", giving a total of six characters
                      matched in the string.  In an expression such as [a-z],
                      the minus means "through" according to the current
                      collating sequence.  A collating sequence may define
                      equivalence classes for use in character ranges.  See
                      "Introduction to International Character Support" in
                      Managing the AIX Operating System for more information on
                      collating sequences and equivalence classes.

                      Note:  If you have selected a specific locale (using
                             either the LANG or LC_COLLATE environment
                             variable), it may not be possible to specify an
                             equivalence class of characters using a range
                             expression.  In such cases, use a character class
                             expression rather than a standard range
                             expression.  For information about character class
                             expressions, see the note on page ed-3 under
                             the ed, red command.




Processed November 8, 1990          BS(1,C)                                   9





BS(1,C)                     AIX Commands Reference                      BS(1,C)



                      The mstring function returns the nth substring in the
                      last call to match (n must be between 1 and 10
                      inclusive).

File-Handling Functions

open(name, file, mode)


close(name)           The name parameter must be a legal variable name (passed
                      as a string).  For the open function, the file parameter
                      may be:

                        o A 0, 1, or 2 for standard input, output, or error
                          output, respectively
                        o A string representing a file name
                        o A string beginning with an !, representing a command
                          to be run (via the sh -c) command.

                      The mode flag must be either r (read), w (write), W
                      (write without new-line character), or a (append).  After
                      a close function, the name becomes an ordinary variable.
                      The initial associations are:

                        open("get", 0, "r")
                        open("put", 1, "w")
                        open("puterr", 2, "w")

access(p, m)          Performs the access system call.  Parameter p is the path
                      name of a file; m is a bit pattern representing the
                      requested mode of access.  This function returns a 0 if
                      the request is permitted and -1 if it is denied.  (See
                      AIX Operating System Technical Reference for an extensive
                      discussion of this system call.)

ftype(s)              Returns a single character indicating file type:  f for
                      regular file, p for FIFO (named pipe), d for directory, b
                      for block special, or c for character special.

Table Functions

table(name, size)     A table in the bs compiler is an associatively accessed,
                      one-dimensional array.  Subscripts (called keys) are
                      strings (numbers are converted).  The name parameter must
                      be a bs variable name (passed as a string).  The size
                      parameter sets the minimum number of elements to be
                      allocated.  On table overflow, the bs compiler writes an
                      error message.

item(name, i)





Processed November 8, 1990          BS(1,C)                                  10





BS(1,C)                     AIX Commands Reference                      BS(1,C)



key( )                The item function accesses table elements sequentially
                      (in normal use, there is an orderly progression of key
                      values).  Where the item function accesses values, the
                      key function accesses the subscript of the previous item
                      call.  The name parameter should not be quoted.  Since
                      exact table sizes are not defined, the interrogation
                      operator should be used to detect end-of-table; for
                      example:

                        table("t",100)
                        .
                        .
                        .
                        #If word contains "party", the following expression
                        #adds one to the count of that word:
                        ++t[word]
                        .
                        .
                        .
                        # To display the key/value pairs:
                        for i=0, ?(s=item(t, i)), ++i if key() put=key()_":"_s

iskey(name, word)     Tests whether the key word exists in the table name and
                      returns 1 for true or 0 for false.

Miscellaneous Functions

eval(string)          The string parameter is evaluated as an expression.  The
                      function is handy for converting numeric strings to
                      numbers.  The eval function can also be used as a crude
                      form of indirection, as in:

                        name = "xyz"
                        eval("++"_name)

                      which increments the variable "xyz".

                      In addition, eval preceded by the interrogation operator
                      permits you to control bs compiler error conditions.  For
                      example:

                        ?eval("open(\"X\",\"XXX\", \"r\")")

                      returns the value 0 if there is no file named ""XXX""
                      (instead of halting your program).  The following
                      performs a goto to the label "L:" (if it exists):

                        label="L:"
                        if!(?eval("goto"_label))puterr="no label"






Processed November 8, 1990          BS(1,C)                                  11





BS(1,C)                     AIX Commands Reference                      BS(1,C)



plot(request, args)   The plot function produces output on devices recognized
                      by the tplot command.  Some requests do not apply to all
                      plotters.  All requests except 0 and 12 are implemented
                      by piping characters to the tplot command.  The requests
                      are as follows:

                      Requests          Function

                      plot(0, term)     Causes further plot output to be piped
                                        into the tplot command with a flag of
                                        -Tterm.

                      plot(1)           "Erases" the plotter.

                      plot (2, string)  Labels the current point with string.

                      plot(3, x1, y1, x2, y2)
                                        Draws a line between (x1, y1) and (x2,
                                        y2).

                      plot(4, x, y, r)  Draws a circle with center (x, y) and
                                        radius r.

                      plot(5, x1, y1, x2, y2, x3, y3)
                                        Draws an arc (counterclockwise) with
                                        center (x1, y1) and endpoints (x2, y2)
                                        and (x3, y3).

                      plot(6)           Not implemented.

                      plot(7, x, y)     Makes the current point at (x, y).

                      plot(8, x, y)     Draws a line from the current point to
                                        (x, y).

                      plot(9, x, y)     Draws a point at (x, y).

                      plot(10, string)  Sets the line mode to string.

                      plot(11, x1, y1, x2, y2)
                                        Makes (x1, y1) the lower left corner of
                                        the plotting area and (x2, y2) the
                                        upper right corner of the plotting
                                        area.











Processed November 8, 1990          BS(1,C)                                  12





BS(1,C)                     AIX Commands Reference                      BS(1,C)



                      Requests          Function

                      plot(12, x1, y1, x2, y2)
                                        Causes subsequent x (y) coordinates to
                                        be multiplied by x1 (y1) and then added
                                        to x2 (y2) before they are plotted.
                                        The initial scaling is plot(12, 1.0,
                                        1.0, 0.0, 0.0).

last()                In immediate mode, the last function returns the most
                      recently computed value.

RELATED INFORMATION

See the following commands:  "ed, red" and "sh, Rsh."

See the access system call, the printf subroutine, and the plot file in AIX
Operating System Technical Reference.





































Processed November 8, 1990          BS(1,C)                                  13



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026