का स्ट्रिंग मान नहीं मिल रहा है, मैं बूस्ट स्पिरिट के साथ एक छोटी प्रोग्रामिंग भाषा के लिए लेक्सर को लागू करने का प्रयास करता हूं।मुझे टोकन
मैं एक टोकन का मान प्राप्त करने के लिए है और मैं एक bad_get अपवाद:
'को बढ़ावा देने :: bad_get' का एक उदाहरण फेंकने के बाद कहा जाता है को समाप्त
क्या(): बढ़ावा :: bad_get: में विफल रहा है मूल्य को बढ़ावा देने का उपयोग कर पाने :: निरस्त
मैं इस अपवाद प्राप्त हो जब कर रही:
std::string contents = "void";
base_iterator_type first = contents.begin();
base_iterator_type last = contents.end();
SimpleLexer<lexer_type> lexer;
iter = lexer.begin(first, last);
end = lexer.end();
std::cout << "Value = " << boost::get<std::string>(iter->value()) << std::endl;
मेरे एल exer परिभाषित किया गया है कि:
typedef std::string::iterator base_iterator_type;
typedef boost::spirit::lex::lexertl::token<base_iterator_type, boost::mpl::vector<unsigned int, std::string>> Tok;
typedef lex::lexertl::actor_lexer<Tok> lexer_type;
template<typename L>
class SimpleLexer : public lex::lexer<L> {
private:
public:
SimpleLexer() {
keyword_for = "for";
keyword_while = "while";
keyword_if = "if";
keyword_else = "else";
keyword_false = "false";
keyword_true = "true";
keyword_from = "from";
keyword_to = "to";
keyword_foreach = "foreach";
word = "[a-zA-Z]+";
integer = "[0-9]+";
litteral = "...";
left_parenth = '(';
right_parenth = ')';
left_brace = '{';
right_brace = '}';
stop = ';';
comma = ',';
swap = "<>";
assign = '=';
addition = '+';
subtraction = '-';
multiplication = '*';
division = '/';
modulo = '%';
equals = "==";
not_equals = "!=";
greater = '>';
less = '<';
greater_equals = ">=";
less_equals = "<=";
whitespaces = "[ \\t\\n]+";
comments = "\\/\\*[^*]*\\*+([^/*][^*]*\\*+)*\\/";
//Add keywords
this->self += keyword_for | keyword_while | keyword_true | keyword_false | keyword_if | keyword_else | keyword_from | keyword_to | keyword_foreach;
this->self += integer | litteral | word;
this->self += equals | not_equals | greater_equals | less_equals | greater | less ;
this->self += left_parenth | right_parenth | left_brace | right_brace;
this->self += comma | stop;
this->self += assign | swap | addition | subtraction | multiplication | division | modulo;
//Ignore whitespaces and comments
this->self += whitespaces [lex::_pass = lex::pass_flags::pass_ignore];
this->self += comments [lex::_pass = lex::pass_flags::pass_ignore];
}
lex::token_def<std::string> word, litteral, integer;
lex::token_def<lex::omit> left_parenth, right_parenth, left_brace, right_brace;
lex::token_def<lex::omit> stop, comma;
lex::token_def<lex::omit> assign, swap, addition, subtraction, multiplication, division, modulo;
lex::token_def<lex::omit> equals, not_equals, greater, less, greater_equals, less_equals;
//Keywords
lex::token_def<lex::omit> keyword_if, keyword_else, keyword_for, keyword_while, keyword_from, keyword_to, keyword_foreach;
lex::token_def<lex::omit> keyword_true, keyword_false;
//Ignored tokens
lex::token_def<lex::omit> whitespaces;
lex::token_def<lex::omit> comments;
};
टोकन के मूल्य को पाने का कोई और तरीका है?
फिर से पढ़ने पर, मुझे लगता है कि आपके द्वारा निर्दिष्ट 'लेक्स :: omit' टोकन विशेषता प्रकार के रूप में ध्यान दें। ये टोकन _any_ मान डेटा का खुलासा नहीं करेंगे (यहां तक कि इटेटरेटर जोड़े भी नहीं)। यह आपकी समस्या हो सकती है। अन्यथा, मैं टोकन इटरेटर्स के शीर्ष पर क्यूई का उपयोग करके पार्सिंग की सलाह देता हूं: दोनों दुनिया के सर्वश्रेष्ठ प्राप्त करें। – sehe
मैंने सत्यापित किया और दुख की बात यह समस्या नहीं है। मैं केवल बूस्ट :: एक टोकन पर अच्छा प्रकार का उपयोग करता हूं और उसके पास मूल्य होना चाहिए। –