<?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[interpreter für polnische notation (zahlen mit mehr als einer stelle)]]></title><description><![CDATA[<p>ich habe einen interpreten für die polnische notation geschrieben.<br />
soweit funktioniert er auch.<br />
nur kann ich zur zeit nur einstelliege operationen und operanden verwenden.</p>
<p>hier schnell meine grammatik als EBNF:</p>
<pre><code>&lt;rechnung&gt; -&gt; &lt;operation&gt;&lt;operand&gt; &lt;operand&gt;
&lt;operand&gt; -&gt; &lt;zahl&gt;|&lt;rechnung&gt;
&lt;operation&gt; -&gt; ^|*|/|+|-
&lt;zahl&gt; -&gt; 0|1|2|3|4|5|6|7|8|9|e
</code></pre>
<p>nun will ich aber die grammatik so erweitern, das ich zahl Element N* machen kann<br />
also als EBNF:</p>
<pre><code>&lt;rechnung&gt; -&gt; &lt;operation&gt;&lt;operand&gt; &lt;operand&gt;
&lt;operand&gt; -&gt; &lt;zahl&gt;|&lt;rechnung&gt;
&lt;operation&gt; -&gt; ^|*|/|+|-
&lt;zahl&gt; -&gt; N*|e
</code></pre>
<p>p.s.: wobei &lt;zahl&gt; der einfachheit halber als Elementensymbol dargestellt ist.</p>
<p>nur habe ich probleme die zahlen dann auszulesen.</p>
<p>hier mein programm. es ist sehr einfach gehalten, da es ein schulprojekt ist und als &quot;lehrprogramm&quot; zur veranschaulichung eingesetzt werden soll.</p>
<pre><code class="language-cpp">const char* string = &quot;-22 2&quot;; 

double rechnung(); 
double operation(); 
double operand(); 
double rechnung(); 

void* doublecat( double* d, char* ch ) 
{ 
  switch( *ch ) 
  { 
    case '0': 
      *d = (*(d) * 10); 
    break; 
    case '1': 
      *d = (*(d) * 10) + 1; 
    break; 
    case '2': 
      *d = (*(d) * 10) + 2; 
    break; 
    case '3': 
      *d = (*(d) * 10) + 3; 
    break; 
    case '4': 
      *d = (*(d) * 10) + 4; 
    break; 
    case '5': 
      *d = (*(d) * 10) + 5; 
    break; 
    case '6': 
      *d = (*(d) * 10) + 6; 
    break; 
    case '7': 
      *d = (*(d) * 10) + 7; 
    break; 
    case '8': 
      *d = (*(d) * 10) + 8; 
    break; 
    case '9': 
      *d = (*(d) * 10) + 9; 
    break; 
  } 

  return NULL; 
} 

char getNextChar() 
/* gibt das nächste zeichen in der kette zurück */ 
{ 
  if( *(string + pos_counter) != '\0' ) 
    return *(string + pos_counter++); 
  else 
    return '\0'; 
} 

double operation() 
{ 
  if( MATH_ERROR || SYNTAX_ERROR ) 
    return 0.0f; 

  double op[2]; 

  if( pos_counter &gt; 0 ) 
    pos_counter--; 

  c = getNextChar(); 

  printf( &quot;OPERATION\t[%s]\t\t(%i)\n&quot;, &amp;c, pos_counter ); 

  if( c == '\0' ) 
    return 0.0f; 

  switch( c ) 
  { 
    case '^': 
      op[0] = operand();  pos_counter++; 

      if( op[0] == 0 ) 
        return 0.0f; 

      op[1] = operand(); 

      if( op[1] == 0.0f ) 
          return 1.0f; 
      else 
      { 
        if( op[1] == 1.0f ) 
          return op[0]; 
        else 
          return pow( op[0], op[1] ); 
      } 
    break; 
    case '*': 
      op[0] = operand();  pos_counter++; 
      op[1] = operand(); 
      return ((double) op[0] * (double) op[1]); 
    break; 
    case '/': 
      op[0] = operand();  pos_counter++; 

      if( op[0] == 0 ) 
      { 
        pos_counter++; 
        return 0.0f; 
      } 

      op[1] = operand(); 

      if( op[1] == 0 ) 
      { 
        MATH_ERROR = true; 
        return 0.0f; 
      } 
      else 
        return ((double) op[0] / (double) op[1]); 
    break; 
    case '+': 
      op[0] = operand();  pos_counter++; 
      op[1] = operand(); 
      return ((double) op[0] + (double) op[1]); 
    break; 
    case '-': 
      op[0] = operand();  pos_counter++; 
      op[1] = operand(); 
      return ((double) op[0] - (double) op[1]); 
    break; 
    default: 
      SYNTAX_ERROR = true; 
      return 0.0f; 
    break; 
  } 
} 

double operand() 
{ 
  if( MATH_ERROR || SYNTAX_ERROR ) 
    return 0.0; 

  double tmp = 0; 

  c = getNextChar(); 

  printf( &quot;OPERAND\t\t[%s]\t\t(%i)\n&quot;, &amp;c, pos_counter ); 

  if( c == '\0' ) 
    return false; 

  switch( c ) 
  { 
    case '0': 
    case '1': 
    case '2': 
    case '3': 
    case '4': 
    case '5': 
    case '6': 
    case '7': 
    case '8': 
    case '9': 
      doublecat( &amp;tmp, &amp;c ); 
      return tmp; 
    break; 
    case 'e': 
      return 2.718281828; 
    break; 
    default: 
      return rechnung(); 
    break; 
  } 
} 

double rechnung() 
{ 
  if( MATH_ERROR || SYNTAX_ERROR ) 
    return 0.0f; 

  printf( &quot;RECHNUNG\t[%s]\t\t(%i)\n&quot;, &amp;c, pos_counter ); 

  if( c == '\0' ) 
  { 
    SYNTAX_ERROR = true; 
    return 0; 
  } 

  return operation(); 
}
</code></pre>
<p>nur fällt mir nichts ein, wie ich die zahlen mehrstellig machen kann und dann als weiter erweiterung noch Zahlen von R+.</p>
<p>ich bin dankbar für jede hilfe.<br />
Danke im voraus.<br />
Uni_Sol</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/133417/interpreter-für-polnische-notation-zahlen-mit-mehr-als-einer-stelle</link><generator>RSS for Node</generator><lastBuildDate>Thu, 27 Aug 2026 22:39:05 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/133417.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 17 Jan 2006 16:28:35 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to interpreter für polnische notation (zahlen mit mehr als einer stelle) on Tue, 17 Jan 2006 16:28:35 GMT]]></title><description><![CDATA[<p>ich habe einen interpreten für die polnische notation geschrieben.<br />
soweit funktioniert er auch.<br />
nur kann ich zur zeit nur einstelliege operationen und operanden verwenden.</p>
<p>hier schnell meine grammatik als EBNF:</p>
<pre><code>&lt;rechnung&gt; -&gt; &lt;operation&gt;&lt;operand&gt; &lt;operand&gt;
&lt;operand&gt; -&gt; &lt;zahl&gt;|&lt;rechnung&gt;
&lt;operation&gt; -&gt; ^|*|/|+|-
&lt;zahl&gt; -&gt; 0|1|2|3|4|5|6|7|8|9|e
</code></pre>
<p>nun will ich aber die grammatik so erweitern, das ich zahl Element N* machen kann<br />
also als EBNF:</p>
<pre><code>&lt;rechnung&gt; -&gt; &lt;operation&gt;&lt;operand&gt; &lt;operand&gt;
&lt;operand&gt; -&gt; &lt;zahl&gt;|&lt;rechnung&gt;
&lt;operation&gt; -&gt; ^|*|/|+|-
&lt;zahl&gt; -&gt; N*|e
</code></pre>
<p>p.s.: wobei &lt;zahl&gt; der einfachheit halber als Elementensymbol dargestellt ist.</p>
<p>nur habe ich probleme die zahlen dann auszulesen.</p>
<p>hier mein programm. es ist sehr einfach gehalten, da es ein schulprojekt ist und als &quot;lehrprogramm&quot; zur veranschaulichung eingesetzt werden soll.</p>
<pre><code class="language-cpp">const char* string = &quot;-22 2&quot;; 

double rechnung(); 
double operation(); 
double operand(); 
double rechnung(); 

void* doublecat( double* d, char* ch ) 
{ 
  switch( *ch ) 
  { 
    case '0': 
      *d = (*(d) * 10); 
    break; 
    case '1': 
      *d = (*(d) * 10) + 1; 
    break; 
    case '2': 
      *d = (*(d) * 10) + 2; 
    break; 
    case '3': 
      *d = (*(d) * 10) + 3; 
    break; 
    case '4': 
      *d = (*(d) * 10) + 4; 
    break; 
    case '5': 
      *d = (*(d) * 10) + 5; 
    break; 
    case '6': 
      *d = (*(d) * 10) + 6; 
    break; 
    case '7': 
      *d = (*(d) * 10) + 7; 
    break; 
    case '8': 
      *d = (*(d) * 10) + 8; 
    break; 
    case '9': 
      *d = (*(d) * 10) + 9; 
    break; 
  } 

  return NULL; 
} 

char getNextChar() 
/* gibt das nächste zeichen in der kette zurück */ 
{ 
  if( *(string + pos_counter) != '\0' ) 
    return *(string + pos_counter++); 
  else 
    return '\0'; 
} 

double operation() 
{ 
  if( MATH_ERROR || SYNTAX_ERROR ) 
    return 0.0f; 

  double op[2]; 

  if( pos_counter &gt; 0 ) 
    pos_counter--; 

  c = getNextChar(); 

  printf( &quot;OPERATION\t[%s]\t\t(%i)\n&quot;, &amp;c, pos_counter ); 

  if( c == '\0' ) 
    return 0.0f; 

  switch( c ) 
  { 
    case '^': 
      op[0] = operand();  pos_counter++; 

      if( op[0] == 0 ) 
        return 0.0f; 

      op[1] = operand(); 

      if( op[1] == 0.0f ) 
          return 1.0f; 
      else 
      { 
        if( op[1] == 1.0f ) 
          return op[0]; 
        else 
          return pow( op[0], op[1] ); 
      } 
    break; 
    case '*': 
      op[0] = operand();  pos_counter++; 
      op[1] = operand(); 
      return ((double) op[0] * (double) op[1]); 
    break; 
    case '/': 
      op[0] = operand();  pos_counter++; 

      if( op[0] == 0 ) 
      { 
        pos_counter++; 
        return 0.0f; 
      } 

      op[1] = operand(); 

      if( op[1] == 0 ) 
      { 
        MATH_ERROR = true; 
        return 0.0f; 
      } 
      else 
        return ((double) op[0] / (double) op[1]); 
    break; 
    case '+': 
      op[0] = operand();  pos_counter++; 
      op[1] = operand(); 
      return ((double) op[0] + (double) op[1]); 
    break; 
    case '-': 
      op[0] = operand();  pos_counter++; 
      op[1] = operand(); 
      return ((double) op[0] - (double) op[1]); 
    break; 
    default: 
      SYNTAX_ERROR = true; 
      return 0.0f; 
    break; 
  } 
} 

double operand() 
{ 
  if( MATH_ERROR || SYNTAX_ERROR ) 
    return 0.0; 

  double tmp = 0; 

  c = getNextChar(); 

  printf( &quot;OPERAND\t\t[%s]\t\t(%i)\n&quot;, &amp;c, pos_counter ); 

  if( c == '\0' ) 
    return false; 

  switch( c ) 
  { 
    case '0': 
    case '1': 
    case '2': 
    case '3': 
    case '4': 
    case '5': 
    case '6': 
    case '7': 
    case '8': 
    case '9': 
      doublecat( &amp;tmp, &amp;c ); 
      return tmp; 
    break; 
    case 'e': 
      return 2.718281828; 
    break; 
    default: 
      return rechnung(); 
    break; 
  } 
} 

double rechnung() 
{ 
  if( MATH_ERROR || SYNTAX_ERROR ) 
    return 0.0f; 

  printf( &quot;RECHNUNG\t[%s]\t\t(%i)\n&quot;, &amp;c, pos_counter ); 

  if( c == '\0' ) 
  { 
    SYNTAX_ERROR = true; 
    return 0; 
  } 

  return operation(); 
}
</code></pre>
<p>nur fällt mir nichts ein, wie ich die zahlen mehrstellig machen kann und dann als weiter erweiterung noch Zahlen von R+.</p>
<p>ich bin dankbar für jede hilfe.<br />
Danke im voraus.<br />
Uni_Sol</p>
]]></description><link>https://www.c-plusplus.net/forum/post/969095</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/969095</guid><dc:creator><![CDATA[bsunisol]]></dc:creator><pubDate>Tue, 17 Jan 2006 16:28:35 GMT</pubDate></item><item><title><![CDATA[Reply to interpreter für polnische notation (zahlen mit mehr als einer stelle) on Tue, 17 Jan 2006 16:45:01 GMT]]></title><description><![CDATA[<p>Frag besser im ANSI C Forum.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/969107</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/969107</guid><dc:creator><![CDATA[.filmor]]></dc:creator><pubDate>Tue, 17 Jan 2006 16:45:01 GMT</pubDate></item><item><title><![CDATA[Reply to interpreter für polnische notation (zahlen mit mehr als einer stelle) on Tue, 17 Jan 2006 16:46:34 GMT]]></title><description><![CDATA[<p>was ist da anders?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/969108</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/969108</guid><dc:creator><![CDATA[bsunisol]]></dc:creator><pubDate>Tue, 17 Jan 2006 16:46:34 GMT</pubDate></item><item><title><![CDATA[Reply to interpreter für polnische notation (zahlen mit mehr als einer stelle) on Tue, 17 Jan 2006 16:51:09 GMT]]></title><description><![CDATA[<p>Alles ;), hier vor allem aber der I/O-Krams.</p>
<p>Ein C++-ler könnte aber auch einfacher Boost.Spirit (quasi Inline-EBNF) verwenden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/969110</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/969110</guid><dc:creator><![CDATA[.filmor]]></dc:creator><pubDate>Tue, 17 Jan 2006 16:51:09 GMT</pubDate></item><item><title><![CDATA[Reply to interpreter für polnische notation (zahlen mit mehr als einer stelle) on Tue, 17 Jan 2006 17:17:44 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>Was ist den die polnische Notation?</p>
<p>chrische</p>
]]></description><link>https://www.c-plusplus.net/forum/post/969131</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/969131</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Tue, 17 Jan 2006 17:17:44 GMT</pubDate></item><item><title><![CDATA[Reply to interpreter für polnische notation (zahlen mit mehr als einer stelle) on Tue, 17 Jan 2006 17:24:24 GMT]]></title><description><![CDATA[<p>chrische5 schrieb:</p>
<blockquote>
<p>Hallo</p>
<p>Was ist den die polnische Notation?</p>
<p>chrische</p>
</blockquote>
<p>hi@wikipedia. ist eine mathematische schreibweise.<br />
das bringt mich aber nicht weiter <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_down"
      title=":-1:"
      alt="👎"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/969138</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/969138</guid><dc:creator><![CDATA[bsunisol]]></dc:creator><pubDate>Tue, 17 Jan 2006 17:24:24 GMT</pubDate></item><item><title><![CDATA[Reply to interpreter für polnische notation (zahlen mit mehr als einer stelle) on Tue, 17 Jan 2006 17:39:18 GMT]]></title><description><![CDATA[<p>Du schreibst nicht, was dein Problem ist. Du hast doch schonmal eine Grammatik in ein Programm umgesetzt, wieso klappt das mit der neuen Grammatik nicht?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/969160</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/969160</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Tue, 17 Jan 2006 17:39:18 GMT</pubDate></item><item><title><![CDATA[Reply to interpreter für polnische notation (zahlen mit mehr als einer stelle) on Tue, 17 Jan 2006 17:49:25 GMT]]></title><description><![CDATA[<p>ihc bin zu doof die zahlen aus zulesen bis der operand zu ende ist....</p>
]]></description><link>https://www.c-plusplus.net/forum/post/969169</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/969169</guid><dc:creator><![CDATA[bsunisol]]></dc:creator><pubDate>Tue, 17 Jan 2006 17:49:25 GMT</pubDate></item><item><title><![CDATA[Reply to interpreter für polnische notation (zahlen mit mehr als einer stelle) on Tue, 17 Jan 2006 17:53:39 GMT]]></title><description><![CDATA[<p>Vielleicht solltest du mal den doublecat Krams in ne while Schleife packen:</p>
<pre><code class="language-cpp">void doublecat( double* d, char* ch )
{
 while (*ch != '\0' &amp;&amp; *ch != ' ')
  switch( *ch )
  {
    case '0':
      *d = (*(d) * 10);
    break;
    case '1':
      *d = (*(d) * 10) + 1;
    break;
    case '2':
      *d = (*(d) * 10) + 2;
    break;
    case '3':
      *d = (*(d) * 10) + 3;
    break;
    case '4':
      *d = (*(d) * 10) + 4;
    break;
    case '5':
      *d = (*(d) * 10) + 5;
    break;
    case '6':
      *d = (*(d) * 10) + 6;
    break;
    case '7':
      *d = (*(d) * 10) + 7;
    break;
    case '8':
      *d = (*(d) * 10) + 8;
    break;
    case '9':
      *d = (*(d) * 10) + 9;
    break;
  }
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/969173</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/969173</guid><dc:creator><![CDATA[.filmor]]></dc:creator><pubDate>Tue, 17 Jan 2006 17:53:39 GMT</pubDate></item><item><title><![CDATA[Reply to interpreter für polnische notation (zahlen mit mehr als einer stelle) on Tue, 17 Jan 2006 20:15:48 GMT]]></title><description><![CDATA[<p>und kurz</p>
<pre><code class="language-cpp">if (*ch &gt;= '0' &amp;&amp; *ch &lt;= '9')
    *d = *d * 10 + (*ch - '0');
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/969311</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/969311</guid><dc:creator><![CDATA[groovemaster]]></dc:creator><pubDate>Tue, 17 Jan 2006 20:15:48 GMT</pubDate></item><item><title><![CDATA[Reply to interpreter für polnische notation (zahlen mit mehr als einer stelle) on Wed, 18 Jan 2006 12:07:36 GMT]]></title><description><![CDATA[<p>hab ich mir auch schon gedacht, aber die funktion kriegt ja nur ein einzelnes zeichen übergeben.</p>
<p>die funktion getNextChar liefert ja nur das nächste char aus der kette.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/969654</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/969654</guid><dc:creator><![CDATA[bsunisol]]></dc:creator><pubDate>Wed, 18 Jan 2006 12:07:36 GMT</pubDate></item><item><title><![CDATA[Reply to interpreter für polnische notation (zahlen mit mehr als einer stelle) on Wed, 18 Jan 2006 12:21:22 GMT]]></title><description><![CDATA[<p>Das Theam hatten wir schon mal. <a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-128696-and-start-is-10.html" rel="nofollow">Hier</a> hatte ich schon mal eine C++-Lösung gepostet.</p>
<p>Gruß<br />
Werner</p>
]]></description><link>https://www.c-plusplus.net/forum/post/969663</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/969663</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Wed, 18 Jan 2006 12:21:22 GMT</pubDate></item></channel></rss>