1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1982-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * David Korn <dgk@research.att.com> *
19 ***********************************************************************/
25 * arithmetic expression evaluator
28 /* The following only is needed for const */
31 #if _AST_VERSION >= 20030127L
32 # include <ast_float.h>
35 #if _ast_fltmax_double
36 #define LDBL_LLONG_MAX DBL_LLONG_MAX
37 #define LDBL_ULLONG_MAX DBL_ULLONG_MAX
38 #define LDBL_LLONG_MIN DBL_LLONG_MIN
41 #ifndef LDBL_LLONG_MAX
43 # define LDBL_LLONG_MAX ((Sfdouble_t)LLONG_MAX)
46 # define LDBL_LLONG_MAX ((Sfdouble_t)LLONG_MAX)
48 # define LDBL_LLONG_MAX ((Sfdouble_t)((((Sflong_t)1) << (8*sizeof(Sflong_t)-1)) -1 ))
52 #ifndef LDBL_ULLONG_MAX
54 # define LDBL_ULLONG_MAX ((Sfdouble_t)ULLONG_MAX)
56 # define LDBL_ULLONG_MAX (2.*((Sfdouble_t)LDBL_LLONG_MAX))
59 #ifndef LDBL_LLONG_MIN
61 # define LDBL_LLONG_MIN ((Sfdouble_t)LLONG_MIN)
63 # define LDBL_LLONG_MIN (-LDBL_LLONG_MAX)
67 # define LDBL_DIG DBL_DIG
73 Sfdouble_t (*fun
)(Sfdouble_t
,...);
87 Sfdouble_t (*fnptr
)(Sfdouble_t
,...);
90 typedef struct _arith_
94 Sfdouble_t (*fun
)(const char**,struct lval
*,int,Sfdouble_t
);
100 #define ARITH_COMP 04 /* set when compile separate from execute */
102 #define MAXPREC 15 /* maximum precision level */
103 #define SEQPOINT 0200 /* sequence point */
104 #define NOASSIGN 0100 /* assignment legal with this operator */
105 #define RASSOC 040 /* right associative */
106 #define NOFLOAT 020 /* illegal with floating point */
107 #define PRECMASK 017 /* precision bit mask */
119 #define A_PLUSPLUS 11
122 #define A_MINUSMINUS 14
163 #define A_ASSIGNOP 55
166 /* define error messages */
167 extern const unsigned char strval_precedence
[35];
168 extern const char strval_states
[64];
169 extern const char e_moretokens
[];
170 extern const char e_argcount
[];
171 extern const char e_paren
[];
172 extern const char e_badnum
[];
173 extern const char e_badcolon
[];
174 extern const char e_recursive
[];
175 extern const char e_divzero
[];
176 extern const char e_synbad
[];
177 extern const char e_notlvalue
[];
178 extern const char e_function
[];
179 extern const char e_questcolon
[];
180 extern const char e_incompatible
[];
181 extern const char e_domain
[];
182 extern const char e_overflow
[];
183 extern const char e_singularity
[];
184 extern const char e_dict
[];
185 extern const char e_charconst
[];
186 extern const struct mathtab shtab_math
[];
188 /* function code for the convert function */
195 extern Sfdouble_t
strval(const char*,char**,Sfdouble_t(*)(const char**,struct lval
*,int,Sfdouble_t
),int);
196 extern Arith_t
*arith_compile(const char*,char**,Sfdouble_t(*)(const char**,struct lval
*,int,Sfdouble_t
),int);
197 extern Sfdouble_t
arith_exec(Arith_t
*);
198 #endif /* !SEQPOINT */