title: Why is there no viable alternative for #include statement in ANTLR 4 with C grammar?
body: <p>I'm just getting started with <a href="http://antlr.org" rel="nofollow">ANTLR</a> v4 and I am a bit confused...</p>
  
  <p>I am using the C grammar file from the antlr project <a href="https://github.com/antlr/grammars-v4/tree/master/c" rel="nofollow">here</a> to work with the following bit of C:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main()
  {
     printf("Hello");
     return 0;
  }
  </code></pre>
  
  <p>(saved as C:\Users\Public\t.c).</p>
  
  <p>I generated the C parser like so:</p>
  
  <pre><code>java -cp lib/antlr-4.4-complete.jar org.antlr.v4.Tool -o src/cparser src/C.g4
  </code></pre>
  
  <p>And I edited the generated files to put a package statement at the top.  </p>
  
  <p>I then whipped up a little Java project including these generated files, referencing <code>antlr-runtime-4.4.jar</code> with a main class that looks like so:</p>
  
  <pre><code>package antlrtest;
  
  import java.io.IOException;
  
  import org.antlr.v4.runtime.ANTLRFileStream;
  import org.antlr.v4.runtime.CommonTokenStream;
  import org.antlr.v4.runtime.tree.ParseTreeWalker;
  
  import cparser.CLexer;
  import cparser.CParser;
  import cparser.CParser.CompilationUnitContext;
  
  public class AntlrTestMain {
      public static void main(String[] arguments) {
          try {           
              CParser parser = new CParser(
                  new CommonTokenStream(
                          new CLexer(
                                  new ANTLRFileStream("C:\\Users\\Public\\t.c"))));
  
              parser.setBuildParseTree(true);
  
              // This line prints the error
              CompilationUnitContext ctx = parser.compilationUnit();
  
              MyListener listener = new MyListener();
              ParseTreeWalker.DEFAULT.walk(listener, ctx);            
          } catch (IOException e) {
              e.printStackTrace();
          }
      }   
  }
  </code></pre>
  
  <p>And for completeness, though I don't think it is important, the listener looks like this (just empty, I plan to put something in here of course):</p>
  
  <pre><code>package antlrtest;
  
  import cparser.CBaseListener;
  
  public class MyListener extends CBaseListener {
  }
  </code></pre>
  
  <p>Now what happens when I run that is when I call the <code>compilationUnit</code> method I get the following errors printed to the console:</p>
  
  <pre><code>line 1:0 token recognition error at: '#i'
  line 1:9 no viable alternative at input 'nclude&lt;'
  </code></pre>
  
  <p>I'm pretty sure the C code is valid and I have not edited the <code>C.g4</code> file at all so what am I doing wrong here - why do I get these errors?  </p>
  
  <p>Is calling <code>compilationUnit()</code> the wrong thing to do perhaps, if so what should I call to pass into the tree walker?</p>