Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Emphasizing what Gumbo said.</p> <p>Also, if a language has a real elif / elsif / elseif (say, a "real" else-if instruction, instead of a kind of nested chaining hidden away by formatting), then the compiler can easly emit a single node in an Abstract Syntax Tree (or similar, see <a href="http://en.wikipedia.org/wiki/Abstract_syntax_tree" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Abstract_syntax_tree</a>) instead of nesting them. </p> <p>To give an example:</p> <p>Say in C/C++ you have:</p> <pre><code>if (a) { X } else if (b) { Y } else if (c) { Z } else { 0 } </code></pre> <p>Then the compiler will build an AST-node like this:</p> <pre><code> a / \ X b / \ Y c / \ Z 0 </code></pre> <p>But if the language of choice has a real if-else:</p> <pre><code>if (a) { X } elif (b) { Y } elif (c) { Z } else { 0 } </code></pre> <p>Then the AST could more easily look like this:</p> <pre><code> (a--b--c) / / / \ X Y Z 0 </code></pre> <p>In such a language, an "if else" would only be possible if braces are not mandatory:</p> <pre><code>if (a) { X } elif (b) { Y } else if (c) { // syntax error "missing braces" if braces mandatory Z } else { 0 } </code></pre> <p>Corresponding AST (<em>if braces are not mandatory</em>):</p> <pre><code> (a--b) / / \ X Y c / \ Z 0 </code></pre> <p>This could make CFG-Analysis (<a href="http://en.wikipedia.org/wiki/Control_flow_graph" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Control_flow_graph</a>) easier to <em>implement</em> (though there might be no actual optimization benefit; so imho it'd just benefit the lazy programmer :D).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload