1N/A/***********************************************************************
1N/A* *
1N/A* This software is part of the ast package *
1N/A* Copyright (c) 1982-2011 AT&T Intellectual Property *
1N/A* and is licensed under the *
1N/A* Common Public License, Version 1.0 *
1N/A* by AT&T Intellectual Property *
1N/A* *
1N/A* A copy of the License is available at *
1N/A* http://www.opensource.org/licenses/cpl1.0.txt *
1N/A* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
1N/A* *
1N/A* Information and Software Systems Research *
1N/A* AT&T Research *
1N/A* Florham Park NJ *
1N/A* *
1N/A* David Korn <dgk@research.att.com> *
1N/A* *
1N/A***********************************************************************/
1N/A#pragma prototyped
1N/A#ifndef SEQPOINT
1N/A/*
1N/A * D. G. Korn
1N/A *
1N/A * arithmetic expression evaluator
1N/A */
1N/A
1N/A/* The following only is needed for const */
1N/A#include <ast.h>
1N/A#include <math.h>
1N/A#include "defs.h"
1N/A#if _AST_VERSION >= 20030127L
1N/A# include <ast_float.h>
1N/A#endif
1N/A
1N/A#if _ast_fltmax_double
1N/A#define LDBL_LLONG_MAX DBL_LLONG_MAX
1N/A#define LDBL_ULLONG_MAX DBL_ULLONG_MAX
1N/A#define LDBL_LLONG_MIN DBL_LLONG_MIN
1N/A#endif
1N/A
1N/A#ifndef LDBL_LLONG_MAX
1N/A# ifdef LLONG_MAX
1N/A# define LDBL_LLONG_MAX ((Sfdouble_t)LLONG_MAX)
1N/A# else
1N/A# ifdef LLONG_MAX
1N/A# define LDBL_LLONG_MAX ((Sfdouble_t)LLONG_MAX)
1N/A# else
1N/A# define LDBL_LLONG_MAX ((Sfdouble_t)((((Sflong_t)1) << (8*sizeof(Sflong_t)-1)) -1 ))
1N/A# endif
1N/A# endif
1N/A#endif
1N/A#ifndef LDBL_ULLONG_MAX
1N/A# ifdef ULLONG_MAX
1N/A# define LDBL_ULLONG_MAX ((Sfdouble_t)ULLONG_MAX)
1N/A# else
1N/A# define LDBL_ULLONG_MAX (2.*((Sfdouble_t)LDBL_LLONG_MAX))
1N/A# endif
1N/A#endif
1N/A#ifndef LDBL_LLONG_MIN
1N/A# ifdef LLONG_MIN
1N/A# define LDBL_LLONG_MIN ((Sfdouble_t)LLONG_MIN)
1N/A# else
1N/A# define LDBL_LLONG_MIN (-LDBL_LLONG_MAX)
1N/A# endif
1N/A#endif
1N/A#ifndef LDBL_DIG
1N/A# define LDBL_DIG DBL_DIG
1N/A#endif
1N/A
1N/Astruct lval
1N/A{
1N/A Shell_t *shp;
1N/A char *value;
1N/A Sfdouble_t (*fun)(Sfdouble_t,...);
1N/A const char *expr;
1N/A const void *ptr;
1N/A int nosub;
1N/A short flag;
1N/A short nargs;
1N/A short emode;
1N/A short level;
1N/A short elen;
1N/A char eflag;
1N/A char isfloat;
1N/A};
1N/A
1N/Astruct mathtab
1N/A{
1N/A char fname[16];
1N/A Sfdouble_t (*fnptr)(Sfdouble_t,...);
1N/A};
1N/A
1N/Atypedef struct _arith_
1N/A{
1N/A Shell_t *shp;
1N/A unsigned char *code;
1N/A const char *expr;
1N/A Sfdouble_t (*fun)(const char**,struct lval*,int,Sfdouble_t);
1N/A short size;
1N/A short staksize;
1N/A short emode;
1N/A short elen;
1N/A} Arith_t;
1N/A#define ARITH_COMP 04 /* set when compile separate from execute */
1N/A#define ARITH_ASSIGNOP 010 /* set during assignment operators */
1N/A
1N/A#define MAXPREC 15 /* maximum precision level */
1N/A#define SEQPOINT 0200 /* sequence point */
1N/A#define NOASSIGN 0100 /* assignment legal with this operator */
1N/A#define RASSOC 040 /* right associative */
1N/A#define NOFLOAT 020 /* illegal with floating point */
1N/A#define PRECMASK 017 /* precision bit mask */
1N/A
1N/A#define A_EOF 1
1N/A#define A_NEQ 2
1N/A#define A_NOT 3
1N/A#define A_MOD 4
1N/A#define A_ANDAND 5
1N/A#define A_AND 6
1N/A#define A_LPAR 7
1N/A#define A_RPAR 8
1N/A#define A_POW 9
1N/A#define A_TIMES 10
1N/A#define A_PLUSPLUS 11
1N/A#define A_PLUS 12
1N/A#define A_COMMA 13
1N/A#define A_MINUSMINUS 14
1N/A#define A_MINUS 15
1N/A#define A_DIV 16
1N/A#define A_LSHIFT 17
1N/A#define A_LE 18
1N/A#define A_LT 19
1N/A#define A_EQ 20
1N/A#define A_ASSIGN 21
1N/A#define A_COLON 22
1N/A#define A_RSHIFT 23
1N/A#define A_GE 24
1N/A#define A_GT 25
1N/A#define A_QCOLON 26
1N/A#define A_QUEST 27
1N/A#define A_XOR 28
1N/A#define A_OROR 29
1N/A#define A_OR 30
1N/A#define A_TILDE 31
1N/A#define A_REG 32
1N/A#define A_DIG 33
1N/A#define A_INCR 34
1N/A#define A_DECR 35
1N/A#define A_PUSHV 36
1N/A#define A_PUSHL 37
1N/A#define A_PUSHN 38
1N/A#define A_PUSHF 39
1N/A#define A_STORE 40
1N/A#define A_POP 41
1N/A#define A_SWAP 42
1N/A#define A_UMINUS 43
1N/A#define A_JMPZ 44
1N/A#define A_JMPNZ 45
1N/A#define A_JMP 46
1N/A#define A_CALL1F 47
1N/A#define A_CALL2F 48
1N/A#define A_CALL3F 49
1N/A#define A_CALL1I 50
1N/A#define A_CALL2I 51
1N/A#define A_DOT 52
1N/A#define A_LIT 53
1N/A#define A_NOTNOT 54
1N/A#define A_ASSIGNOP 55
1N/A#define A_ENUM 56
1N/A#define A_ASSIGNOP1 57
1N/A
1N/A
1N/A/* define error messages */
1N/Aextern const unsigned char strval_precedence[35];
1N/Aextern const char strval_states[64];
1N/Aextern const char e_moretokens[];
1N/Aextern const char e_argcount[];
1N/Aextern const char e_paren[];
1N/Aextern const char e_badnum[];
1N/Aextern const char e_badcolon[];
1N/Aextern const char e_recursive[];
1N/Aextern const char e_divzero[];
1N/Aextern const char e_synbad[];
1N/Aextern const char e_notlvalue[];
1N/Aextern const char e_function[];
1N/Aextern const char e_questcolon[];
1N/Aextern const char e_incompatible[];
1N/Aextern const char e_domain[];
1N/Aextern const char e_overflow[];
1N/Aextern const char e_singularity[];
1N/Aextern const char e_dict[];
1N/Aextern const char e_charconst[];
1N/Aextern const struct mathtab shtab_math[];
1N/A
1N/A/* function code for the convert function */
1N/A
1N/A#define LOOKUP 0
1N/A#define ASSIGN 1
1N/A#define VALUE 2
1N/A#define MESSAGE 3
1N/A
1N/Aextern Sfdouble_t strval(Shell_t*,const char*,char**,Sfdouble_t(*)(const char**,struct lval*,int,Sfdouble_t),int);
1N/Aextern Arith_t *arith_compile(Shell_t *,const char*,char**,Sfdouble_t(*)(const char**,struct lval*,int,Sfdouble_t),int);
1N/Aextern Sfdouble_t arith_exec(Arith_t*);
1N/A#endif /* !SEQPOINT */