compute
[ XITE Reference Manual | XITE home ]
Contents
Name
compute, compute_line, compute_answer, compute_define,
compute_error - Simple calculator.
#include <xite/compu4.h>
int compute_line( char* inp_line, ...);
number *compute_answer( void );
char *compute_error( int message );
int compute_define( char* name, func action );
Compute the value of an expression.
The value can be of all types. The return value
gives the type of the answer.
#define TY_UN -1 * Unknown, Error in i_value *
#define TY_BF 0 * Boolean, false
#define TY_BT 1 * Boolean, true
#define TY_CI 2 * int, Answer in i_value *
#define TY_CD 3 * double, Answer in d_value *
#define TY_CS 4 * *char, Answer in p_value *
#define TY_BO 5 * Boolean, Answer in i_value *
#define TY_CP 6 * Predefined constant *
#define TY_VR 7 * Variable *
Answer is a number record containing the result
of the expression. Number is defined as:
typedef struct u_tag
{
union
{
INT i_value;
double d_value;
char *p_value
} u_value
int u_type;
} number;
Line is the string which is evaluated. The line is an
arithmetic and/or a boolean expression. Special symbols
introduced by the character % is converted to a string,
or a constant from the argument list. The grammar is
S -> $
S -> E$
E -> un E
E -> E op E
E -> (E)
E -> id = E
$ - End of line
E - Input constant.
%S - The first argument in the list is
replaced as a character string.
%s - The next (or second) argument in the list is
replaced as a character str ing.
%L - The first argument in the list is
replaced as a lowercase character string.
%l - The next (or second) argument in the list is
replaced as a lowercase character string.
%U - The first argument in the list is
replaced as a uppercase character string.
%u - The next (or second) argument in the list is
replaced as a uppercase character string.
%D - The first argument in the list is
replaced as an integer.
%d - The next (or second) argument in the list is
replaced as an integer.
%F - The first argument in the list is
replaced as a double precision.
%f - The next (or second) argument in the list is
replaced as a double precision.
Predefined Constant.
INT - All integer strings and all integers
REAL - All floating-point strings and reals
FILE - All strings = name of existing file.
EXE - All strings = name of executable file.
WRITE - All strings = name of file with write
access.
READ - All strings = name of file with read
access.
usrdef - Define your own constant
Result from: un E, E op E, or (E)
un - [+,-] int, float or string,
String is converted to INT or float.
[NOT] Boolean
op - [*,/] int, float or string.
String is converted to INT or float.
INT op float -> int.
float op INT -> float.
op - [+,-] int, float or string.
String is converted to INT or float.
INT op float -> int.
float op INT -> float.
op - [LT,<,LE,<=,EQ,==,NE,!=,GE,>=,GT,>]
String is converted to INT or float.
INT op float -> INT op INT -> Boolean.
float op INT -> float op float -> Boolean.
op [IS] True is first argument match the regular
expresion in arg2. All Predefined
constants are valid regular expresions.
op - [AND] Bool op Bool -> Bool. Second argument
is not computed if first arg is FALSE.
op - [OR] Bool op Bool -> Bool. Second argument
is not computed if first arg is TRUE.
() - Operators abow are listed with decreasing
precedence.
= Define variables. Defined variables may
be used in other expressions.
A = 4
B = 2*A
The diagnostic code is listed below.
If the evaluation of the expression was sucsessful the
function returns a non-negative result.
If the evaluation fails compute_error will return
E_TOK - Undefined token.
E_ARG - Missing argument.
E_OP - Missing operand.
E_LP - Too many )'s.
E_EOL - Unexpected end of line.
E_RP - Expected )
E_TYP - Wrong arg type for op
E_LEN - Too long input line
E_EQ - Variable expexted
Otto Milvang
$Id: compu4.c,v 1.27 1997/01/29 10:46:18 svein Exp $
--------------------------------------------------------------- */
/*
---------------------------------------------------------------
compute - include files
---------------------------------------------------------------