Previous: uttepp Up: ../plot79_u.html Next: uttik


UTTEXP

       SUBROUTINE  UTTEXP (ERRCDE,LOCERR, VTYPE,V,NV,MAXV,
      X     SOURCE,LOC,LENGTH)
 C$    (Expression Evaluation)
 C$    This routine provides for the evaluation of general numeric
 C$    vector expressions,  or comma-separated  vector  expression
 C$    lists, passed as  a packed  Hollerith string.   It will  be
 C$    particularly useful  for  the  parsing  and  evaluation  of
 C$    expressions in an  input language, and  could be  trivially
 C$    used to implement a desk calculator.
 C$
 C$    Assignment   operators   are   included,   permitting   the
 C$    definition of symbolic  values which can  be used in  later
 C$    expressions  in  the  same  or  successive  calls  to  this
 C$    routine.   This  feature  uses  the  symbol  table  support
 C$    routines UTTSIN, UTTSLI, and UTTSLN, and the dynamic memory
 C$    management stack allocation routines from the PORT  Library
 C$    Framework.  Thus, in order to use this routine, the  symbol
 C$    table must  be initialized  by a  call to  UTTS00, and  the
 C$    stack allocation system should be initialized by a call  to
 C$    ISTKIN.  The  default  internal  stack  size  in  the  PORT
 C$    Library package of  500 double  words is  adequate for  the
 C$    definition of about 25 symbolic names, so it may have to be
 C$    increased.  A sample initialization sequence is as follows.
 C$
 C$    INTEGER UTTS00
 C$    COMMON / CSTAK / DSTAK(2500)
 C$    ...
 C$    CALL ISTKIN (2500,4)
 C$    MAXKEY = 100
 C$    NAVAIL = UTTS00 (MAXKEY,1)
 C$    CALL UTTEXP (...)
 C$
 C$    The output arguments are:
 C$
 C$    ERRCDE.........INTEGER error  code.    Because of the large
 C$                   number of  error codes,  a support  utility,
 C$                   UTTEMS, is  provided to  type a  descriptive
 C$                   message and flag  the point  of error.   The
 C$                   possible values of ERRCDE are
 C$                   0  - no error,
 C$                   1  - wrong number of function arguments,
 C$                   2  - incomplete expression,
 C$                   3  - illegal name token,
 C$                   4  - empty string - no expression found,
 C$                   5  - illegal number format,
 C$                   6  - internal error - stack overflow;
 C$                        expression may be too complex for
 C$                        preset stack depth,
 C$                   7  - illegal operator,
 C$                   8  - illegal adjacent operators or operands
 C$                   9  - unbalanced parentheses,
 C$                  10  - internal error - stack underflow.
 C$                  11  - assignment failed because symbol table
 C$                        full.
 C$                  12  - internal error - operator table not in
 C$                        order.
 C$                  13  - undefined variable used in expression.
 C$                  14  - illegal assignment to non-variable.
 C$                  15  - internal error - stack or symbol table
 C$                        corrupt.
 C$                  16  - wrong number of subscripts
 C$                  17  - subscript out of range
 C$                  18  - illegal argument type or size
 C$    LOCERR.........Approximate character position in SOURCE(*)
 C$                   where  an  error   was  detected;  it   will
 C$                   normally point to the beginning of the token
 C$                   causing the error.  On a successful  return,
 C$                   it will point past the last character in the
 C$                   string.
 C$    VTYPE(*).......INTEGER array of value  types returned (1  =
 C$                   Boolean, 2 = Integer,  4 = Double  Precision
 C$                   Floating  Point,  15  =  undefined).   These
 C$                   values are  the same  as those  used by  the
 C$                   PORT Library stack allocation routines.
 C$    V(*)...........DOUBLE PRECISION array of values returned.
 C$    NV.............Number of values returned in V(*).
 C$
 C$    The input arguments are:
 C$
 C$    MAXV...........Dimension of V(*).  If NV > MAXV on  return,
 C$                   insufficient storage was available, and only
 C$                   MAXV values have been stored.
 C$    SOURCE(*)......Packed    Hollerith    string     containing
 C$                   expression to evaluate.  Letter case is  NOT
 C$                   significant.    White    space    characters
 C$                   (blanks,  tabs,   and  control   characters)
 C$                   embedded in  tokens  are  ILLEGAL,  but  may
 C$                   be freely  used  between tokens  to  improve
 C$                   readability.
 C$    LOC............Starting  position  (1,2,3...) in SOURCE(*).
 C$    LENGTH.........Number  of  characters  in  SOURCE(*)  (i.e.
 C$                   positions  LOC  ..   LOC+LENGTH-1  will   be
 C$                   examined).
 C$
 C$    Numeric literals containing a decimal point and/or followed
 C$    by a power-of-ten exponent  (D+nn, D-nn, E+nn, E-nn,  Q+nn,
 C$    Q-nn)  are  treated  as  double  precision   floating-point
 C$    values; otherwise they are  treated as integer values.   By
 C$    analogy with  Ada,  but  choosing  a  quote  delimiter  (')
 C$    instead of a number sign (#) delimiter, which is used as  a
 C$    "not-equal" operator, numbers with bases other than 10  are
 C$    represented by  constants  of the  form  bb'<integer>'  and
 C$    bb'<floating>', where bb is a DECIMAL integer defining  the
 C$    base (in the range 2..16), and the value inside the  quotes
 C$    is a number  in that base.   Digits in bases  11 .. 16  are
 C$    represented by letters A through F, and letter case is  NOT
 C$    significant.  For bases larger than 12, Q should be used as
 C$    the  exponent  letter  to  distinguish  it  from  a   digit
 C$    character.  Examples  are 2'101'  (=  5), 8'777'  (=  511),
 C$    2'-11' (= -3), 16'f3'  (= 243), and  16'1Q3' (= 16'1000'  =
 C$    4096.0).
 C$
 C$    Named literals must  begin with  a letter  and may  contain
 C$    letters, digits, underscore,  and period.   Letter case  is
 C$    NOT significant.  Names are looked up first in the function
 C$    name table, and  if not found  there, then in the  variable
 C$    name table.   Thus,  all  function  names  are  effectively
 C$    reserved words, and  attempts to assign  values to them  or
 C$    use them  as  scalar  variables will  result  in  an  error
 C$    return.
 C$
 C$    This reservation of some names is required because size and
 C$    type declarations of  variables are not  required; when  an
 C$    unknown name is  encountered, it  is automatically  entered
 C$    into the symbol table with a flag marking it as  undefined.
 C$    Immediate symbol  table installation  is necessary  because
 C$    this parser requires no lookahead at all, and the use of  a
 C$    variable on the left-hand side  of an assignment cannot  be
 C$    recognized until possibly many more tokens have been parsed
 C$    (e.g.  "V(verylongsubscriptexpression)  =  value").   Thus,
 C$    variables  come  into  existence  when  they  are  assigned
 C$    values,  and  disappear  only  when  the  symbol  table  is
 C$    reinitialized.
 C$
 C$    Binary operators