1 /* PSPP - computes sample statistics.
2 Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
3 Written by Ben Pfaff <blp@gnu.org>.
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24 /*#define DEBUGGING 1*/
25 #include "debug-print.h"
28 void debug_print_expr (struct expression *);
29 void debug_print_op (short int *);
32 /* Expression types. */
35 EX_ERROR, /* Error value for propagation. */
36 EX_BOOLEAN, /* Numeric value that's 0, 1, or SYSMIS. */
37 EX_NUMERIC, /* Numeric value. */
38 EX_STRING /* String value. */
41 /* Expression operators.
42 The ordering below is important. Do not change it. */
47 /* Basic operators. */
55 /* Numeric relational operators. */
63 /* String relational operators. */
71 /* Unary functions. */
88 /* N-ary numeric functions. */
103 /* Time construction & extraction functions. */
106 /* These never appear in a tree or an expression.
107 They disappear in parse.c:unary_func(). */
114 /* Date construction functions. */
123 /* Date extraction functions. */
138 /* String functions. */
162 OP_INV, /* Reciprocal. */
163 OP_SQUARE, /* Squares the argument. */
164 OP_NUM_TO_BOOL, /* Converts ~0=>0, ~1=>1, SYSMIS=>SYSMIS,
165 others=>0 with a warning. */
168 OP_MOD, /* Modulo function. */
169 OP_NORMAL, /* Normally distributed PRNG. */
170 OP_UNIFORM, /* Uniformly distributed PRNG. */
171 OP_SYSMIS, /* Tests whether for SYSMIS argument. */
172 OP_VEC_ELEM_NUM, /* Element of a numeric vector. */
173 OP_VEC_ELEM_STR, /* Element of a string vector. */
176 OP_TERMINAL, /* Not a valid type. Boundary
177 between terminals and nonterminals. */
179 OP_NUM_CON, /* Numeric constant. */
180 OP_STR_CON, /* String literal. */
181 OP_NUM_VAR, /* Numeric variable reference. */
182 OP_STR_VAR, /* String variable reference. */
183 OP_NUM_LAG, /* Numeric variable from an earlier case. */
184 OP_STR_LAG, /* String variable from an earlier case. */
185 OP_NUM_SYS, /* SYSMIS(numvar). */
186 OP_NUM_VAL, /* VALUE(numvar). */
187 OP_STR_MIS, /* MISSING(strvar). */
188 OP_CASENUM, /* $CASENUM. */
189 OP_SENTINEL /* Sentinel. */
192 /* Flags that describe operators. */
195 OP_VAR_ARGS = 001, /* 1=Variable number of args. */
196 OP_MIN_ARGS = 002, /* 1=Can specific min args with .X. */
197 OP_FMT_SPEC = 004, /* 1=Includes a format specifier. */
198 OP_ABSORB_MISS = 010, /* 1=May return other than SYSMIS if
199 given a SYSMIS argument. */
202 /* Describes an operator. */
206 const char *name; /* Operator name. */
208 unsigned char flags; /* Flags. */
209 signed char height; /* Effect on stack height. */
210 unsigned char skip; /* Number of operator item arguments. */
213 extern struct op_desc ops[];
215 /* Tree structured expressions. */
217 /* Numeric constant. */
220 int type; /* Always OP_NUM_CON. */
221 double value; /* Numeric value. */
224 /* String literal. */
227 int type; /* Always OP_STR_CON. */
228 int len; /* Length of string. */
229 char s[1]; /* String value. */
232 /* Variable or test for missing values or cancellation of
236 int type; /* OP_NUM_VAR, OP_NUM_SYS, OP_NUM_VAL,
237 OP_STR_MIS, or OP_STR_VAR. */
238 struct variable *v; /* Variable. */
241 /* Variable from an earlier case. */
244 int type; /* Always OP_NUM_LAG. */
245 struct variable *v; /* Relevant variable. */
246 int lag; /* Number of cases to lag. */
252 int type; /* Always OP_CASENUM. */
255 /* Any nonterminal node. */
258 int type; /* Always greater than OP_TERMINAL. */
259 int n; /* Number of arguments. */
260 union any_node *arg[1]; /* Arguments. */
267 struct nonterm_node nonterm;
268 struct num_con_node num_con;
269 struct str_con_node str_con;
272 struct casenum_node casenum;
278 int type; /* Type of expression result. */
279 unsigned char *op; /* Operators. */
280 struct variable **var; /* Variables. */
281 double *num; /* Numeric operands. */
282 unsigned char *str; /* String operands. */
283 union value *stack; /* Evaluation stack. */
284 unsigned char *str_stack; /* String evaluation stack. */
286 size_t str_size; /* Size of string eval stack. */
290 struct nonterm_node *optimize_expression (struct nonterm_node *);
291 void dump_expression (union any_node *, struct expression *);
292 void free_node (union any_node *);
294 double yrmoda (double year, double month, double day);