title: Start states in Lex / Flex
body: <p>I'm using Flex and Bison for a parser generator, but having problems with the start states in my scanner.</p>
  
  <p>I'm using exclusive rules to deal with commenting, but this grammar doesn't seem to match quoted tokens:</p>
  
  <pre><code>%x COMMENT
  
  //                    { BEGIN(COMMENT); }
  &lt;COMMENT&gt;[^\n]        ;
  &lt;COMMENT&gt;\n           { BEGIN(INITIAL); }
  
  "=="                  { return EQUALEQUAL; }
  
  .                     ;
  </code></pre>
  
  <p>In this simple example the line:</p>
  
  <pre><code>// a == b
  </code></pre>
  
  <p>isn't matched entirely as a comment, unless I include this rule:</p>
  
  <pre><code>&lt;COMMENT&gt;"=="             ;
  </code></pre>
  
  <p>How do I get round this without having to add all these tokens into my exclusive rules?</p>