Version 3.0.0:Use at your own risk.
The JUEXPR(3f) library evaluates
CHARACTER strings containing FORTRAN-like expressions and returns
numeric and string values.
It supports named variables and most ANSI FORTRAN 77 functions.
- juexpr.f is the library code
- simple.f is a very simple example that calls the convenience function RNUM0(3f)
- mycalc.f is an example that calls the main routine JUEXPR(3f)
f77 juexpr.f mycalc.f -o mycalc
Using the JUEXPR(3f) interface it is easy to make free-format and
order-independent input interfaces where values can be expressions
and variable names instead of simple numbers.
It has been used in lieu of NAMELIST in many
programs; and as a basic building block in creating language-like
There are much more powerful and modern expression parsers available
now-adays, but this routine has proven to be very portable and
simple to maintain; and is still useful.
The library is written in FORTRAN 77; it uses no recursion and no
dynamically allocated variables and is very portable. It does
not support user-defined arrays, handling of complex numbers,
or interpreted user-defined functions.
The parser is not intended to be used to generate a large number
(hundreds of thousands) of calculations. It was written to be
portable, not optimal. The library has been used on many operating
systems, including NOS, NOS/VE, VMS, COS, Aegis, UNICOS, SunOS,
HP-UX, IRIX64, AIX, Solaris, Ultrix, Tru64, OpenBSD, Linux, CygWin,
Perhaps the simplest example is a loop that reads input lines
and calls the calculator using the convenience function RNUM0(3f):
WRITE(*,*)'Enter numeric expressions'
A run of the example program might look like this:
A summary of the syntax rules for the expressions follows:
- The hierarchy of operations is the same as that of
FORTRAN 77 except that adjacent exponents are done from left
to right, not right to left [i.e. in FORTRAN
3**2**4=3**(2**4), in JUEXPR 3**2**4=(3**2)**4]; and +-
strings are resolved to a single sign (that is, 3+ -4 is
acceptable instead of 3+(-4)).
- The JUEXPR routine provides almost all the ANSI
mathematical functions available in FORTRAN 77, as well as
access to common extensions and custom routines.
- Embedded non-quoted blanks are ignored during the processing of a calculation.
- All numeric values are treated as FORTRAN type REAL*8 variables.
- Input lines should not be longer than 255 characters.
- There are three ways to store results to be used in future calculations:
Each of the types will be discussed separately.
- Variable names
- The current-value
- The x and y arrays
Names must be 1 to 20 characters long, and are case-sensitive. Up
to 2345 names are permitted. Numeric variable names should be
composed of the letters a-z and underscores and numbers. String
variables are similar but start with a dollar sign($). Names must
not end in a "digit-E" combination. For example:
Variables may be defined by equating them to an expression.
To define or redefine a variable called FRED, simply enter:
The last value assigned to a variable will be used to
evaluate the expression on the left of the equals sign when this
expression redefines the variable. For example:
To allow FORTRAN-type E-format numeric entry and yet not
cause the calculator routine to do an excessive amount of checking,
a variable name ending in the letter E must not have a digit
(012345789) in front of that ending E. Attempting to define such a
variable name will produce an error. This limitation prevents the
calculator from becoming confused by whether 12E+3 is a variable
called 12E plus 3 or the exponential number 12E3=12000.
The variable name '?' is automatically set by the program to
contain the last calculated value. This current-value
register may be used like any variable or number. It is 0 at
program initialization. Example:
THE X AND Y ARRAYS
Two arrays called X and Y are available that can contain up
to 3333 values each. The arrays are originally initialized
to all zeros. To set values in the arrays, use the xstore (or
ystore) command. The format of the commands is
where start=array address to start storing at
and ex(i) are expressions.
The current value is assigned the last value stored.
In addition there are similar string arrays and functions
that can hold up to 50 255-character strings:
For example, to store into the locations 10,11,and 12
the values 1/10,2/10, and 3/10, the following could be
- $xstore(), $ystore()
- $x() ,$y()
xstore( 10 , 1/10 , 2/20 , 3/10 )
*-------Start storing evaluated expressions sequentially,
beginning at x(10).
REFERENCING AN ARRAY VALUE
The values stored into the arrays may be referenced by
subscript. For example:
- x and y array values cannot be used on the left of
x(10)=5 # IS ILLEGAL
- The current value is set to the value of the last
expression by the xstore and ystore commands
- r2d(arg) - converts from radians to degrees
- d2r(arg) - converts from degrees to radians
- f2c() - convert Fahrenheit to Celcius
- c2f() - convert Celcius to Fahrenheit
- ge(val1,val2) - return TRUE if VAL1 is greater than or equal to VAL2, else return FALSE
- gt(val1,val2) - return TRUE if VAL1 is greater than to VAL2, else return FALSE
- eq(val1,val2) - return TRUE if VAL1 is equal to VAL2, else return FALSE
- le(val1,val2) - return TRUE if VAL1 is less than or equal to VAL2, else return FALSE
- lt(val1,val2) - return TRUE if VAL1 is less than VAL2, else return FALSE
- ne(val1,val2) - return TRUE if VAL1 is not equal to VAL2, else return FALSE
- if(expression,val1,val2) - If expression is TRUE, return VAL1 else return VAL2
means return a if b is greater than or equal to c else return d.
lexical logical functions
- lge($str1,$str2) - return TRUE if $STR1 is lexically greater than or equal to $STR2, else return FALSE
- lgt($str1,$str2) - return TRUE if $STR1 is lexically greater than to $STR2, else return FALSE
- leq($str1,$strN) - return TRUE if $STR1 is lexically equal to any of the other strings, else return FALSE
- lle($str1,$str2) - return TRUE if $STR1 is lexically less than or equal to $STR2, else return FALSE
- llt($str1,$str2) - return TRUE if $STR1 is lexically less than $STR2, else return FALSE
- lne($str1,$strN) - return TRUE if $STR1 is not equal to all following strings.
- $if(expression,$str1,$str2) - If expression is TRUE, return $STR1 else return $STR2
- ceil(val1) - ceil() returns the least integral value greater than or equal to VAL1.
- floor(val1) - floor() returns the greatest integral value less than or equal to VAL1.
- in(val1,val2,val3) - returns TRUE if VAL1 is between VAL2 and VAL3 else returns FALSE
- $char(v1,v2,....) - return characters indicated by numeric ADE (ASCII decimal equivalent) values passed.
- $(ex,ex,ex,...) or $str(ex,ex,ex,...) - generate a string from a series of strings and values
- str(ex,ex,ex,...) - same as $str() but convert resulting string to a number IF the string is a simple numeric value
- $substr(string,i,j) - return a string that is columns i thru j of the input string (first character is called column 1).
- ichar($char) - return the ADE (ASCII Decimal Equivalent) value of a letter
- index($str1,$str2) - return column number where $str2 begins in $str1 or zero(0).
- len($str1) - return the length of the string
ANSI FORTRAN INTRINSIC MATH FUNCTIONS
The common FORTRAN 77 intrinsic functions are supported.
| abs || acos || aint || anint || asin |
| atan || atan2 || cos || cosh || dim |
| exp || frac || idnint || int || log |
| log10 || max || min || mod || nint |
| real || sign || sin || sinh || sqrt |
| tan || tanh |
Displaying variable values: dump
- The current value and all defined variable names are
displayed via the dump command.
- Listing Available Functions:
- A display of all available functions can be obtained
when executing JUEXPR by entering the command 'funcs'. No
descriptions are provided.
Known bugs and limitations
- There is no type-checking to make sure that numeric values are not used where strings are required and vice-versa. That is,
can cause problems.
- If you are looking for another type of parser, some useful keywords would be "Shunting yard algorithm" for converting infix notation to postfix notation; "bytecode interpreters" which can be used to rapidly repeat a series of operations on a vector;...