예제 #1
0
    expression_literal eval(
            const std::string &name,
            const expression_function::argtype_list_type &arg_types,
            expression_container::expr_list_type &args
    ) {
        if (name == "XOR") {
            if (arg_types.size() != 2
                or args.size() != 2
                or arg_types[0] != expression::TYPE_BOOL
                or arg_types[1] != expression::TYPE_BOOL
                or args[0]->infer_type() != expression::TYPE_BOOL
                or args[1]->infer_type() != expression::TYPE_BOOL
            ) {
                throw uhd::syntax_error("eval(): XOR type mismatch");
            }
            return expression_literal(bool(
                args[0]->eval().get_bool() xor args[1]->eval().get_bool()
            ));
        }

        if (name == "AND") {
            if (arg_types.size() != 2
                or args.size() != 2
                or arg_types[0] != expression::TYPE_BOOL
                or arg_types[1] != expression::TYPE_BOOL
                or args[0]->infer_type() != expression::TYPE_BOOL
                or args[1]->infer_type() != expression::TYPE_BOOL
            ) {
                throw uhd::syntax_error("eval(): AND type mismatch");
            }
            std::cout << "Calling AND" << std::endl;
            and_counter++;
            return expression_literal(bool(
                args[0]->eval().get_bool() and args[1]->eval().get_bool()
            ));
        }

        if (name == "ADD") {
            if (args.size() != 2) {
                throw uhd::syntax_error("eval(): ADD type mismatch");
            }
            if ((args[0]->infer_type() == expression::TYPE_INT) and
                (args[1]->infer_type() == expression::TYPE_INT)) {
                return expression_literal(int(
                    args[0]->eval().get_int() + args[1]->eval().get_int()
                ));
            }
            else if ((args[0]->infer_type() == expression::TYPE_DOUBLE) and
                (args[1]->infer_type() == expression::TYPE_DOUBLE)) {
                return expression_literal(double(
                    args[0]->eval().get_double() + args[1]->eval().get_double()
                ));
            }
            throw uhd::syntax_error("eval(): ADD type mismatch");
        }
        throw uhd::syntax_error("eval(): unknown function");
    }
예제 #2
0
expression_literal variable_get_value(const std::string &var_name)
{
    if (var_name == "spp") {
        std::cout << "Returning value for $spp..." << std::endl;
        return expression_literal(5);
    }
    if (var_name == "is_true") {
        std::cout << "Returning value for $is_true..." << std::endl;
        return expression_literal(true);
    }

    throw uhd::syntax_error("Cannot read value (unknown variable)");
}
예제 #3
0
// Some bogus function to test the registry
expression_literal add_plus2_int(expression_container::expr_list_type args)
{
    return expression_literal(args[0]->eval().get_int() + args[1]->eval().get_int() + 2);
}
예제 #4
0
// Some bogus function to test the registry
expression_literal dummy_false(expression_container::expr_list_type)
{
    dummy_false_counter++;
    std::cout << "Running dummy/false statement." << std::endl;
    return expression_literal(false);
}