title: JavaScript for-loop in BNF
body: <p>I'm writing BNF for JavaScript which will be used to generate a lexer and a parser for the language. However, I'd like some ideas on how to design the for-loop. Here is the simplified version of my current BNF:</p>
  
  <pre><code>[...]
  VarDecl. Statement ::= "var" Identifier "=" Expr ";"
  ForLoop. Statement ::= "for" "(" Expr ";" Expr ";" Expr ")"
  [...]
  </code></pre>
  
  <p>So as you can see, there are two statements in the example, variable declarations and for-loops.  There are a bunch of different expressions, but <em>none</em> of the expressions are also statements.</p>
  
  <p>The problem now is that this JavaScript code will not pass through the parser:</p>
  
  <pre><code>for (var x = 3; [...]; [...])
  </code></pre>
  
  <p>This is because a variable declaration is not an expression.</p>
  
  <p>What are your ideas on how to solve this? I can think of a few ways, but I don't want to get in the way of your own thoughts, so I won't mention them here.</p>