标签: boost-spirit

为什么 nvcc 无法使用 boost::spirit 编译 CUDA 文件?

我正在尝试将 CUDA 集成到使用 boost::spirit 的现有应用程序中。

隔离问题后,我发现以下代码无法与 nvcc 编译:

main.cu

#include <boost/spirit/include/qi.hpp>
int main(){
    exit(0);
}
Run Code Online (Sandbox Code Playgroud)

编译nvcc -o cudaTest main.cu我得到了很多可以在这里看到的错误。

但是,如果我将文件名更改为main.cpp,然后使用 再次编译nvcc,则可以正常工作。这里发生了什么,我该如何解决?

c++ boost cuda boost-spirit nvcc

4
推荐指数
1
解决办法
2290
查看次数

如何在 Boost.Spirit 中跳过行/块/嵌套块注释?

使用 Boost.Spirit 解析语言时,如何确保跳​​过

// line comments

/* block
   comments */ and

/* /* nested
   block */ comments */
Run Code Online (Sandbox Code Playgroud)

在阅读代码时?目前,我只是做了phrase_parse一个预定义的qi::grammar. 我想我需要的是某种跳过词法分析器,对吗?

c++ boost boost-spirit boost-spirit-qi

4
推荐指数
1
解决办法
850
查看次数

使用自定义属性解析来提升精神规则

我正在编写一个Boost Spirit语法来将文本解析为这些结构的向量:

struct Pair
{
    double a;
    double b;
};

BOOST_FUSION_ADAPT_STRUCT(
    Pair,
    (double, a)
    (double, a)
)
Run Code Online (Sandbox Code Playgroud)

这个语法有这样的规则:

qi::rule<Iterator, Pair()> pairSequence;
Run Code Online (Sandbox Code Playgroud)

但是,实际的语法pairSequence是这样的:

double_ % separator
Run Code Online (Sandbox Code Playgroud)

我想这个语法产生一个Pair具有a等于双层并b等于某个常数.我想做这样的事情:

pairSequence = double_[_val = Pair(_1, DEFAULT_B)] % separator;
Run Code Online (Sandbox Code Playgroud)

当然,上面没有编译.我尝试添加一个构造函数Pair,但我仍然得到编译错误(没有匹配函数调用'Pair :: Pair(const boost :: phoenix :: actor>&,double)').

attributes boost boost-spirit boost-phoenix boost-spirit-qi

3
推荐指数
1
解决办法
1727
查看次数

提升基于精神语法的字符串拆分

我正在使用Boost 1.44,Spirit解析器适用于数值解析,但对于字符串解析来说真的很棘手.我试图解析一个字符串,使用多个分隔符进行拆分:',',';' 要么 ' '.当我这样做时,它适用于数字(其中vect = vector <double>):

qi::parse(first,last,double_ >> *(',' >> double_  | ' ' >> double_ | ';' >> double_),
Run Code Online (Sandbox Code Playgroud)

VECT,空间);

但是,当我使用vect = vector <string>修改字符串的语法时,

+char_ >> *(',' >> +char_  | ' ' >> +char_ | ';' >> +char_)
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

/usr/include/boost/spirit/home/qi/detail/assign_to.hpp:109:13: error: invalid conversion from ‘char’ to ‘const char*’/usr/include/boost/spirit/home/qi/detail/assign_to.hpp:109:13: error:   initializing argument 1 of ‘std::basic_string<_CharT, _Traits,_Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]’
Run Code Online (Sandbox Code Playgroud)

我将错误缩小为语法语法中的第一个+ char_,它被视为一系列字符而不是字符串.有什么方法可以解决这个问题吗?

谢谢

c++ boost boost-spirit boost-spirit-qi

3
推荐指数
1
解决办法
919
查看次数

如何使用Boost Spirit来解析中文(unicode utf-16)?

我的节目不承认中文.如何使用精神来认识中国人?我使用wstring并将其转换为utf-16.

这是我的头文件:

#pragma once

#define BOOST_SPIRIT_UNICODE 

#include <boost/spirit/include/qi.hpp>  
#include <string>
#include <vector>
#include <map>
using namespace std;



namespace qi = boost::spirit::qi;
namespace ascii = boost::spirit::ascii;


typedef pair<wstring,wstring> WordMeaningType;
typedef vector<WordMeaningType> WordMeaningsType;
typedef pair<wstring,WordMeaningsType> WordType;
typedef vector<WordType> WordListType;

struct WordPaser
    :qi::grammar<wstring::iterator,WordListType(),ascii::space_type > 
{
public:
    qi::rule<wstring::iterator, wstring(),ascii::space_type> mRuleWordPart;
    qi::rule<wstring::iterator, wstring(),ascii::space_type> mRuleWordMeaning;
    qi::rule<wstring::iterator, wstring(),ascii::space_type> mRuleWord;

    qi::rule<wstring::iterator, WordMeaningType(),ascii::space_type> mRulePM;
    qi::rule<wstring::iterator, WordMeaningsType(),ascii::space_type> mRulePMs;
    qi::rule<wstring::iterator, WordType(),ascii::space_type> mRuleCurWPM;

    qi::rule<wstring::iterator, WordListType(),ascii::space_type> mRuleEntrence;


    wstring mCurWord;
    wstring mCurWordPart;
    wstring mCurWordMeaning;
    WordMeaningType mCurPM;
    WordMeaningsType mCurPMs;
    WordType mCurWPM;

    WordPaser();


}; …
Run Code Online (Sandbox Code Playgroud)

unicode boost utf-16 cjk boost-spirit

3
推荐指数
1
解决办法
1410
查看次数

boost :: qi :: parse似乎导致编译错误

我正在尝试使用Boost :: Spirit编写解析器,并且我编写了解析器并进行了编译.问题是,当我尝试编译解析函数时,编译器会抛出一堆模板错误.这是Qi语法:

template<typename Iterator>
struct etf_parser : qi::grammar<Iterator, std::map<std::string, etfnode>(), ascii::space_type> {
    etf_parser() : etf_parser::base_type(start) {
            using qi::int_;
            using qi::lit;
            using qi::double_;
            using qi::bool_;
            using qi::lexeme;
            using ascii::char_;

            quoted_string %= lexeme['"' >> +(char_ - '"') >> '"'];

            dataVal %= (quoted_string | double_ | int_ | bool_ | listObj | pairObj | mapObj);

            pairObj %= ('<' >> dataVal >> ',' >> dataVal >> '>');

            listObj %= '{' >> dataVal % ',' >> '}';

            mapKey %= +qi::char_("a-zA-Z_-0-9.");
            mapPair %= mapKey >> …
Run Code Online (Sandbox Code Playgroud)

c++ boost compiler-errors boost-spirit

3
推荐指数
1
解决办法
1093
查看次数

使用karma为指针向量生成输出

我在使用karma为boost :: shared_ptrs的向量中保存的结构生成输出时遇到了一些麻烦.我有一个使用不能编译的int的小测试用例.我以为我可以使用deref_iterator自定义点来处理这种情况,或者也许开箱即用的精神会注意到我的容器持有指针类型并进行额外的解引用.无论如何,这是测试用例:

#include <boost/spirit/include/karma.hpp>
#include <boost/shared_ptr.hpp>
#include <vector>

typedef boost::shared_ptr< int > ptr;
typedef std::vector< ptr > vec;

namespace boost {
namespace spirit {
namespace traits {

// specialise how iterators into containers of pointers are dereferenced
template <>
struct deref_iterator< typename container_iterator< vec const >::type >
{
    typedef int type;

    static
    type
    call( typename container_iterator< vec const >::type & it ) {
        return **it;
    }
};

} // namespace traits
} // namespace spirit
} // namespace boost …
Run Code Online (Sandbox Code Playgroud)

c++ boost boost-spirit boost-spirit-karma

3
推荐指数
1
解决办法
563
查看次数

是否可以将动作附加到boost :: spirit :: rule解析器,该解析器将解析后的结果分配给(尚未)未知实例的成员?

我正试图从boost :: spirit规则定义的动作中引用(尚未)未知实例的成员,因此在伪代码中,

而不是double_ [ref(rN)= _1]我正在寻找类似X**ppx的东西; double_ [ref(&X :: rN,ppx)= _1]

它的解决方法可能是一个简单的"语义操作",其中一个参数可以知道实例并且可以写入它,就像

qi::rule<Iterator, Skipper> start;
my_grammar(DataContext*& dataContext) : my_grammar::base_type(start) , execContext(execContext) {
    start = qi::double_[ boost::bind(&my_grammar::newValueForXY, dataContext, ::_1) ];
Run Code Online (Sandbox Code Playgroud)

但是,我想知道是否有可能直接"绑定"到成员变量,就像可以通过使用"phoenix :: ref(...)= value"绑定到"本地"变量一样.

我尝试了以下语法:

start = qi::int_[ boost::bind<int&>(&DataContext::newValueForXY, boost::ref(dataContext))() = ::_1] ];
Run Code Online (Sandbox Code Playgroud)

但是VS2010SP1和错误消息失败了

错误C2440:'=':'boost :: arg'无法转换为...

c++ reference boost-bind boost-spirit boost-spirit-qi

3
推荐指数
1
解决办法
1701
查看次数

内部编译器错误,同时使用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能够编译它,并且解析器的工作原理如何.

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

c++ boost-spirit c++14 boost-spirit-x3

3
推荐指数
1
解决办法
170
查看次数

将解析序列的每个元素传递给返回规则属性类型的函数

我想解析CSS颜色函数(为简单起见,所有参数都是0到255之间的数字)

rgb(r,g,b)
rgba(r,g,b,a)
hsl(h,s,l)
hsla(h,s,l,a)
Run Code Online (Sandbox Code Playgroud)

struct color
{
    color(std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint8_t a) : red{r}, green{g}, blue{b}, alpha{a} {}
    static color hsl(std::uint8_t h, std::uint8_t s, std::uint8_t l, std::uint8_t a) { ... }
    std::uint8_t red;
    std::uint8_t green;
    std::uint8_t blue;
    std::uint8_t alpha;
}
Run Code Online (Sandbox Code Playgroud)

我有一个工作hsl函数实现,它将h,s和l转换为rgb值.

我还要rule处理前两个函数:

constexpr auto uint8 = uint_parser<std::uint8_t>{};
const auto color_rgb = rule<struct rgb, color>{"rgb"}
                     = lit("rgb") >> '(' >> uint8 >> ',' >> uint8 >> ',' >> uint8 >> ')' >> …
Run Code Online (Sandbox Code Playgroud)

css c++ boost-spirit boost-spirit-x3 c++17

3
推荐指数
1
解决办法
102
查看次数