title: Grammar to Lex/Yacc
body: <p>I have been tasked with a project that involves me taking a Grammar (in BNF form) and creating a lexical scanner (using lex) and a parser (using bison). I've never worked with any of these programs and I think a good reference would be to see how these items are created from a grammar. I am looking for a grammar and it's associated .l and .ypp files, preferably in C++. I've been able to find sample files or sample grammars, but not both of them. I've spent some time searching and I could not find anything. I figure I'd post here in hopes that someone has something for me, but I will continue searching in the meantime.</p>
  
  <p>I am currently reading Tom Niemann's
  <a href="http://epaperpress.com/lexandyacc/download/LexAndYaccTutorial.pdf" rel="nofollow">http://epaperpress.com/lexandyacc/download/LexAndYaccTutorial.pdf</a> which seems to be pretty well written and understandable. </p>
  
  <p>Thanks</p>
  
  <p>Edit: I am still searching, I am starting to think that what I am looking for does not exist. Google usually never fails me!</p>
  
  <p>Edit 2: Maybe if I provide some of the grammar, you folks could show me what the appropriate .l and .ypp files would look like. This is just a snippet of the grammar, I just need a little 'taste' of how this works and I think I can take it from there.</p>
  
  <p>Grammar:</p>
  
  <pre><code>Program ::= Compound
  Statements ::= Compound | Assignment | ...
  Assignment ::= Var ASSIGN Expression
  Expression ::= Var | Operator Expression Expression | Number
  Compound := START Statements END
  Number ::= NUMBER
  </code></pre>
  
  <p>Descriptions:</p>
  
  <pre><code>Assignment is the equal sign ":="
  
  Var is an identifier that begins with a lower case letter and is followed by lower case letters or digits
  
  START is the "start" keyword
  
  END is the "end keyword
  
  Operator is "+", "-", "*", "/"
  
  Number is decimal digits which could potentially be negative (minus sign in front)
  </code></pre>