Problem in compiling Java Source using ANTLR v3

10,015

You're using the antlr runtime so you'll have to specify the antlr jar files as part of the classpath so the compiler can find the antlr classes you use e.g.

   javac -classpath c:\java\antlr-3.3\lib\antlr-3.3-complete.jar Main.java 
Share:
10,015
user628127
Author by

user628127

Updated on June 17, 2022

Comments

  • user628127
    user628127 almost 2 years

    I am trying to run ANTLR C grammar file (DummyC.g) from command line to parse C source and header files (a.h). When I run it with antlr.jar file, it generates parser and lexer files. but when I compile test file Main.java. It gives error of missing ANTLR packages as shown below.

    C:\antlr-2.7.6\test>javac Main.java

    Main.java:1: package org.antlr.tool does not exist import org.antlr.tool.;
    ^ Main.java:2: package org.antlr.runtime does not exist import org.antlr.runtime.
    ;
    ^ Main.java:3: package org.antlr.runtime.tree does not exist import org.antlr.runtime.tree.;
    ^ Main.java:4: package org.antlr.stringtemplate does not exist import org.antlr.stringtemplate.
    ;
    ^ Main.java:8: cannot find symbol symbol : class CommonTree location: class Main CommonTree tree = DummyCParser.start("a.h");

    Main.java

    import org.antlr.tool.*;   
    import org.antlr.runtime.*;   
    import org.antlr.runtime.tree.*;   
    import org.antlr.stringtemplate.*;   
    
    public class Main {   
        public static void main(String[] args) throws Exception {   
            CommonTree tree = DummyCParser.start("a.h");    
            DOTTreeGenerator gen = new DOTTreeGenerator();   
            StringTemplate st = gen.toDOT(tree);    
            System.out.println(st);   
          }  
    }  
    

    What could be the problem?