title: How can I create a simple input validator by using ANTLR?
body: <p>I wrote my grammar in ANTLRWorks and it worked pretty well and then I generated lexer and parser.</p>
  
  <p>Well the code executes and there's no error.</p>
  
  <p>But it makes me crazy even with a wrong input everything is fine. By this I mean that <code>parser.prog()</code> executes just fine. So where is the information that I should get as the result? I just want to check the input to figure it out that if it is a propositional logic statement or not?</p>
  
  <p>I used the below to generate the code but it had some errors like it can not find the main class!</p>
  
  <pre><code>java antlr.jar org.antlr.Tool PropLogic.g
  </code></pre>
  
  <p>But this code worked :</p>
  
  <pre><code>java -cp antlr.jar org.antlr.Tool PropLogic.g
  </code></pre>
  
  <p>Here's the Grammar :</p>
  
  <pre><code>    grammar PropLogic;
  
      NOT : '!' ;
      OR  : '+' ;
      AND : '.' ;
      IMPLIES : '-&gt;' ;
      SYMBOLS : ('a'..'z') | '~' ;
      OP : '(' ;
      CP : ')' ;
  
  prog    : formula ;
  
  
  formula : NOT formula
      | OP formula( AND formula CP | OR formula CP | IMPLIES formula CP)
      | SYMBOLS ;
  
  
  WHITESPACE : ( '\t' | ' ' | '\r' | '\n'| '\u000C' )+    { $channel = HIDDEN; } ;
  </code></pre>
  
  <p>Here's my code:</p>
  
  <pre><code>import org.antlr.runtime.ANTLRStringStream;
  import org.antlr.runtime.CommonTokenStream;
  
  public class Tableaux {
  
      public static void main(String[] args) throws Exception {
  
      ANTLRStringStream in = new ANTLRStringStream("a b c");
          PropLogicLexer lexer = new PropLogicLexer(in);
          CommonTokenStream tokens = new CommonTokenStream(lexer);
          PropLogicParser parser = new PropLogicParser(tokens);
          parser.prog();
      }
  
  }
  </code></pre>