Пример #1
0
        ///
        /// Evaluates the expression using values from the specified table.
        /// \param args The table of variable values.
        /// \return The output from the expression.
        ///
        float_type evaluate(const args_type & args = args_type()) const
        {
            std::vector<float_type> stack;

            for (const auto & t : _queue)
            {
                if (t.type == _token::number)
                {
                    stack.push_back(t.get_value());
                }
                else if (t.type == _token::variable)
                {
                    const auto item = args.find(t.text);

                    if (item == args.end())
                        throw jade::error()
                            << "undefined variable '"
                            << t.text
                            << "'";

                    stack.push_back(item->second);
                }
                else
                {
                    if (stack.size() < 2)
                        throw jade::error("invalid expression");

                    const auto n2 = stack.back();
                    stack.pop_back();
                    const auto n1 = stack.back();
                    stack.pop_back();

                    if      (t.type == _token::plus ) stack.push_back(n1 + n2);
                    else if (t.type == _token::minus) stack.push_back(n1 - n2);
                    else if (t.type == _token::star ) stack.push_back(n1 * n2);
                    else if (t.type == _token::slash) stack.push_back(n1 / n2);
                    else throw jade::error("invalid operator");
                }
            }

            if (stack.size() != 1)
                throw jade::error("invalid expression");

            return stack[0];
        }
Пример #2
0
inline std::vector<char const *> get_args_ptrs(args_type const& args)
{
    std::vector<char const*> args_ptrs{args.size()};
    std::transform(std::begin(args), std::end(args), std::begin(args_ptrs), [](std::string const& s){ return s.c_str(); });
    return args_ptrs;
}
Пример #3
0
std::vector<const char*> libclang_vim::get_args_ptrs(const args_type& args) {
    std::vector<const char*> args_ptrs{args.size()};
    std::transform(std::begin(args), std::end(args), std::begin(args_ptrs),
                   [](const std::string& s) { return s.c_str(); });
    return args_ptrs;
}