    <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/">
     <channel>
        <title>ACCU  :: Letter to the Editor</title>
        <link>https://members.accu.org/index.php/articles/2125</link>
        <description>Professionalism in Programming</description>
        <dc:language>en-us</dc:language> 
        <dc:creator>Administrator</dc:creator> 
        <admin:generatorAgent rdf:resource="http://www.xaraya.org" /> 
        <admin:errorReportsTo rdf:resource="mailto:webeditor@accu.org" />
       <sy:updatePeriod>hourly</sy:updatePeriod>
       <sy:updateFrequency>1</sy:updateFrequency>
       <docs>http://backend.userland.com/rss</docs>




<div class="xar-mod-head"><span class="xar-mod-title">Letters to the Editor + CVu Journal Vol 27, #3 - July 2015</span></div>

<table border="0" cellpadding="1" cellspacing="0">
    <tbody>
    <tr>
        <td valign="top">
            Browse in :
       </td>
       <td valign="top">

                                            <a href="https://members.accu.org/index.php/articles/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c184/">Journal Columns</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c186/">LettersEditor</a>
<br />

                                            <a href="https://members.accu.org/index.php/articles/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c76/">Journals</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c77/">CVu</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c351/">273</a>
<br />

                                            <a href="https://members.accu.org/index.php/articles/c186-351/">Any of these categories</a>

                    -                        <a href="https://members.accu.org/index.php/articles/c186+351/">All of these categories</a>
<br />
</td>
   </tr>
   </tbody>
</table>




<div class="xar-error">
   <p>
 <strong>Note:</strong> when you create a new publication type,
the articles module will automatically use the templates
<em>user-display-[publicationtype].xt</em>
and <em>user-summary-[publicationtype].xt</em>.
If those templates do not exist when you try to preview or display a new article,
you'll get this warning :-)  Please place your own templates in themes/<em>yourtheme</em>/modules/articles . The templates will get the extension .xt there. </p>
</div>
<div class="xar-norm xar-standard-box-padding">
   <h1><strong>Title:</strong>&nbsp;Letter to the Editor</h1>
<p><strong>Author:</strong>&nbsp;Martin Moene</p>
<p>
<strong>Date:</strong> 04 July 2015 21:57:43 +01:00 or Sat, 04 July 2015 21:57:43 +01:00</p>
<p><strong>Summary:</strong>&nbsp;</p>
<p><strong>Body:</strong>&nbsp;<p>Dear Editor,</p>

<p>I liked the idea of Vassili Kaplanâ€™s easy-to-code parser (â€˜Split and Merge â€“ Another Algorithm for Parsing Mathematical Expressionsâ€™, C Vu 27.2, May 2015).</p>

<p>One small thing I think we should point out, though, is that the algorithm as described in that article treats the associativity of operators in a way we probably donâ€™t want.</p>

<p>With the commutative, transitive operators + and *, associativity doesnâ€™t matter: A*(B*C) = (A*B)*C and same goes with +. But things can be more subtle with - and /.</p>

<p>To take the example of 3+2*6-1 becoming 3+12-1 and then 3+11, what if that first + were changed into a -, so we have 3-2*6-1 becoming 3-12-1 and 3-11? That would give a result of -8, instead of the -10 youâ€™d get if you did it as (3-2*6)-1 as weâ€™d normally understand it.</p>

<p>Moreover, the Split and Merge algorithm, as described in the article, does not consistently treat operators as right-associative either. If the operator is preceded by another of the same or lower precedence level, then it will be left-associative: 3-12-1 would get -10. But if the operator is preceded by one of a higher precedence level, it will become right-associative with the operators before that: 3-2*6-1 would get -8. This is a bit inconsistent and I canâ€™t think of a language where weâ€™d actually want this behaviour, although there might perhaps be one out there somewhere.</p>

<p>To make the algorithm consistently left-associative, weâ€™d have to change the parser by having it break out of the merge loop and going back to the beginning after any successful merge, although it doesnâ€™t have to do this if itâ€™s already dealing with the first thing in the expression, or if the next operator is + or * and therefore can be evaluated with either associativity.</p>

<p>Having to break out of the loop will of course increase the time complexity a little, and letâ€™s hope weâ€™re not coding a language in which some operators are left-associative whereas others are right-associative.
When inventing a new way of parsing expressions, it might be a good idea to test the code with as many expressions as possible. Perhaps write a random expression generator and feed the resulting expressions both to your code and to an established parser (such as Pythonâ€™s eval function) and have it alert you about any differences in the result, or at least any difference in the first 3 significant digits (as you canâ€™t count on both floating point systems to be using the same precision).</p>

<p>Of course, a lot would depend on how thorough your random expression generator is, so perhaps test its thoroughness first by making sure it flags up the problem with the existing version of the code. Thatâ€™s what Richard Feynmann would call an â€˜A-1â€™ experiment: first check our observation methods by verifying we can observe what we have already, before changing things.</p>

<p>While such â€˜fuzz testingâ€™ does not provide a 100% solid guarantee of catching all cases (youâ€™d have to use formal code-proving methods for that, preferably checked by automatic proof-checking tools and itâ€™s still possible to slip up by using them incorrectly), at least â€˜fuzz testingâ€™ should catch most things: I hope a decent fuzz-tester would have drawn our attention to the inconsistent associativity.</p>

<p>Silas</p>

<p>Silas S Brown http://people.ds.cam.ac.uk/ssb22</p>

<p class = "quotation">Have a reputation for being reasonable<br />
~ Philippians 4:5, Phillipâ€™s</p>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
