title: Is C++ context-free or context-sensitive?
body: <p>I often hear claims that C++ is a context-sensitive language. Take the following example:</p>
  
  <pre><code>a b(c);
  </code></pre>
  
  <p>Is this a variable definition or a function declaration? That depends on the meaning of the symbol <code>c</code>. If <code>c</code> is a <em>variable</em>, then <code>a b(c);</code> defines a variable named <code>b</code> of type <code>a</code>. It is directly initialized with <code>c</code>. But if <code>c</code> is a <em>type</em>, then <code>a b(c);</code> declares a function named <code>b</code> that takes a <code>c</code> and returns an <code>a</code>.</p>
  
  <p>If you look up the definition of context-free languages, it will basically tell you that all grammar rules must have left-hand sides that consist of exactly one non-terminal symbol. Context-sensitive grammars, on the other hand, allow arbitrary strings of terminal and non-terminal symbols on the left-hand side.</p>
  
  <p>Browsing through Appendix A of "The C++ Programming Language", I couldn't find a single grammar rule that had anything else besides a single non-terminal symbol on its left-hand side. That would imply that C++ is context-free. (Of course, every context-free language is also context-sensitive in the sense that the context-free languages form a subset of the context-sensitive languages, but that is not the point.)</p>
  
  <p>So, is C++ context-free or context-sensitive?</p>