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
23 #include "debug-print.h"
25 void debug_print_op (short int *);
28 /* Expression operators. */
29 #define DEFINE_OPERATOR(NAME, STACK_DELTA, FLAGS, ARGS) \
37 #define IS_TERMINAL(OPERATOR) (ops[OPERATOR].height > 0)
38 #define IS_NONTERMINAL(OPERATOR) !IS_TERMINAL (OPERATOR)
40 /* Flags that describe operators. */
43 OP_NO_FLAGS = 0, /* No flags. */
44 OP_VAR_ARGS = 001, /* 1=Variable number of args. */
45 OP_MIN_ARGS = 002, /* 1=Can specific min args with .X. */
46 OP_FMT_SPEC = 004, /* 1=Includes a format specifier. */
47 OP_ABSORB_MISS = 010, /* 1=May return other than SYSMIS if
48 given a SYSMIS argument. */
51 /* Describes an operator. */
54 const char *name; /* Operator name. */
55 signed char height; /* Effect on stack height. */
56 unsigned char flags; /* Flags. */
57 unsigned char skip; /* Number of operator item arguments. */
60 extern struct op_desc ops[];
62 /* Tree structured expressions. */
64 /* Numeric constant. */
67 int type; /* Always OP_NUM_CON. */
68 double value; /* Numeric value. */
74 int type; /* Always OP_STR_CON. */
75 int len; /* Length of string. */
76 char s[1]; /* String value. */
79 /* Variable or test for missing values or cancellation of
83 int type; /* OP_NUM_VAR, OP_NUM_SYS, OP_NUM_VAL,
85 struct variable *v; /* Variable. */
88 /* Variable from an earlier case. */
91 int type; /* Always OP_NUM_LAG. */
92 struct variable *v; /* Relevant variable. */
93 int lag; /* Number of cases to lag. */
99 int type; /* Always OP_CASENUM. */
102 /* Any nonterminal node. */
105 int type; /* Always greater than OP_TERMINAL. */
106 int n; /* Number of arguments. */
107 union any_node *arg[1]; /* Arguments. */
114 struct nonterm_node nonterm;
115 struct num_con_node num_con;
116 struct str_con_node str_con;
119 struct casenum_node casenum;
125 enum expr_type type; /* Type of expression result. */
126 unsigned char *op; /* Operators. */
127 struct variable **var; /* Variables. */
128 double *num; /* Numeric operands. */
129 unsigned char *str; /* String operands. */
130 union value *stack; /* Evaluation stack. */
131 struct pool *pool; /* Pool for evaluation temporaries. */
134 void optimize_expression (union any_node **);
135 void dump_expression (union any_node *, struct expression *);
136 void free_node (union any_node *);
138 double yrmoda (double year, double month, double day);