- TYPED(num_exp, exp1)
- NAMED(num_exp_op_token, operator_)
- TYPED(num_exp, exp2)) {
- exp = exp1;
- do {
- struct psi_num_exp *op = exp1;
- while (op->operand) {
- op = op->operand;
- }
- op->op = operator_->type;
- op->operand = exp2;
- } while(0);
- free(operator_);
+ TYPED(number, num)) {
+ exp = psi_num_exp_init_num(num);
+ exp->token = psi_token_copy(num->token);
+}
+
+/*
+ * num_exp: ( num_exp )
+ */
+PARSE_TYPED(num_exp, exp,
+ NAMED(LPAREN, L)
+ TYPED(num_exp, exp_)
+ TOKEN(RPAREN)) {
+ exp = psi_num_exp_init_unary(PSI_T_LPAREN, exp_);
+ exp->token = L;
+}
+
+/*
+ * num_exp: num_exp binary_op_token num_exp
+ */
+PARSE_TYPED(num_exp, exp,
+ TYPED(num_exp, lhs_)
+ NAMED(binary_op_token, OP)
+ TYPED(num_exp, rhs_)) {
+ exp = psi_num_exp_init_binary(OP->type, lhs_, rhs_);
+ exp->token = OP;
+}
+
+/*
+ * num_exp: unary_op_token num_exp
+ */
+PARSE_TYPED(num_exp, exp,
+ NAMED(unary_op_token, OP)
+ TYPED(num_exp, exp_)) {
+ exp = psi_num_exp_init_unary(OP->type, exp_);
+ exp->token = OP;