添加语义动作提振精神分析器时编译错误 [英] Compile error when adding semantic action to Boost Spirit parser

查看:212
本文介绍了添加语义动作提振精神分析器时编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于从用户sehe我现在的地步,我可以帮助
编译我AST。

Thanks to the help from user 'sehe' I'm now at the point where I can compile my ast.

(请在这里看到: http://stackoverflow.com/a/29301655/1835623

现在从JEDEC文件中提取的数据字段我需要解析看起来像这样之一:

Now one of the data fields extracted from JEDEC file I need to parse looks like this:

12345 0000100101010111010110101011010

"12345 0000100101010111010110101011010"

我已经建立了一个解析器来消费这些类型的字段:

I already built a parser to consume these kind of fields:

std::string input("12345 010101010101010101010");
std::string::iterator st = input.begin();

qi::parse(st, input.end(), qi::ulong_ >> ' ' >> *qi::char_("01"));

显然没有那么复杂。现在我的问题是,我要分配
的ulong_并使用语义动作二进制串到一些局部变量。这就是我所做的:

Obviously not that complicated. Now my problem is that I want to assign the ulong_ and the binary string to some local variables using a semantic action. This is what I did:

using boost::phoenix::ref;

std::string input("12345 010101010101010101010");
std::string::iterator st = input.begin();

uint32_t idx;
std::string sequence;
qi::parse(st, input.end(),
          qi::ulong_[ref(idx) = qi::_1] >>
          ' ' >>
          *qi::char_("01")[ref(sequence) += qi::_2]);

但不幸的是,这并不甚至编译和错误消息我得到
是没有帮助的(至少我)?我想这是简单的东西......但我现在绝望地卡住。 : - (

But unfortunately this doesn't even compile and the error message I get is not helpful (at least to me)? I guess it's something simple... but I'm hopelessly stuck now. :-(

是否有人有一个想法是什么,我做错了?

Does someone have an idea what I'm doing wrong?

推荐答案

有两种方式:


  1. 解决SA的

  1. fix the SA's

qi::parse(st, input.end(),
          qi::ulong_[ref(idx) = qi::_1] >>
          ' ' >>
          qi::as_string[*qi::char_("01")] [phx::ref(sequence) += qi::_1]);

注:


  • 齐:: _ 1 因为前pression的SA重视不公开两个要素,只有1

  • 它的明确 PHX :: REF ,否则ADL¹将选择的std :: REF (因为的std ::字符串

  • 使用 as_string 来强迫从 STD属性类型::矢量<字符>

  • it's qi::_1 because the expression the SA attaches to doesn't expose two elements, just 1
  • it's explicitly phx::ref because otherwise ADL¹ will select std::ref (because of std::string)
  • use as_string to coerce the attribute type from std::vector<char>


不过,当然,一如既往:提升精神:&QUOT;语义行为是邪恶的&QUOT;?

However, of course, as always: Boost Spirit: "Semantic actions are evil"?

qi::parse(st, input.end(),
          qi::ulong_ >> ' ' >> *qi::char_("01"),
          idx, sequence
    );

使用解析器API绑定到属性引用。

Use the parser API to bind references to attributes.

¹<一href=\"http://stackoverflow.com/questions/8111677/what-is-argument-dependent-lookup-aka-adl-or-koenig-lookup/8111750#8111750\">What是&QUOT;参数依赖性查找&QUOT; (又名ADL,或QUOT; Koenig查找&QUOT;)

这篇关于添加语义动作提振精神分析器时编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆