title: Is HTML a context-free language?
body: <p>Reading <a href="https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1758162#1758162">some</a> <a href="https://stackoverflow.com/questions/4933611/can-extended-regex-implementations-parse-html/4934590#4934590">related</a> <a href="https://stackoverflow.com/questions/590747/using-regular-expressions-to-parse-html-why-not/590789#590789">questions</a> made me think about the theoretical nature of HTML.</p>
  
  <p>I'm not talking about XHTML-like code here. I'm talking about stuff like this crazy piece of markup, which is perfectly valid HTML(!)</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"&gt;
  &lt;html&lt;head&gt;
  &lt;title//
  &lt;p ltr&lt;span id=p&gt;&lt;/span&lt;/p&gt;
  &lt;/&gt;
  </code></pre>
  
  <p>So given the enormous complexity that SGML injects here, is HTML a context-free language? Is it a formal language anyway? With a grammar?</p>
  
  <p>What about HTML5?</p>
  
  <p><sub>
  I'm new to the concept of formal languages, so please bear with me. And yes, I have read the wikipedia article ;)
  </sub></p>