<?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[Parser überliest Token]]></title><description><![CDATA[<p>Tach, ich habe folgende Funktion, die einen Parser für einen kleinen Taschenrechner darstellt:</p>
<pre><code>bool GetToken(std::istream&amp; stream, ccToken&amp; token) {

  char ch;

	do {
		if(!stream.get(ch)) return false;
	} while(isspace(ch) || !isprint(ch));

	if(ch=='=') std::cout &lt;&lt; &quot;YEEHAA&quot; &lt;&lt; std::endl;

	switch(ch) {
		case tokAssign:
    case tokPlus:
		case tokMinus:
		case tokMul:
		case tokDiv:
		case tokPower:
		case tokFaculty:
		case tokLBracket:
		case tokRBracket:
		case tokSemicolon:
		case tokComma:
      {
      	token.tokType = ccTokenType(ch);
      	#ifdef CC_DEBUG
      	std::cout &lt;&lt; &quot;OPERATOR \&quot;&quot; &lt;&lt; char(token.tokType) &lt;&lt; &quot;\&quot;&quot; &lt;&lt; std::endl;
      	#endif
      	return true;
      };
    default:
      {
      	// numeric literal
      	if(isdigit(ch)) {
      		stream.putback(ch);
      		stream &gt;&gt; token.tokNumValue;
          token.tokType = tokNumLiteral;
      		#ifdef CC_DEBUG
      		std::cout &lt;&lt; &quot;NUMBER \&quot;&quot; &lt;&lt; token.tokNumValue &lt;&lt; &quot;\&quot;&quot; &lt;&lt; std::endl;
      		#endif
      		return true;
        };

        // identifier &amp; biult in commands
        /*if(isletter(ch)) {
        	token.tokStrValue = &quot;&quot;;
          stream.putback(ch);
        	while(stream.get(ch) &amp;&amp; isletter(ch)) {
        		//std::cout &lt;&lt; &quot;LESE ZEICHEN &quot; &lt;&lt; ch &lt;&lt; std::endl;
            token.tokStrValue.append(1,ch);
        	};
        	// built in - print
        	if(!strcmp(token.tokStrValue.c_str(), &quot;print&quot;) || !strcmp(token.tokStrValue.c_str(), &quot;define&quot;)) {
            if(!strcmp(token.tokStrValue.c_str(), &quot;print&quot;)) {
              token.tokType = tokPrint;
              #ifdef CC_DEBUG
              std::cout &lt;&lt; &quot;BUILT IN \&quot;&quot; &lt;&lt; token.tokStrValue &lt;&lt; &quot;\&quot;&quot; &lt;&lt; std::endl;
              #endif
              return true;
            };
            if(!strcmp(token.tokStrValue.c_str(), &quot;define&quot;)) {
              token.tokType = tokDefine;
              #ifdef CC_DEBUG
              std::cout &lt;&lt; &quot;BUILT IN \&quot;&quot; &lt;&lt; token.tokStrValue &lt;&lt; &quot;\&quot;&quot; &lt;&lt; std::endl;
              #endif
              return true;
            };
        	}
        	else {
        		token.tokType = tokIdentifier;
            #ifdef CC_DEBUG
            std::cout &lt;&lt; &quot;IDENTIFIER \&quot;&quot; &lt;&lt; token.tokStrValue &lt;&lt; &quot;\&quot;&quot; &lt;&lt; std::endl;
            #endif
            return true;
        	};
        };*/
      };
  };
  std::cout &lt;&lt; &quot;FALSCHES ZEICHEN GEFUNDEN &quot; &lt;&lt; ch &lt;&lt; &quot; &quot; &lt;&lt; stream.tellg() &lt;&lt;std::endl;
}
</code></pre>
<p>Aus mir nicht nachvollziehbaren Gründen überliest diese aber (wenn der entsprechende Code auskommentiert ist) das ASSIGN Token. Ich verstehe einfach nicht warum??? In dem Zustand wie oben funktioniert sie einwandfrei, erkennt nur eben keine IDENTIFIER und BUILTINs. Ich finde den Fehler einfach nicht!</p>
<p>MfG</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/125995/parser-überliest-token</link><generator>RSS for Node</generator><lastBuildDate>Thu, 16 Apr 2026 19:58:27 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/125995.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 10 Nov 2005 22:34:26 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Parser überliest Token on Thu, 10 Nov 2005 22:34:26 GMT]]></title><description><![CDATA[<p>Tach, ich habe folgende Funktion, die einen Parser für einen kleinen Taschenrechner darstellt:</p>
<pre><code>bool GetToken(std::istream&amp; stream, ccToken&amp; token) {

  char ch;

	do {
		if(!stream.get(ch)) return false;
	} while(isspace(ch) || !isprint(ch));

	if(ch=='=') std::cout &lt;&lt; &quot;YEEHAA&quot; &lt;&lt; std::endl;

	switch(ch) {
		case tokAssign:
    case tokPlus:
		case tokMinus:
		case tokMul:
		case tokDiv:
		case tokPower:
		case tokFaculty:
		case tokLBracket:
		case tokRBracket:
		case tokSemicolon:
		case tokComma:
      {
      	token.tokType = ccTokenType(ch);
      	#ifdef CC_DEBUG
      	std::cout &lt;&lt; &quot;OPERATOR \&quot;&quot; &lt;&lt; char(token.tokType) &lt;&lt; &quot;\&quot;&quot; &lt;&lt; std::endl;
      	#endif
      	return true;
      };
    default:
      {
      	// numeric literal
      	if(isdigit(ch)) {
      		stream.putback(ch);
      		stream &gt;&gt; token.tokNumValue;
          token.tokType = tokNumLiteral;
      		#ifdef CC_DEBUG
      		std::cout &lt;&lt; &quot;NUMBER \&quot;&quot; &lt;&lt; token.tokNumValue &lt;&lt; &quot;\&quot;&quot; &lt;&lt; std::endl;
      		#endif
      		return true;
        };

        // identifier &amp; biult in commands
        /*if(isletter(ch)) {
        	token.tokStrValue = &quot;&quot;;
          stream.putback(ch);
        	while(stream.get(ch) &amp;&amp; isletter(ch)) {
        		//std::cout &lt;&lt; &quot;LESE ZEICHEN &quot; &lt;&lt; ch &lt;&lt; std::endl;
            token.tokStrValue.append(1,ch);
        	};
        	// built in - print
        	if(!strcmp(token.tokStrValue.c_str(), &quot;print&quot;) || !strcmp(token.tokStrValue.c_str(), &quot;define&quot;)) {
            if(!strcmp(token.tokStrValue.c_str(), &quot;print&quot;)) {
              token.tokType = tokPrint;
              #ifdef CC_DEBUG
              std::cout &lt;&lt; &quot;BUILT IN \&quot;&quot; &lt;&lt; token.tokStrValue &lt;&lt; &quot;\&quot;&quot; &lt;&lt; std::endl;
              #endif
              return true;
            };
            if(!strcmp(token.tokStrValue.c_str(), &quot;define&quot;)) {
              token.tokType = tokDefine;
              #ifdef CC_DEBUG
              std::cout &lt;&lt; &quot;BUILT IN \&quot;&quot; &lt;&lt; token.tokStrValue &lt;&lt; &quot;\&quot;&quot; &lt;&lt; std::endl;
              #endif
              return true;
            };
        	}
        	else {
        		token.tokType = tokIdentifier;
            #ifdef CC_DEBUG
            std::cout &lt;&lt; &quot;IDENTIFIER \&quot;&quot; &lt;&lt; token.tokStrValue &lt;&lt; &quot;\&quot;&quot; &lt;&lt; std::endl;
            #endif
            return true;
        	};
        };*/
      };
  };
  std::cout &lt;&lt; &quot;FALSCHES ZEICHEN GEFUNDEN &quot; &lt;&lt; ch &lt;&lt; &quot; &quot; &lt;&lt; stream.tellg() &lt;&lt;std::endl;
}
</code></pre>
<p>Aus mir nicht nachvollziehbaren Gründen überliest diese aber (wenn der entsprechende Code auskommentiert ist) das ASSIGN Token. Ich verstehe einfach nicht warum??? In dem Zustand wie oben funktioniert sie einwandfrei, erkennt nur eben keine IDENTIFIER und BUILTINs. Ich finde den Fehler einfach nicht!</p>
<p>MfG</p>
]]></description><link>https://www.c-plusplus.net/forum/post/914481</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/914481</guid><dc:creator><![CDATA[_kyle++]]></dc:creator><pubDate>Thu, 10 Nov 2005 22:34:26 GMT</pubDate></item></channel></rss>