forked from JavaTX/JavaCompilerCore
Main class for JavaTXParser.
This commit is contained in:
parent
18965e0eda
commit
5cc418371d
57
src/de/dhbwstuttgart/parser/RunTXParser.java
Normal file
57
src/de/dhbwstuttgart/parser/RunTXParser.java
Normal file
@ -0,0 +1,57 @@
|
||||
package de.dhbwstuttgart.parser;
|
||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.SyntaxTreeGenerator;
|
||||
import de.dhbwstuttgart.parser.antlr.Java8Lexer;
|
||||
import de.dhbwstuttgart.parser.antlr.Java8Parser;
|
||||
import de.dhbwstuttgart.typecheck.JavaClassName;
|
||||
import de.dhbwstuttgart.typecheck.JavaClassRegistry;
|
||||
import org.antlr.v4.runtime.ANTLRInputStream;
|
||||
import org.antlr.v4.runtime.CommonTokenStream;
|
||||
import de.dhbwstuttgart.syntaxtree.*;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Scanner;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
public class RunTXParser{
|
||||
public static void main(String[] args){
|
||||
try{
|
||||
JavaTXParser parser = new JavaTXParser();
|
||||
SourceFile f = parser.parse(new File(args[0]));
|
||||
String pkgName = f.getPkgName();
|
||||
System.out.println("package: " + pkgName);
|
||||
System.out.println("Imports:");
|
||||
for(JavaClassName c : f.getImports()){
|
||||
System.out.println(c.toString());
|
||||
}
|
||||
System.out.println("classes:");
|
||||
for(ClassOrInterface c : f.getClasses()){
|
||||
int mod = c.getModifiers();
|
||||
System.out.println(Modifier.toString(mod));
|
||||
System.out.println(c.getClassName().toString());
|
||||
System.out.println("{");
|
||||
for(Field field : c.getFieldDecl()){
|
||||
System.out.println(field.getName());
|
||||
}
|
||||
System.out.println("}");
|
||||
}
|
||||
}
|
||||
catch(java.util.NoSuchElementException e){
|
||||
System.out.println("Error: Source seems to be empty.");
|
||||
}
|
||||
catch(ClassNotFoundException e){
|
||||
System.out.println("Class not found.");
|
||||
}
|
||||
catch(FileNotFoundException e){
|
||||
System.out.println("File not found.");
|
||||
}
|
||||
catch(IOException e){
|
||||
System.out.println("An exception occured which is on our TODO list.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user