title: Computing leading and trailing sets for context-free grammar
body: <p>I am seeking for a detailed algorithm describing how to generate leading and trailing sets for non-terminal symbols in context-free grammars. </p>
  
  <p>I've found something like this:
  <a href="https://pl.scribd.com/doc/51358638/16/Operator-Precedence-Relations" rel="nofollow">https://pl.scribd.com/doc/51358638/16/Operator-Precedence-Relations</a> 
  but I'm unsure about how it works. (See page 20)</p>
  
  <p>Assume, that we have productions:</p>
  
  <blockquote>
    <p>A -> YaZ | B</p>
    
    <p>B -> b</p>
  </blockquote>
  
  <p>then, it is said, that Leading(A) = {a}, Leading(A) = Leading(B) and Leading(B)={b}.
  And I have my doubts about this:</p>
  
  <ol>
  <li>Does it mean, that Leading(A) = {a, b} ? - I assume that in every step we do not replace the set already generated because of '=', but make sum of two sets.</li>
  <li>Does it mean, that Leading(B) is {b} or {a, b}? - Does the third rule mean, that we add Leading(B) to Leading(A) or that Leading(A) and Leading(B) are equivalent?</li>
  </ol>