I have written a compiler program and now I am trying to run it from terminal. I am using antlr library inside my program. This code works pretty well when compiled using eclipse.
I am using the following command in terminal
javac -classpath antlr-runtime-3.2.jar Main.java
The file antlr-runtime-3.2.jar is present but still I am receiving the following errors
- Main.java:34: error: cannot find symbol MiniJavaLexer lexer = new MiniJavaLexer(charStream)
- Main.java:42: error: cannot find symbol PrintVisitor dfsPrint = new PrintVisitor()
- Main.java:46: error: cannot find symbol SymbolTableVisitor stVisitor = new SymbolTableVisitor()
This error is coming for every class I am using.
I want to compile and then run the program using terminal
The main.java file contains
package mini.java.compiler;
import java.io.IOException;
import org.antlr.runtime.ANTLRFileStream;
import org.antlr.runtime.CharStream;
import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.RecognitionException;
import org.antlr.runtime.tree.Tree;
public class Main {
public static void main(String[] args) throws RecognitionException,
IOException {
// TODO Auto-generated method stub
String file = "samples/factorial.java";
CharStream charStream = new ANTLRFileStream(file);
MiniJavaLexer lexer = new MiniJavaLexer(charStream);
CommonTokenStream tokens = new CommonTokenStream(lexer);
MiniJavaParser parser = new MiniJavaParser(tokens);
MiniJavaParser.goal_return res = parser.goal();
Tree tree = (Tree) res.getTree(); // The root node.
/* Print tree */
PrintVisitor dfsPrint = new PrintVisitor();
dfsPrint.visit(tree);
/* Symbol table construction */
SymbolTableVisitor stVisitor = new SymbolTableVisitor();
SymbolTable symTab = (SymbolTable) stVisitor.visit(tree);
System.out.println("-------------------");
System.out.println("Symbol Table");
System.out.println("-------------------");
symTab.printTable();
symTab.resetTable();
/* Type checking */
TypeCheckingVisitor tcVisitor = new TypeCheckingVisitor(symTab);
tcVisitor.visit(tree);
symTab.resetTable();
/* Byte Code Generation */
CodeGenerationVisitor cgVisitor = new CodeGenerationVisitor(symTab);
ClassFile cf = (ClassFile) cgVisitor.visit(tree);
System.out.println("-------------------");
System.out.println("Stack Machine Code");
System.out.println("-------------------");
cf.print();
cf.writeToFile();
}
}