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"
27 void debug_print_op (short int *);
30 /* Expression operators. */
31 #define DEFINE_OPERATOR(NAME, STACK_DELTA, FLAGS, ARGS) \
39 #define IS_TERMINAL(OPERATOR) (ops[OPERATOR].height > 0)
40 #define IS_NONTERMINAL(OPERATOR) !IS_TERMINAL (OPERATOR)
42 /* Flags that describe operators. */
45 OP_NO_FLAGS = 0, /* No flags. */
46 OP_VAR_ARGS = 001, /* 1=Variable number of args. */
47 OP_MIN_ARGS = 002, /* 1=Can specific min args with .X. */
48 OP_FMT_SPEC = 004, /* 1=Includes a format specifier. */
49 OP_ABSORB_MISS = 010, /* 1=May return other than SYSMIS if
50 given a SYSMIS argument. */
53 /* Describes an operator. */
56 const char *name; /* Operator name. */
57 signed char height; /* Effect on stack height. */
58 unsigned char flags; /* Flags. */
59 unsigned char skip; /* Number of operator item arguments. */
62 extern struct op_desc ops[];
64 /* Tree structured expressions. */
66 /* Numeric constant. */
69 int type; /* Always OP_NUM_CON. */
70 double value; /* Numeric value. */
76 int type; /* Always OP_STR_CON. */
77 int len; /* Length of string. */
78 char s[1]; /* String value. */
81 /* Variable or test for missing values or cancellation of
85 int type; /* OP_NUM_VAR, OP_NUM_SYS, OP_NUM_VAL,
87 struct variable *v; /* Variable. */
90 /* Variable from an earlier case. */
93 int type; /* Always OP_NUM_LAG. */
94 struct variable *v; /* Relevant variable. */
95 int lag; /* Number of cases to lag. */
101 int type; /* Always OP_CASENUM. */
104 /* Any nonterminal node. */
107 int type; /* Always greater than OP_TERMINAL. */
108 int n; /* Number of arguments. */
109 union any_node *arg[1]; /* Arguments. */
116 struct nonterm_node nonterm;
117 struct num_con_node num_con;
118 struct str_con_node str_con;
121 struct casenum_node casenum;
127 enum expr_type type; /* Type of expression result. */
128 unsigned char *op; /* Operators. */
129 struct variable **var; /* Variables. */
130 double *num; /* Numeric operands. */
131 unsigned char *str; /* String operands. */
132 union value *stack; /* Evaluation stack. */
133 struct pool *pool; /* Pool for evaluation temporaries. */
136 void optimize_expression (union any_node **);
137 void dump_expression (union any_node *, struct expression *);
138 void free_node (union any_node *);
140 double yrmoda (double year, double month, double day);