Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ boost::spirit::lex-标点符号有问题_C++_Boost_Boost Spirit_Boost Spirit Lex - Fatal编程技术网

C++ boost::spirit::lex-标点符号有问题

C++ boost::spirit::lex-标点符号有问题,c++,boost,boost-spirit,boost-spirit-lex,C++,Boost,Boost Spirit,Boost Spirit Lex,我想创建一个包含“[”或“]”或“&>”等字符序列的lex::token_def 我尝试转义必要的字符: namespace lex = boost::spirit::lex; enum LexerIDs { ID_IDENTIFIER, ID_WHITESPACE, ID_INTEGER, ID_FLOAT, ID_PUNCTUATOR }; template <typename Lexer> struct my_lexer : lex::lexer<Lexer>

我想创建一个包含“[”或“]”或“&>”等字符序列的lex::token_def

我尝试转义必要的字符:

namespace lex = boost::spirit::lex;

enum LexerIDs { ID_IDENTIFIER, ID_WHITESPACE, ID_INTEGER, ID_FLOAT, ID_PUNCTUATOR };

template <typename Lexer>
struct my_lexer : lex::lexer<Lexer>
{
    my_lexer() : punctuator("\[|\]|\(|\)|\.|&>|\*\*|\*|\+|-|~|!|/|%|<<|>>|<|>|<=|>=|==|!=")
    {
        this->self.add(punctuator, ID_PUNCTUATOR);
    }
    lex::token_def<> punctuator;
};
namespace-lex=boost::spirit::lex;
枚举LexerIDs{ID\u标识符、ID\u空格、ID\u整数、ID\u浮点、ID\u标点符号};
模板
struct my_lexer:lex::lexer
{
my|lexer():标点符号(“\[|\]\(|\)\\.&>\*\*\\*\+-| ~~!|/|%| |=|=|=|!=”)
{
此->self.add(标点符号,ID\u标点符号);
}
lex::token_def标点器;
};

但这给了我一些关于无法识别的转义字符的警告&用它来分析字符串会失败。如何正确执行此操作?

您需要额外的转义级别:

my_lexer() : punctuator("\\[|\\]|\\(|\\)|\\.|&>|\\*\\*|\\*|\\+|-|~|!|/|%|<<|>>|<|>|<=|>=|==|!=")
my|lexer():标点符号(“\\[\\\]\\\\(\\\\)\\\\\\\\.&>\\\\*\\\\*\\\\\+\\\\\\\\+-\\\\\\\\\\\\\+-\\\\\\\\\\!\/\\\\\\\%\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

“\\”
是一个字符串文本,包含一个反斜杠,然后lexer构造函数将对其进行解析。

谢谢-就是这样。唯一不幸的是,正则表达式得到了额外一层“模糊处理”@tobislangner如果你能使用c++11,这会有很大帮助。