title: Antlr4 grammar compilation error
body: <p>I made my own chess PGN grammar for ANTLR4, but I get a java stacktrace error :</p>
  
  <p>Pgn.g4 grammar :</p>
  
  <pre><code>grammar Pgn;
  
  file:       game (NEWLINE+ game)*;
  game:       (tag+ NEWLINE+)? notation;
  
  tag:        '['TAG_TYPE "TAG_VALUE"']';
  notation: move+ END_RESULT?;
  move:   MOVE_NUMBER\. MOVE_DESC MOVE_DESC       #CompleteMove
          |   MOVE_NUMBER\. MOVE_DESC             #OnlyWhiteMove
          |   MOVE_NUMBER\.\.\. MOVE_DESC         #OnlyBlackMove
          ;
  
  END_RESULT: '1-0'
              | '0-1'
              | '1/2-1/2'
              ;
  
  TAG_TYPE:   LETTER+;
  TAG_VALUE:  .*;
  
  MOVE_NUMBER: DIGIT+;
  MOVE_DESC: .*;  
  
  NEWLINE:    \r? \n;
  SPACES:     [ \t]+ -&gt; skip;
  
  fragment LETTER: [a-zA-Z];
  fragment DIGIT: [0-9];
  </code></pre>
  
  <p>And this is the error output :</p>
  
  <pre><code>$ antlr4 Pgn.g4 
  org\antlr\v4\parse\GrammarTreeVisitor.g: node from line 24:11 required (...)+ loop did not match anything at input 'r'
  org\antlr\v4\parse\GrammarTreeVisitor.g: node from line 24:15 mismatched tree node: n expecting &lt;UP&gt;
  org\antlr\v4\parse\GrammarTreeVisitor.g: node from line 24:11 required (...)+ loop did not match anything at input 'r'
  org\antlr\v4\parse\GrammarTreeVisitor.g: node from line 24:15 mismatched tree node: n expecting &lt;UP&gt;
  org\antlr\v4\parse\GrammarTreeVisitor.g: node from line 24:11 required (...)+ loop did not match anything at input 'r'
  org\antlr\v4\parse\GrammarTreeVisitor.g: node from line 24:15 mismatched tree node: n expecting &lt;UP&gt;
  org\antlr\v4\parse\GrammarTreeVisitor.g: node from line 24:11 required (...)+ loop did not match anything at input 'r'
  org\antlr\v4\parse\GrammarTreeVisitor.g: node from line 24:15 mismatched tree node: n expecting &lt;UP&gt;
  error(20):  internal error: Rule LETTER undefined 
  error(20):  internal error: element list has first|last == null 
  Exception in thread "main" java.lang.NullPointerException
      at org.antlr.v4.automata.ParserATNFactory.elemList(ParserATNFactory.java:445)
      at org.antlr.v4.automata.ParserATNFactory.alt(ParserATNFactory.java:414)
      at org.antlr.v4.parse.ATNBuilder.alternative(ATNBuilder.java:567)
      at org.antlr.v4.parse.ATNBuilder.block(ATNBuilder.java:400)
      at org.antlr.v4.parse.ATNBuilder.subrule(ATNBuilder.java:1185)
      at org.antlr.v4.parse.ATNBuilder.element(ATNBuilder.java:887)
      at org.antlr.v4.parse.ATNBuilder.alternative(ATNBuilder.java:550)
      at org.antlr.v4.parse.ATNBuilder.ruleBlock(ATNBuilder.java:289)
      at org.antlr.v4.automata.ParserATNFactory._createATN(ParserATNFactory.java:148)
      at org.antlr.v4.automata.LexerATNFactory.createATN(LexerATNFactory.java:94)
      at org.antlr.v4.Tool.processNonCombinedGrammar(Tool.java:407)
      at org.antlr.v4.Tool.process(Tool.java:376)
      at org.antlr.v4.Tool.processGrammarsOnCommandLine(Tool.java:343)
      at org.antlr.v4.Tool.main(Tool.java:190)
  </code></pre>
  
  <p>So, what's the problem with my grammar ?</p>
  
  <p>(Notice that this post can be a step further the one I exposed in <a href="https://stackoverflow.com/questions/20759138/error-when-generating-a-grammar-for-chess-pgn-files">this post</a>, where I had a syntax error).</p>