Talk about implied decimal places in FORTRAN style for DATA LIST
[pspp-builds.git] / src / exprP.h
1 /* PSPP - computes sample statistics.
2    Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
3    Written by Ben Pfaff <blp@gnu.org>.
4
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.
9
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.
14
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
18    02111-1307, USA. */
19
20 #if !exprP_h
21 #define exprP_h 1
22
23 #include "debug-print.h"
24
25 void debug_print_op (short int *);
26
27
28 /* Expression operators. */
29 #define DEFINE_OPERATOR(NAME, STACK_DELTA, FLAGS, ARGS) \
30         OP_##NAME,
31 enum
32   {
33 #include "expr.def"
34     OP_SENTINEL
35   };
36
37 #define IS_TERMINAL(OPERATOR) (ops[OPERATOR].height > 0)
38 #define IS_NONTERMINAL(OPERATOR) !IS_TERMINAL (OPERATOR)
39
40 /* Flags that describe operators. */
41 enum
42   {
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. */
49   };
50
51 /* Describes an operator. */
52 struct op_desc
53   {
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. */
58   };
59
60 extern struct op_desc ops[];
61
62 /* Tree structured expressions. */ 
63
64 /* Numeric constant. */
65 struct num_con_node
66   {
67     int type;                   /* Always OP_NUM_CON. */
68     double value;               /* Numeric value. */
69   };
70
71 /* String literal. */
72 struct str_con_node
73   {
74     int type;                   /* Always OP_STR_CON. */
75     int len;                    /* Length of string. */
76     char s[1];                  /* String value. */
77   };
78
79 /* Variable or test for missing values or cancellation of
80    user-missing. */
81 struct var_node
82   {
83     int type;                   /* OP_NUM_VAR, OP_NUM_SYS, OP_NUM_VAL,
84                                    or OP_STR_VAR. */
85     struct variable *v;         /* Variable. */
86   };
87
88 /* Variable from an earlier case. */
89 struct lag_node
90   {
91     int type;                   /* Always OP_NUM_LAG. */
92     struct variable *v;         /* Relevant variable. */
93     int lag;                    /* Number of cases to lag. */
94   };
95
96 /* $CASENUM. */
97 struct casenum_node
98   {
99     int type;                   /* Always OP_CASENUM. */
100   };
101
102 /* Any nonterminal node. */
103 struct nonterm_node
104   {
105     int type;                   /* Always greater than OP_TERMINAL. */
106     int n;                      /* Number of arguments. */
107     union any_node *arg[1];     /* Arguments. */
108   };
109
110 /* Any node. */
111 union any_node
112   {
113     int type;
114     struct nonterm_node nonterm;
115     struct num_con_node num_con;
116     struct str_con_node str_con;
117     struct var_node var;
118     struct lag_node lag;
119     struct casenum_node casenum;
120   };
121
122 /* An expression. */
123 struct expression
124   {
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. */
132   };
133
134 void optimize_expression (union any_node **);
135 void dump_expression (union any_node *, struct expression *);
136 void free_node (union any_node *);
137
138 double yrmoda (double year, double month, double day);
139
140 #endif /* exprP.h */