void Expression::push_back_ternary_op(const Expression &e1, const Expression &e2) { Op op; op.opcode = ExprOpcode::TERNARY_OP; ops.push_back(op); op.opcode = ExprOpcode::SKIP; op.skip_num = e1.get_num_ops() + 1; ops.push_back(op); append_expression(e1); op.skip_num = e2.get_num_ops(); ops.push_back(op); append_expression(e2); }
compile_states::States field_after_group_state_handler(CompileStateData& data) { if (data.current_expr->get_type() != compiled_expr::FIELD && data.current_expr->get_type() != compiled_expr::TAG) { throw ExprCompilerError("We're in FIELD_AFTER_GROUP state, but current EXPR is not a FIELD or TAG!"); } // Creating a new `if' for this field. append_expression(data); // Appending a new result. (*data.result) << " $r" << data.result_counter; // Increasing result counter. data.result_counter++; if (data.next_expr->get_type() == compiled_expr::CONNECTIVE) { return compile_states::GROUP; } if (data.next_expr->get_type() == compiled_expr::END_CONNECTIVE_GROUP) { return compile_states::END_GROUP; } else if (data.next_expr->get_type() == compiled_expr::FIELD || data.next_expr->get_type() == compiled_expr::TAG) { return compile_states::FIELD; } // If we reach here, there's nothing else to do. return compile_states::FINISH; }
int main(int argc, char const *argv[]) { Expression_t *a = Term("a"), *b = Term("b"), *c = TermLiteral(litInt(5)), *plus = Plus(a,b), *mult = Multiply(plus, c); Expression_print(mult); append_expression(mult, plus); puts(""); Expression_printList(mult); puts(""); return 0; }
Expression_t *append_expression(Expression_t *e1, Expression_t *e2) { if (!e1) return e2; return app_exp(e1, append_expression(e1->next, e2)); }