title: How to handle back references in a parser?
body: <p>I'm working on a XAML parser. I would like to make it as context-free as possible.</p>
  
  <p>You know XAML is similar to plain XML, but with properties and extensibility in mind (value conversion, templates, markup extensions, named references between elements...)</p>
  
  <p>Currently, I'm having a big problem: the XAML specification allows <strong>nodes to be named</strong> and usually there are properties <strong>can depend on those names</strong>.</p>
  
  <p>Consider this XAML:</p>
  
  <pre><code>&lt;Parent x:Name="MyParent"&gt;
     &lt;Setter Target="MyParent.Background" Value="Red" /&gt;
  &lt;/Parent&gt;
  </code></pre>
  
  <p>In this snippet you can see that the <code>Target</code> property will have to "wait" until the Parent is created to be able to deliver a value. The concept of waiting sounds to me like a Task (a promise) that may be resolved at a later time, but it seems complex and may be an overkill. </p>
  
  <p>To understand the problem it's important to notice that, as a design decision, I made my parser to inflate children elements <strong>before</strong> the parent elements.</p>
  
  <p>For instance:</p>
  
  <pre><code>&lt;Parent&gt;
     &lt;Child1/&gt;
     &lt;Child2/&gt;
  &lt;/Parent&gt;
  </code></pre>
  
  <p>The instances <code>Child1</code> and <code>Child2</code> are fully initialized before the instance of Parent is created.</p>
  
  <p>Now that I have explained how it works, how could I handle those references between nodes? References from parent => child will work, but not the opposite, because parents are created after all their children are.</p>