Note that there are some explanatory texts on larger screens.

plurals
  1. POWill this 'algorithm' for nullable and first work (in a parser)?
    primarykey
    data
    text
    <p>Working through this for fun: <a href="http://www.diku.dk/hjemmesider/ansatte/torbenm/Basics/" rel="nofollow noreferrer">http://www.diku.dk/hjemmesider/ansatte/torbenm/Basics/</a></p> <p>Example calculation of nullable and first uses a fixed-point calculation. (see section 3.8)</p> <p>I'm doing things in Scheme and relying a lot on recursion.</p> <p>If you try to implement nullable or first via recursion, it should be clear you'll recur infinitely on a production like </p> <p><code>N -&gt; N a b</code></p> <p>where N is a non-terminal and a,b are terminals.</p> <p>Could this be solved, recursively, by maintaining a set of non-terminals seen on the left hand side of production rules, and ignoring them after we have accounted for them once? </p> <p>This seems to work for nullable. What about for first?</p> <p><strong>EDIT:</strong> This is what I have learned from playing around. Source code link at bottom.</p> <p>Non terminals cannot be ignored in the calculation of first unless they are nullable. </p> <p>Consider:</p> <pre><code>N -&gt; N a N -&gt; X N -&gt; </code></pre> <p>Here we can ignore <code>N</code> in <code>N a</code> because <code>N</code> is nullable. We can replace <code>N -&gt; N a</code> with <code>N -&gt; a</code> and deduce that <code>a</code> is a member of <code>first(N)</code>.</p> <p>Here we cannot ignore <code>N</code>:</p> <pre><code>N -&gt; N a N -&gt; M M -&gt; b </code></pre> <p>If we ignored the <code>N</code> in <code>N -&gt; N a</code> we would deduce that <code>a</code> is in <code>first(N)</code> which is false. Instead, we see that N is not nullable, and hence when calculating first, we can omit any production where <code>N</code> is found as the first symbol in the RHS.</p> <p>This yields:</p> <pre><code>N -&gt; M M -&gt; b </code></pre> <p>which tells us <code>b</code> is in <code>first(N)</code>.</p> <p>Source Code: <a href="http://gist.github.com/287069" rel="nofollow noreferrer">http://gist.github.com/287069</a></p> <p>So ... does this sound OK?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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