内部编译器错误,同时使用boost spirit x3

Exa*_*gon 3 c++ boost-spirit c++14 boost-spirit-x3

我目前正在使用boost spirit X3为我的DSL实现表达式和运算符层次结构.

我认为我的解析器在语义上是正确的,但是当我尝试编译它时,在编译时,gcc和clang具有巨大的内存占用,编译了无限的时间,然后退出"g ++:内部编译器错误:已杀死(程序cc1plus) )".

我试图最小化表达式解析器的代码,但它不是那么简单

是一个演示.

有人能告诉我这里我做错了什么,或者这是一个错误?

编辑:我认为问题是那里的问题:

auto const idx = as<ast::Operation>(helper::idxaccess_op > expression > ']');
auto const func = as<ast::Operation>(helper::func_call_op > expression%',' > ')');
auto const data = as<ast::Operation>(helper::access_op > expression);

auto const func_call_expr_def =
    primary_expr >> *(idx|func|data);
Run Code Online (Sandbox Code Playgroud)

如果我(idx|func|data)改为(idx|func),它也会永久编译并使用高达16GB的ram,但gcc能够编译它,并且解析器的工作原理如何.

编辑二:请看看上面的链接有我的例子导致错误.

Aru*_*nmu 6

我在源文件上做了很多更改.请查看http://melpon.org/wandbox/permlink/sY2CQkXiMiLoS1BM上的内容.

变化是:

  1. 改变了AST.这似乎不正确.主要是为变体添加"一元"的部分.
  2. 纠正了语法.这是基于我真正可以从你的测试中得到的语法.我可能错了,我只是尝试让第一个测试用例工作.最好运行diff工具来比较我的更改,特别是在'parser.hpp'中

注意:如果我的更改根据您的要求不正确,我建议您启用调试'BOOST_SPIRIT_X3_DEBUG'并跟踪它.在这种情况下,不能强调BOOST_SPIRIT_X3_DEBUG有多大用处.

parser.hpp

#include <boost/spirit/home/x3.hpp>
#include "ast.hpp"
#include "operators.hpp"
namespace parser{
    namespace x3 = boost::spirit::x3;


    template<typename T>
    auto as = [](auto p) { return x3::rule<struct _, T>{} = as_parser(p); };


    typedef x3::rule<struct multiplicative_expr_class, ast::Expression> multiplicative_expr_type;
    typedef x3::rule<struct expression_class, ast::Expression> expression_type;
    typedef x3::rule<struct primary_expr_class, ast::Operand> primary_expr_type;
    typedef x3::rule<struct func_call_call_class, ast::Expression> func_call_expr_type;
    typedef x3::rule<struct unary_expr_class, ast::Operand> unary_expr_type;



    const primary_expr_type primary_expr = "primary_expr";    
    const func_call_expr_type func_call_expr = "func_call_expr";
    const expression_type expression = "expression";
    const multiplicative_expr_type multiplicative_expr = "multiplicative_expr";
    const unary_expr_type unary_expr = "unary_expr";


    auto const primary_expr_def =
        +(x3::alpha | x3::char_('.'))
        | ( "(" > expression > ")" );

    auto const idx = as<ast::Operation>(helper::idxaccess_op > primary_expr > ']');
    auto const func = as<ast::Operation>(helper::func_call_op > primary_expr%',' > ')');
    auto const data = as<ast::Operation>(helper::access_op > expression);

    auto const func_call_expr_def =
        primary_expr >> *( idx | func | data );

    auto const unary_expr_def =
              func_call_expr
                      | as<ast::Operation>(helper::unary_op > func_call_expr);

    auto const multiplicative_expr_def =
        primary_expr >>  *(idx | func);

    auto const expression_def = multiplicative_expr_def;


BOOST_SPIRIT_DEFINE(primary_expr,
                    func_call_expr,
                    multiplicative_expr,
                    unary_expr,
                    expression);

}
Run Code Online (Sandbox Code Playgroud)

ast.hpp

#include <boost/spirit/home/x3.hpp>
#include <boost/spirit/home/x3/support/ast/variant.hpp>
#include <boost/fusion/include/adapt_struct.hpp>

#include <vector>

namespace ast{
    namespace x3 = boost::spirit::x3;

    enum class operator_t
    {
      _eq_,       // ==
      _ne_,       // !=
      _lt_,       // <
      _gt_,       // >
      _le_,       // <=
      _ge_,       // >=
      _add_,      // +
      _sub_,      // -
      _mul_,      // *
      _div_,      // /
      _mod_,      // %
      _pos_,      // unary +
      _neg_,      // unary -
      _not_,      // unary !
      _size_,     // unary #
      _bitnot_,   // unary ~
      _bitand_,   // &
      _bitor_,    // |
      _bitxor_,   // ^
      _shl_,      // <<
      _shr_,      // >>
      _and_,      // &&
      _or_,       // ||
      _idx_,      // []
      _apply_,    // ()
      _access_    // .
    };

    struct nil{};
    struct Expression;

    typedef x3::variant<
            nil,
            std::string,
            x3::forward_ast<Expression>
            //std::vector<Expression> //adding this as an operand for function parameter
    > Operand;

    struct Operation {
        operator_t operator_;
        Operand operand_;
    };

    struct Expression {
        Operand first_;
        std::vector<Operation> rest_;
    };
}
BOOST_FUSION_ADAPT_STRUCT(ast::Operation, operator_, operand_)
BOOST_FUSION_ADAPT_STRUCT(ast::Expression, first_, rest_)
Run Code Online (Sandbox Code Playgroud)