<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Boost Spirit Qi Parser]]></title><description><![CDATA[<p>Vielleicht hat jemand eine Idee mir zu helfen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p>Ich hab eine Qi Parser aus dem Boost Spirit 2.3.</p>
<pre><code class="language-cpp">start = (string_literal &gt;&gt; bool_literal) [bind(zombie_test)];
</code></pre>
<p>string_literal ist eine Zeichenkette in der From: 'ab' (mind 2 Stellig).<br />
bool_literal ist true und false.</p>
<p>Beide Literale werden werden vom dem Spirit Lex an dem Parser weiter gereicht ( ich sag's weil der Artikel im Magazin kein Scanner verwendet).</p>
<p>Die Zombie-Funktion schreibt einfach in die Ausgabe, was sie erkannt hat.</p>
<p>Ledenfalls wird die Funktion nicht ausgelöst in der Form.</p>
<p>Wie auch immer wenn ich die &gt;&gt;(Konkatenation) durch |(Oder) ersetzte, werden Bools und Strings ohne Probleme erkannt.</p>
<p>Danke.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/269921/boost-spirit-qi-parser</link><generator>RSS for Node</generator><lastBuildDate>Sun, 30 Aug 2026 19:02:56 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/269921.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 03 Jul 2010 19:01:08 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Boost Spirit Qi Parser on Sat, 03 Jul 2010 19:01:08 GMT]]></title><description><![CDATA[<p>Vielleicht hat jemand eine Idee mir zu helfen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p>Ich hab eine Qi Parser aus dem Boost Spirit 2.3.</p>
<pre><code class="language-cpp">start = (string_literal &gt;&gt; bool_literal) [bind(zombie_test)];
</code></pre>
<p>string_literal ist eine Zeichenkette in der From: 'ab' (mind 2 Stellig).<br />
bool_literal ist true und false.</p>
<p>Beide Literale werden werden vom dem Spirit Lex an dem Parser weiter gereicht ( ich sag's weil der Artikel im Magazin kein Scanner verwendet).</p>
<p>Die Zombie-Funktion schreibt einfach in die Ausgabe, was sie erkannt hat.</p>
<p>Ledenfalls wird die Funktion nicht ausgelöst in der Form.</p>
<p>Wie auch immer wenn ich die &gt;&gt;(Konkatenation) durch |(Oder) ersetzte, werden Bools und Strings ohne Probleme erkannt.</p>
<p>Danke.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1920901</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1920901</guid><dc:creator><![CDATA[Zeus]]></dc:creator><pubDate>Sat, 03 Jul 2010 19:01:08 GMT</pubDate></item><item><title><![CDATA[Reply to Boost Spirit Qi Parser on Sat, 03 Jul 2010 19:40:58 GMT]]></title><description><![CDATA[<p>Minimalbeispiel:</p>
<pre><code class="language-cpp">#include &lt;boost/spirit/include/lex_lexertl.hpp&gt;
#include &lt;boost/spirit/include/qi.hpp&gt;
#include &lt;boost/spirit/include/phoenix_operator.hpp&gt;
#include &lt;boost/spirit/include/phoenix_statement.hpp&gt;
#include &lt;boost/spirit/include/phoenix_container.hpp&gt;

#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;boost/bind.hpp&gt;
#include &lt;boost/ref.hpp&gt;

using namespace boost::spirit::lex;
using namespace boost::spirit;
using namespace boost::spirit::ascii;

template&lt;class Lexer&gt; struct rules : lexer&lt;Lexer&gt; {
	rules() {												
		this-&gt;self.add_pattern(&quot;STRING_LITERAL&quot;, &quot;\\'([A-Za-z]|[0-9])([A-Za-z]|[0-9])+\\'&quot;);
		this-&gt;self.add_pattern(&quot;TRUE_LITERAL&quot;, &quot;true&quot;);
		this-&gt;self.add_pattern(&quot;FALSE_LITERAL&quot;, &quot;false&quot;);

		string_literal = &quot;{STRING_LITERAL}&quot;;
		true_literal = &quot;{TRUE_LITERAL}&quot;;
		false_literal = &quot;{FALSE_LITERAL}&quot;;

		this-&gt;self.add(string_literal);				
		this-&gt;self.add(true_literal);
		this-&gt;self.add(false_literal);	

	}
	token_def&lt;std::string&gt; string_literal, true_literal, false_literal;
};

void zombie_string() { std::cout &lt;&lt; &quot;string&quot; &lt;&lt; std::endl; }
void zombie_bool() { std::cout &lt;&lt; &quot;bool&quot; &lt;&lt; std::endl; }
void zombie_end() { std::cout &lt;&lt; &quot;end&quot; &lt;&lt; std::endl; }

template&lt;class Iterator&gt; struct grammar : qi::grammar&lt;Iterator&gt;
{
	template&lt;class TokenDefinition&gt;
	grammar(const TokenDefinition&amp; td) : grammar::base_type(start)
	{
		using boost::bind;

		string_literal				=	td.string_literal						[bind(zombie_string)]		;
		true_literal				=	td.true_literal									;
		false_literal				=	td.false_literal								;
		bool_literal				=	(false_literal | true_literal)			[bind(zombie_bool)]			;

		start						=	(string_literal &gt;&gt; bool_literal)		[bind(zombie_end)]			;
	}			

	qi::rule&lt;Iterator&gt; string_literal, bool_literal, true_literal, false_literal;
	qi::rule&lt;Iterator&gt; start;
};

int main() {
	typedef lexertl::token&lt;char const*, boost::mpl::vector&lt;std::string&gt; &gt; token_type;
	typedef lexertl::lexer&lt;token_type&gt; lexer_type;
	typedef rules&lt;lexer_type&gt;::iterator_type iterator_type;

	rules&lt;lexer_type&gt; lexer;
	grammar&lt;iterator_type&gt; parser(lexer);

	while(true) {
		std::string input;
		std::cin &gt;&gt; input;

		char const* first = input.c_str();
		char const* last = &amp;first[input.size()];

		tokenize_and_parse(first, last, lexer, parser);
	}
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1920913</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1920913</guid><dc:creator><![CDATA[Zeus]]></dc:creator><pubDate>Sat, 03 Jul 2010 19:40:58 GMT</pubDate></item><item><title><![CDATA[Reply to Boost Spirit Qi Parser on Sun, 04 Jul 2010 00:26:04 GMT]]></title><description><![CDATA[<p>Spirit Regeln (rules) verhalten sich anders in Abhängigkeit davon, ob der Ausdruck auf der rechten Seite semantische Aktionen hat oder nicht. Wenn keine semantischen Aktionen vorhanden sind, verhält sich die Regel so, als ob die rechte Seite mit operator%= zugewiesen worden wäre, also das Attribute der linken Seite automatisch an die rechte Seite 'weitergereicht' wird. Sobald semantische Aktionen ins Spiel kommen, wird dieser 'Auto-Mechanismus' ausgeschaltet.</p>
<p>Aus diesem Grund scheint der Ausdruck</p>
<pre><code class="language-cpp">qi::rule&lt;Iterator&gt; start = (string_literal &gt;&gt; bool_literal) [...]
</code></pre>
<p>kein Resultat zu liefern.</p>
<p>Weiterhin mußt Du den Instanzen der Regeln sagen, welchen Attribut-Typ diese 'liefern'. Also z.B.</p>
<pre><code class="language-cpp">qi::rule&lt;Iterator, std::string()&gt; string_literal = td.string_literal;
</code></pre>
<p>Wenn Du trotz semantischer Aktionen das Attribut durchreichen willst, müssen alle Zuweisungen mittels %= erfolgen.</p>
<p>Regards Hartmut</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1921020</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1921020</guid><dc:creator><![CDATA[hkaiser]]></dc:creator><pubDate>Sun, 04 Jul 2010 00:26:04 GMT</pubDate></item><item><title><![CDATA[Reply to Boost Spirit Qi Parser on Sun, 04 Jul 2010 09:51:12 GMT]]></title><description><![CDATA[<p>Danke für die Hinweise. Ich werd's mit wohl an ein kalteren Tagen nochmal ansehen.</p>
<p>Erstaml geht es mir um die richtige und tatsächliche Reihenfolge der semantischen Aktionen. Es macht mich nur bisschen stutzig, weil ein anderes Programm genauso aufgebaut ist, allerdings verhält es sich korrekt, wie erwartet.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;string&gt;

#include &lt;boost/spirit/include/lex_lexertl.hpp&gt;
#include &lt;boost/spirit/include/qi.hpp&gt;
#include &lt;boost/spirit/include/phoenix_operator.hpp&gt;
#include &lt;boost/spirit/include/phoenix_statement.hpp&gt;
#include &lt;boost/spirit/include/phoenix_container.hpp&gt;
#include &lt;boost/bind.hpp&gt;
#include &lt;boost/ref.hpp&gt; 

using namespace boost::spirit;
using namespace boost::spirit::lex;
using namespace boost::spirit::ascii;

template&lt;class Lexer&gt; struct rules : lexer&lt;Lexer&gt; {
	rules() {
		this-&gt;self.add_pattern(&quot;DIGIT&quot;, &quot;[0-9]&quot;);
		this-&gt;self.add_pattern(&quot;PREFIX&quot;, &quot;[-|+]&quot;);

		digit	= &quot;{DIGIT}&quot;;
		prefix = &quot;{PREFIX}&quot;;

		this-&gt;self.add(digit);
		this-&gt;self.add(prefix);

	}

	lex::token_def&lt;std::string&gt; digit, prefix;
};

void m_digit() { std::cout &lt;&lt; &quot;digit&quot; &lt;&lt; std::endl; }
void m_prefix() {std::cout &lt;&lt; &quot;prefix&quot; &lt;&lt; std::endl;}
void m_pair() {std::cout &lt;&lt; &quot;pair&quot; &lt;&lt; std::endl;}
void m_end() {std::cout &lt;&lt; &quot;end&quot; &lt;&lt; std::endl;}

template&lt;class Iterator&gt; struct grammar : qi::grammar&lt;Iterator&gt; {

	template&lt;class TokenDefinition&gt;
	grammar(const TokenDefinition&amp; td) : grammar::base_type(start) {
		using boost::bind;				

		prefix		=		td.prefix								[bind(m_prefix)]	;
		digit		=		td.digit								[bind(m_digit)]		;
		pair		=		(prefix &gt;&gt; digit)						[bind(m_pair)]		;
		start		=		pair									[bind(m_end)]		;
	}			
	qi::rule&lt;Iterator&gt; start, pair ,digit, prefix;
};

int main() {
	typedef lexertl::token&lt;char const*, boost::mpl::vector&lt;std::string&gt; &gt; token_type;
	typedef lexertl::lexer&lt;token_type&gt; lexer_type;
	typedef rules&lt;lexer_type&gt;::iterator_type iterator_type;

	rules&lt;lexer_type&gt; my_lexer;
	grammar&lt;iterator_type&gt; my_parser(my_lexer);

	while(true) {
		std::string input;
		std::cin &gt;&gt; input;

		char const* first = input.c_str();
		char const* last = &amp;first[input.size()];

		lex::tokenize_and_parse(first, last, my_lexer, my_parser);

	}
	std::cin.get();
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1921062</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1921062</guid><dc:creator><![CDATA[Zeus]]></dc:creator><pubDate>Sun, 04 Jul 2010 09:51:12 GMT</pubDate></item><item><title><![CDATA[Reply to Boost Spirit Qi Parser on Sun, 04 Jul 2010 17:28:57 GMT]]></title><description><![CDATA[<p>Kannst Du bitte an Hand einer konkreten Eingabe-Zeichenkette zeigen, welches Ergebnis Du siehst und was Du eigentlich sehen wolltest?</p>
<p>Regards Hartmut</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1921228</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1921228</guid><dc:creator><![CDATA[hkaiser]]></dc:creator><pubDate>Sun, 04 Jul 2010 17:28:57 GMT</pubDate></item><item><title><![CDATA[Reply to Boost Spirit Qi Parser on Sun, 04 Jul 2010 17:37:16 GMT]]></title><description><![CDATA[<p>Ja gern <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p>1. Version<br />
Eingabe:<br />
'Hallo' true</p>
<p>Ausgabe:<br />
string</p>
<p>Erwartet:<br />
string<br />
bool<br />
end</p>
<p>2. Version<br />
Eingabe:<br />
+1</p>
<p>Ausgabe:<br />
prefix<br />
digit<br />
pair<br />
end</p>
<p>Erwartet:<br />
prefix<br />
digit<br />
pair<br />
end</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1921231</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1921231</guid><dc:creator><![CDATA[Zeus]]></dc:creator><pubDate>Sun, 04 Jul 2010 17:37:16 GMT</pubDate></item><item><title><![CDATA[Reply to Boost Spirit Qi Parser on Sun, 04 Jul 2010 20:08:22 GMT]]></title><description><![CDATA[<p>Zeus schrieb:</p>
<blockquote>
<p>Ja gern <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p>1. Version<br />
Eingabe:<br />
'Hallo' true</p>
<p>Ausgabe:<br />
string</p>
<p>Erwartet:<br />
string<br />
bool<br />
end</p>
</blockquote>
<p>Wenn Du das Leerzeichen zwischen 'Hallo' und true wegläßt, dann bekommst Du die erwartete Ausgabe. Weder der Lexer, noch der Parser wissen etwas über ein einzelnes (oder auch mehrere) Leerzeichen, Deine Eingabe kann also nicht 'gematched' werden. Der Rückgabewert von lex::tokenize_and_parse is false (der Parser liefert diesen Fehler), zusätzlich ist nach dem Aufruf von tokenize_and_parse first != last, was darauf hinweist, daß die Eingabe nicht vollständig verarbeitet wurde.</p>
<p>Zeus schrieb:</p>
<blockquote>
<p>2. Version<br />
Eingabe:<br />
+1</p>
<p>Ausgabe:<br />
prefix<br />
digit<br />
pair<br />
end</p>
<p>Erwartet:<br />
prefix<br />
digit<br />
pair<br />
end</p>
</blockquote>
<p>Hier stimmt ja alles <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61b.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_tongue"
      title=":-P"
      alt="😛"
    /></p>
<p>Regards Hartmut</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1921281</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1921281</guid><dc:creator><![CDATA[hkaiser]]></dc:creator><pubDate>Sun, 04 Jul 2010 20:08:22 GMT</pubDate></item><item><title><![CDATA[Reply to Boost Spirit Qi Parser on Sun, 04 Jul 2010 21:10:20 GMT]]></title><description><![CDATA[<p>Hmm ok,... *peinlich wegrennen*</p>
<p>In der Tat hab ich die Whitespaces nicht mehr gedacht. Ich weiß, wie ich die Sachen im Lexergenerator Flex einstellen, einfach eine leere Regeln ohne Aktion. Wie ist ein Spirit.Lex, ich hab ein wenig probiert und in die Dokumentation nachgesehen erstmal ohne Erfolg. Geht das nur mit eine Skip Grammar?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1921300</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1921300</guid><dc:creator><![CDATA[Zeus]]></dc:creator><pubDate>Sun, 04 Jul 2010 21:10:20 GMT</pubDate></item><item><title><![CDATA[Reply to Boost Spirit Qi Parser on Mon, 05 Jul 2010 15:15:51 GMT]]></title><description><![CDATA[<p>Zeus schrieb:</p>
<blockquote>
<p>In der Tat hab ich die Whitespaces nicht mehr gedacht. Ich weiß, wie ich die Sachen im Lexergenerator Flex einstellen, einfach eine leere Regeln ohne Aktion. Wie ist ein Spirit.Lex, ich hab ein wenig probiert und in die Dokumentation nachgesehen erstmal ohne Erfolg. Geht das nur mit eine Skip Grammar?</p>
</blockquote>
<p>Am einfachsten ist es wohl, dem Lexer zu sagen bestimmte Tokens zu ignorieren:</p>
<pre><code class="language-cpp">template&lt;class Lexer&gt; struct rules : lexer&lt;Lexer&gt; 
{
    rules() {
        using lex::_pass;
        using lex::pass_flags;

        this-&gt;self.add_pattern(&quot;DIGIT&quot;, &quot;[0-9]&quot;);
        this-&gt;self.add_pattern(&quot;PREFIX&quot;, &quot;[-|+]&quot;);

        digit    = &quot;{DIGIT}&quot;;
        prefix = &quot;{PREFIX}&quot;;
        ws = &quot;[ \t\n]&quot;;

        this-&gt;self.add(digit);
        this-&gt;self.add(prefix);
        this-&gt;self += ws [_pass = pass_flags::pass_ignore];
    }

    lex::token_def&lt;std::string&gt; digit, prefix;
    lex::token_def&lt;&gt; ws;
};
</code></pre>
<p>Die einzige Besonderheit ist, daß der verwendete Lexer vom Typ</p>
<pre><code class="language-cpp">lex::lexertl::actor_lexer&lt;token_type&gt;
</code></pre>
<p>sein muß (ansonsten bekommst Du auf Grund der semantischen Aktion mehrere Compiler-Fehler).</p>
<p>Regards Hartmut</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1921731</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1921731</guid><dc:creator><![CDATA[hkaiser]]></dc:creator><pubDate>Mon, 05 Jul 2010 15:15:51 GMT</pubDate></item><item><title><![CDATA[Reply to Boost Spirit Qi Parser on Mon, 05 Jul 2010 16:49:00 GMT]]></title><description><![CDATA[<p><div class="plugin-markdown"><input type="checkbox" id="checkbox78193" checked="true" /><label for="checkbox78193">angeben, geht es ohne Probleme. Dann wird eine Eingabe +x1 wie erwartet geparst (halt als ob das x nie dort stände).</label></div></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1921775</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1921775</guid><dc:creator><![CDATA[Zeus]]></dc:creator><pubDate>Mon, 05 Jul 2010 16:49:00 GMT</pubDate></item><item><title><![CDATA[Reply to Boost Spirit Qi Parser on Mon, 05 Jul 2010 17:52:12 GMT]]></title><description><![CDATA[<p>Zeus schrieb:</p>
<blockquote>
<p><div class="plugin-markdown"><input type="checkbox" id="checkbox78194" checked="true" /><label for="checkbox78194">angeben, geht es ohne Probleme. Dann wird eine Eingabe +x1 wie erwartet geparst (halt als ob das x nie dort stände).</label></div></p>
</blockquote>
<p>Bitte stelle mir das vollständige Programm zur Verfügung, ich schau es mir dann an.</p>
<p>Regards Hartmut</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1921801</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1921801</guid><dc:creator><![CDATA[hkaiser]]></dc:creator><pubDate>Mon, 05 Jul 2010 17:52:12 GMT</pubDate></item><item><title><![CDATA[Reply to Boost Spirit Qi Parser on Mon, 05 Jul 2010 18:20:53 GMT]]></title><description><![CDATA[<p>Vielen Danke, dass du dir so viele Mühe mit mir machst <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p>Eingabe sind:<br />
+1 Geht<br />
+ 1 Geht nie</p>
<p><div class="plugin-markdown"><input type="checkbox" id="checkbox78195" checked="true" /><label for="checkbox78195">geht.</label></div></p>
<pre><code class="language-cpp">#include &lt;iostream&gt; 
#include &lt;string&gt; 

#include &lt;boost/spirit/include/lex_lexertl.hpp&gt; 
#include &lt;boost/spirit/include/qi.hpp&gt; 
#include &lt;boost/spirit/include/phoenix_operator.hpp&gt; 
#include &lt;boost/spirit/include/phoenix_statement.hpp&gt; 
#include &lt;boost/spirit/include/phoenix_container.hpp&gt; 
#include &lt;boost/bind.hpp&gt; 
#include &lt;boost/ref.hpp&gt; 

using namespace boost::spirit; 
using namespace boost::spirit::lex; 
using namespace boost::spirit::ascii; 

template&lt;class Lexer&gt; struct rules : lexer&lt;Lexer&gt; 
{ 
	rules() { 
		using lex::_pass; 
		using lex::pass_flags; 

		this-&gt;self.add_pattern(&quot;DIGIT&quot;, &quot;[0-9]&quot;); 
		this-&gt;self.add_pattern(&quot;PREFIX&quot;, &quot;[-|+]&quot;); 

		digit    = &quot;{DIGIT}&quot;; 
		prefix = &quot;{PREFIX}&quot;; 

		//ws = &quot;[ ]&quot;; // Geht nicht
		//ws = &quot;[\\ ]&quot;; // Geht nicht
		//ws = &quot;[\\\x20]&quot;; // Geht nicht
		//ws = &quot;[\x20]&quot;; // Geht nicht 

		ws = &quot;[ \t\n]&quot;; // Geht nicht
		//ws = &quot;[x]&quot;;  // Geht

		this-&gt;self.add(digit); 
		this-&gt;self.add(prefix); 
		this-&gt;self += ws [_pass = pass_flags::pass_ignore]; 
	} 

	lex::token_def&lt;std::string&gt; digit, prefix; 
	lex::token_def&lt;&gt; ws; 
};

void m_digit() { std::cout &lt;&lt; &quot;digit&quot; &lt;&lt; std::endl; } 
void m_prefix() {std::cout &lt;&lt; &quot;prefix&quot; &lt;&lt; std::endl;} 
void m_pair() {std::cout &lt;&lt; &quot;pair&quot; &lt;&lt; std::endl;} 
void m_end() {std::cout &lt;&lt; &quot;end&quot; &lt;&lt; std::endl;} 

template&lt;class Iterator&gt; struct grammar : qi::grammar&lt;Iterator&gt; { 

	template&lt;class TokenDefinition&gt; 
	grammar(const TokenDefinition&amp; td) : grammar::base_type(start) { 
		using boost::bind;                

		prefix        =        td.prefix                                [bind(m_prefix)]    ; 
		digit        =        td.digit                                [bind(m_digit)]        ; 
		pair        =        (prefix &gt;&gt; digit)                        [bind(m_pair)]        ; 
		start        =        pair                                    [bind(m_end)]        ; 
	}            
	qi::rule&lt;Iterator&gt; start, pair ,digit, prefix; 
}; 

int main() { 
	typedef lexertl::token&lt;char const*, boost::mpl::vector&lt;std::string&gt; &gt; token_type; 
	typedef lexertl::actor_lexer&lt;token_type&gt; lexer_type; 
	typedef rules&lt;lexer_type&gt;::iterator_type iterator_type; 

	rules&lt;lexer_type&gt; my_lexer; 
	grammar&lt;iterator_type&gt; my_parser(my_lexer); 

	while(true) { 
		std::string input; 
		std::cin &gt;&gt; input; 

		char const* first = input.c_str(); 
		char const* last = &amp;first[input.size()]; 

		bool b = lex::tokenize_and_parse(first, last, my_lexer, my_parser); 
		std::cout &lt;&lt; &quot;Parser says: &quot; &lt;&lt; b &lt;&lt; std::endl;

	} 
	std::cin.get(); 
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1921830</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1921830</guid><dc:creator><![CDATA[Zeus]]></dc:creator><pubDate>Mon, 05 Jul 2010 18:20:53 GMT</pubDate></item><item><title><![CDATA[Reply to Boost Spirit Qi Parser on Mon, 05 Jul 2010 18:44:04 GMT]]></title><description><![CDATA[<p>Dein Problem liegt hier:</p>
<p>Zeus schrieb:</p>
<blockquote>
<pre><code class="language-cpp">while(true) { 
        std::string input; 
        std::cin &gt;&gt; input; 
        // ...
    }
</code></pre>
</blockquote>
<p>Es muß so aussehen:</p>
<pre><code class="language-cpp">std::string input; 
    std::cin.unsetf(std::ios::skipws);
    while(std::getline(std::cin, input)) 
    { 
        // ...
    }
</code></pre>
<p>Ansonsten spielt Dir der iostream einen Streich und der Lexer/Parser sieht immer nur die Eingabe bis zum nächsten Leerzeichen.</p>
<p>HTH<br />
Regards Hartmut</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1921848</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1921848</guid><dc:creator><![CDATA[hkaiser]]></dc:creator><pubDate>Mon, 05 Jul 2010 18:44:04 GMT</pubDate></item><item><title><![CDATA[Reply to Boost Spirit Qi Parser on Mon, 05 Jul 2010 18:55:42 GMT]]></title><description><![CDATA[<p>Endlich kann ich Spaß mit Spirit haben :&gt;</p>
<p>Danke ^^</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1921855</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1921855</guid><dc:creator><![CDATA[Zeus]]></dc:creator><pubDate>Mon, 05 Jul 2010 18:55:42 GMT</pubDate></item></channel></rss>