struct compute_trns;
struct lvalue;
+/* COMPUTE or IF target variable or vector element.
+ For a variable, the `variable' member is non-null.
+ For a vector element, the `vector' member is non-null. */
+struct lvalue
+ {
+ struct variable *variable; /* Destination variable. */
+ bool is_new_variable; /* Did we create the variable? */
+
+ const struct vector *vector; /* Destination vector, if any, or NULL. */
+ struct expression *element; /* Destination vector element, or NULL. */
+ };
+
/* Target of a COMPUTE or IF assignment, either a variable or a
vector element. */
static struct lvalue *lvalue_parse (struct lexer *lexer, struct dataset *);
|| expr_evaluate_num (compute->test, *c, case_num) == 1.0)
{
*c = case_unshare (*c);
- case_data_rw (*c, compute->variable)->f
+ *case_num_rw (*c, compute->variable)
= expr_evaluate_num (compute->rvalue, *c, case_num);
}
}
*c = case_unshare (*c);
- case_data_rw (*c, vector_get_var (compute->vector, rindx - 1))->f
+ *case_num_rw (*c, vector_get_var (compute->vector, rindx - 1))
= expr_evaluate_num (compute->rvalue, *c, case_num);
}
compute = compute_trns_create ();
/* Test expression. */
- compute->test = expr_parse (lexer, ds, EXPR_BOOLEAN);
+ compute->test = expr_parse_bool (lexer, NULL, ds);
if (compute->test == NULL)
goto fail;
parse_rvalue (struct lexer *lexer,
const struct lvalue *lvalue, struct dataset *ds)
{
- bool is_numeric = lvalue_get_type (lvalue) == VAL_NUMERIC;
-
- return expr_parse (lexer, ds, is_numeric ? EXPR_NUMBER : EXPR_STRING);
+ if (lvalue->is_new_variable)
+ return expr_parse_new_variable (lexer, NULL, ds, var_get_name (lvalue->variable));
+ else
+ return expr_parse (lexer, NULL, ds, lvalue_get_type (lvalue));
}
/* Returns a new struct compute_trns after initializing its fields. */
return true;
}
\f
-/* COMPUTE or IF target variable or vector element.
- For a variable, the `variable' member is non-null.
- For a vector element, the `vector' member is non-null. */
-struct lvalue
- {
- struct variable *variable; /* Destination variable. */
- bool is_new_variable; /* Did we create the variable? */
-
- const struct vector *vector; /* Destination vector, if any, or NULL. */
- struct expression *element; /* Destination vector element, or NULL. */
- };
-
/* Parses the target variable or vector element into a new
`struct lvalue', which is returned. */
static struct lvalue *
lex_get (lexer);
if (!lex_force_match (lexer, T_LPAREN))
goto lossage;
- lvalue->element = expr_parse (lexer, ds, EXPR_NUMBER);
+ lvalue->element = expr_parse (lexer, NULL, ds, VAL_NUMERIC);
if (lvalue->element == NULL)
goto lossage;
if (!lex_force_match (lexer, T_RPAREN))