Upload Tizen:Base source
[external/gmp.git] / demos / expr / expr.h
1 /* Header for expression evaluation.
2
3 Copyright 2000, 2001, 2002, 2004 Free Software Foundation, Inc.
4
5 This file is part of the GNU MP Library.
6
7 The GNU MP Library is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11
12 The GNU MP Library is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
15 License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with the GNU MP Library.  If not, see http://www.gnu.org/licenses/.  */
19
20
21 #ifndef __EXPR_H__
22 #define __EXPR_H__
23
24 #define MPEXPR_RESULT_OK            0
25 #define MPEXPR_RESULT_BAD_VARIABLE  1
26 #define MPEXPR_RESULT_BAD_TABLE     2
27 #define MPEXPR_RESULT_PARSE_ERROR   3
28 #define MPEXPR_RESULT_NOT_UI        4
29
30
31 /* basic types */
32 #define MPEXPR_TYPE_NARY(n)       ((n) * 0x0100)
33 #define MPEXPR_TYPE_MASK_ARGCOUNT MPEXPR_TYPE_NARY(0xF)
34 #define MPEXPR_TYPE_0ARY          MPEXPR_TYPE_NARY(0)
35 #define MPEXPR_TYPE_UNARY         MPEXPR_TYPE_NARY(1)
36 #define MPEXPR_TYPE_BINARY        MPEXPR_TYPE_NARY(2)
37 #define MPEXPR_TYPE_TERNARY       MPEXPR_TYPE_NARY(3)
38
39 /* options for all */
40 #define MPEXPR_TYPE_LAST_UI       0x0010
41 #define MPEXPR_TYPE_RESULT_INT    0x0020
42 #define MPEXPR_TYPE_MASK_ARGSTYLE 0x0030
43
44 #define MPEXPR_TYPE_UNARY_UI     (MPEXPR_TYPE_UNARY   | MPEXPR_TYPE_LAST_UI)
45 #define MPEXPR_TYPE_I_UNARY      (MPEXPR_TYPE_UNARY   | MPEXPR_TYPE_RESULT_INT)
46 #define MPEXPR_TYPE_I_UNARY_UI   (MPEXPR_TYPE_I_UNARY | MPEXPR_TYPE_LAST_UI)
47 #define MPEXPR_TYPE_BINARY_UI    (MPEXPR_TYPE_BINARY  | MPEXPR_TYPE_LAST_UI)
48 #define MPEXPR_TYPE_I_BINARY     (MPEXPR_TYPE_BINARY  | MPEXPR_TYPE_RESULT_INT)
49 #define MPEXPR_TYPE_I_BINARY_UI  (MPEXPR_TYPE_I_BINARY| MPEXPR_TYPE_LAST_UI)
50 #define MPEXPR_TYPE_TERNARY_UI   (MPEXPR_TYPE_TERNARY | MPEXPR_TYPE_LAST_UI)
51 #define MPEXPR_TYPE_I_TERNARY    (MPEXPR_TYPE_TERNARY | MPEXPR_TYPE_RESULT_INT)
52 #define MPEXPR_TYPE_I_TERNARY_UI (MPEXPR_TYPE_I_TERNARY|MPEXPR_TYPE_LAST_UI)
53
54 /* 0ary with options */
55 #define MPEXPR_TYPE_CONSTANT      (MPEXPR_TYPE_0ARY | 0x0040)
56
57 /* unary options */
58 #define MPEXPR_TYPE_PREFIX        0x0040
59
60 /* binary options */
61 #define MPEXPR_TYPE_RIGHTASSOC    0x0040
62 #define MPEXPR_TYPE_PAIRWISE      0x0080
63
64 #define MPEXPR_TYPE_MASK_SPECIAL  0x000F
65
66 /* unary specials */
67 #define MPEXPR_TYPE_NEW_TABLE     (MPEXPR_TYPE_UNARY | 0x001)
68 #define MPEXPR_TYPE_DONE          (MPEXPR_TYPE_UNARY | 0x002)
69 #define MPEXPR_TYPE_VARIABLE      (MPEXPR_TYPE_UNARY | 0x003)
70 #define MPEXPR_TYPE_LOGICAL_NOT   (MPEXPR_TYPE_UNARY | 0x004)
71 #define MPEXPR_TYPE_CLOSEPAREN    (MPEXPR_TYPE_UNARY | 0x005)
72 #define MPEXPR_TYPE_OPENPAREN     (MPEXPR_TYPE_CLOSEPAREN | MPEXPR_TYPE_PREFIX)
73
74 /* binary specials */
75 #define MPEXPR_TYPE_LOGICAL_AND   (MPEXPR_TYPE_BINARY | 0x001)
76 #define MPEXPR_TYPE_LOGICAL_OR    (MPEXPR_TYPE_BINARY | 0x002)
77 #define MPEXPR_TYPE_ARGSEP        (MPEXPR_TYPE_BINARY | 0x003)
78 #define MPEXPR_TYPE_QUESTION      (MPEXPR_TYPE_BINARY | 0x004)
79 #define MPEXPR_TYPE_COLON         (MPEXPR_TYPE_BINARY | 0x005)
80 #define MPEXPR_TYPE_MAX           (MPEXPR_TYPE_BINARY | 0x006)
81 #define MPEXPR_TYPE_MIN           (MPEXPR_TYPE_BINARY | 0x007)
82 #define MPEXPR_TYPE_MASK_CMP      0x008
83 #define MPEXPR_TYPE_MASK_CMP_LT   0x001
84 #define MPEXPR_TYPE_MASK_CMP_EQ   0x002
85 #define MPEXPR_TYPE_MASK_CMP_GT   0x004
86 #define MPEXPR_TYPE_CMP_LT       (MPEXPR_TYPE_BINARY | MPEXPR_TYPE_MASK_CMP \
87                                   | MPEXPR_TYPE_MASK_CMP_LT)
88 #define MPEXPR_TYPE_CMP_EQ       (MPEXPR_TYPE_BINARY | MPEXPR_TYPE_MASK_CMP \
89                                   | MPEXPR_TYPE_MASK_CMP_EQ)
90 #define MPEXPR_TYPE_CMP_GT       (MPEXPR_TYPE_BINARY | MPEXPR_TYPE_MASK_CMP \
91                                   | MPEXPR_TYPE_MASK_CMP_GT)
92 #define MPEXPR_TYPE_CMP_LE       (MPEXPR_TYPE_CMP_LT | MPEXPR_TYPE_MASK_CMP_EQ)
93 #define MPEXPR_TYPE_CMP_NE       (MPEXPR_TYPE_CMP_LT | MPEXPR_TYPE_MASK_CMP_GT)
94 #define MPEXPR_TYPE_CMP_GE       (MPEXPR_TYPE_CMP_GT | MPEXPR_TYPE_MASK_CMP_EQ)
95
96 /* parse options */
97 #define MPEXPR_TYPE_WHOLEWORD      0x1000
98 #define MPEXPR_TYPE_OPERATOR       0x2000
99
100
101 typedef void (*mpexpr_fun_t) __GMP_PROTO ((void));
102
103 struct mpexpr_operator_t {
104   __gmp_const char  *name;
105   mpexpr_fun_t      fun;
106   int               type;
107   int               precedence;
108 };
109
110
111 int mpf_expr_a __GMP_PROTO ((__gmp_const struct mpexpr_operator_t *table,
112                         mpf_ptr res, int base, unsigned long prec,
113                         __gmp_const char *e, size_t elen,
114                         mpf_srcptr var[26]));
115 int mpf_expr __GMP_PROTO ((mpf_ptr res, int base, __gmp_const char *e, ...));
116
117 int mpq_expr_a __GMP_PROTO ((__gmp_const struct mpexpr_operator_t *table,
118                         mpq_ptr res, int base,
119                         __gmp_const char *e, size_t elen,
120                         mpq_srcptr var[26]));
121 int mpq_expr __GMP_PROTO ((mpq_ptr res, int base, __gmp_const char *e, ...));
122
123 int mpz_expr_a __GMP_PROTO ((__gmp_const struct mpexpr_operator_t *table,
124                         mpz_ptr res, int base,
125                         __gmp_const char *e, size_t elen,
126                         mpz_srcptr var[26]));
127 int mpz_expr __GMP_PROTO ((mpz_ptr res, int base, __gmp_const char *e, ...));
128
129 #endif