title: Lex - How to run / compile a lex program on commandline
body: <p>I am very new to Lex and Yacc. I have a Lex program. Example: <code>wordcount.l</code></p>
  
  <p>I am using windows and putty.</p>
  
  <p>I am just trying to run this file..</p>
  
  <ol>
  <li><p>Does the <code>wordcount.l</code> file go on the C drive?</p></li>
  <li><p>Do I compile the Lex program and it generates a <code>.c</code> program and then what do I run?</p></li>
  </ol>
  
  <p>I tried on the command-line: Lex <code>wordcount.l</code> </p>
  
  <p>but I just get file not found...</p>
  
  <p>wordcount.l</p>
  
  <pre><code>%{  
  #include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  
  int charCount=0;
  int wordCount=0;
  int lineCount=0;
  %}
  %%
  \n      {charCount++; lineCount++;}   
  [^ \t\n]+   {wordCount++; charCount+=yyleng;}
  .       {charCount++;}
  
  %%
  main(argc, argv)
  int argc;
  char** argv;
  {           
  if (argc &gt; 1)
  {
      FILE *file;
      file = fopen(argv[1], "r");
      if (!file)
      {
          fprintf(stderr, "Could not open %s\n", argv[1]);
          exit(1);
      }
      yyin = file;
  }
  
  yylex();
  printf("%d   %d   %d\n", charCount, wordCount, lineCount);
  }
  </code></pre>
  
  <p>In putty how do I compile and run this program?</p>