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