title: ANTLR Making Negative Test Cases
body: <p>I'm new to ANTLR and am trying to understand how to do some things with it.  I need it to throw an error when a statement is missing things, like a semicolon or an end bracket.  It's been called negative test cases by the problem set that I'm working through.</p>
  <p>For example, the below code returns true, which is correct.</p>
  <pre><code>val program = &quot;&quot;&quot;
  1 + 2;
  &quot;&quot;&quot;
  
  recognize(program)
  </code></pre>
  <p>However, this code also returns true, despite it missing the semicolon at the end.  It should return false ([PARSER error at line=1]: missing ';' at '').</p>
  <pre><code>val program = &quot;&quot;&quot;
  1 + 2
  &quot;&quot;&quot;.trimIndent()
  
  recognize(program)
  </code></pre>
  <p>The grammar is as follows:</p>
  <pre><code>program: (expression ';')* | EOF;
  
  expression: INT PLUS INT | OPENBRAC INT PLUS INT CLOSEBRAC | QUOTE IDENT QUOTE PLUS QUOTE IDENT QUOTE;
  
  IDENT: [A-Za-z0-9]+;
  INT: [-][0-9]+ | ('0'..'9')+;
  PLUS: '+';
  OPENBRAC: '(';
  CLOSEBRAC: ')';
  QUOTE: '&quot;';
  </code></pre>